PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/UiException/TraceExceptionHelper.cs

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