PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/UiException/TraceExceptionHelper.cs

#
C# | 76 lines | 36 code | 8 blank | 32 comment | 4 complexity | bf689179d981ed1e4f58241132d94881 MD5 | raw file
 1// ****************************************************************
 2// This is free software licensed under the NUnit license. You may
 3// obtain a copy of the license at http://nunit.org
 4// ****************************************************************
 5
 6using System;
 7using System.Collections.Generic;
 8using System.Text;
 9using System.Diagnostics;
10
11namespace NUnit.UiException
12{
13    /// <summary>
14    /// (formerly named TraceExceptionHelper)
15    /// 
16    /// Exposes static methods to assert predicates and throw exceptions
17    /// as needed.
18    /// </summary>
19    public class UiExceptionHelper
20    {
21        /// <summary>
22        /// Asserts that reference is not null; otherwise throws an
23        /// ArgumentNullException.
24        /// </summary>
25        /// <param name="value">The reference to be tested.</param>
26        /// <param name="paramName">The name of this reference</param>
27        [DebuggerStepThrough]
28        public static void CheckNotNull(object value, string paramName)
29        {
30            if (value == null)
31                throw new ArgumentNullException(paramName);
32
33            return;
34        }
35
36        /// <summary>
37        /// Asserts that 'test' is true or throws an ArgumentException.
38        /// </summary>
39        /// <param name="test">The boolean to be tested.</param>
40        /// <param name="message">The error message.</param>
41        /// <param name="paramName">The parameter name to be passed to ArgumentException.</param>
42        [DebuggerStepThrough]
43        public static void CheckTrue(bool test, string message, string paramName)
44        {
45            if (!test)
46                throw new ArgumentException(message, paramName);
47
48            return;
49        }
50
51        /// <summary>
52        /// Asserts that 'test' is false or throws an ArgumentException.
53        /// </summary>
54        /// <param name="test">The boolean to be tested.</param>
55        /// <param name="message">The error message.</param>
56        /// <param name="paramName">The parameter name to be passed to ArgumentException.</param>
57        [DebuggerStepThrough]
58        public static void CheckFalse(bool test, string message, string paramName)
59        {
60            if (test)
61                throw new ArgumentException(message, paramName);
62
63            return;
64        }
65
66        /// <summary>
67        /// Throws an ApplicationException with the given message.
68        /// </summary>
69        /// <param name="message">The error message.</param>
70        [DebuggerStepThrough]
71        public static void Fail(string message)
72        {
73            throw new ApplicationException(message);
74        }        
75    }
76}