ExceptionAssert2.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using System.Security.Cryptography;
  5. using Xunit;
  6. namespace Microsoft.AspNetCore.Testing
  7. {
  8. internal static class ExceptionAssert2
  9. {
  10. /// <summary>
  11. /// Verifies that the code throws an <see cref="ArgumentNullException"/>.
  12. /// </summary>
  13. /// <param name="testCode">A delegate to the code to be tested</param>
  14. /// <param name="paramName">The name of the parameter that should throw the exception</param>
  15. /// <returns>The <see cref="ArgumentNullException"/> that was thrown, when successful</returns>
  16. /// <exception>Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown</exception>
  17. public static ArgumentNullException ThrowsArgumentNull(Action testCode, string paramName)
  18. {
  19. var ex = Assert.Throws<ArgumentNullException>(testCode);
  20. Assert.Equal(paramName, ex.ParamName);
  21. return ex;
  22. }
  23. /// <summary>
  24. /// Verifies that the code throws a <see cref="CryptographicException"/>.
  25. /// </summary>
  26. /// <param name="testCode">A delegate to the code to be tested</param>
  27. /// <returns>The <see cref="CryptographicException"/> that was thrown, when successful</returns>
  28. /// <exception>Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown</exception>
  29. public static CryptographicException ThrowsCryptographicException(Action testCode)
  30. {
  31. return Assert.Throws<CryptographicException>(testCode);
  32. }
  33. }
  34. }