public static async Task <ExceptionAssertions <ApiException> > ThrowApiExceptionAsync( this AsyncFunctionAssertions assertions, string because = "", params object[] becauseArgs) { return(await assertions.ThrowExactlyAsync <ApiException>(because, becauseArgs)); }
public static void ThrowArgumentNullException <TTask, TAssertions>(this AsyncFunctionAssertions <TTask, TAssertions> asyncErrorAssertion, string argName) where TTask : Task where TAssertions : AsyncFunctionAssertions <TTask, TAssertions> { asyncErrorAssertion .ThrowAsync <ArgumentNullException>().Result .Which.ParamName.Should().Be(argName); }
/// <summary> /// Asserts that the <paramref name="asyncActionAssertions"/> subject throws the exact exception (and not a derived exception type). /// </summary> /// <param name="asyncActionAssertions">A reference to the method or property.</param> /// <typeparam name="TException"> /// The type of the exception it should throw. /// </typeparam> /// <param name="because"> /// A formatted phrase explaining why the assertion should be satisfied. If the phrase does not /// start with the word <i>because</i>, it is prepended to the message. /// </param> /// <param name="becauseArgs"> /// Zero or more values to use for filling in any <see cref="string.Format(string,object[])"/> compatible placeholders. /// </param> /// <returns> /// Returns an object that allows asserting additional members of the thrown exception. /// </returns> public static ExceptionAssertions <TException> ThrowExactly <TException>(this AsyncFunctionAssertions asyncActionAssertions, string because = "", params object[] becauseArgs) where TException : Exception { var exceptionAssertions = asyncActionAssertions.Throw <TException>(because, becauseArgs); exceptionAssertions.Which.GetType().Should().Be <TException>(because, becauseArgs); return(exceptionAssertions); }
public static async Task <AndConstraint <ObjectAssertions> > ThrowAsync(this AsyncFunctionAssertions assertions, Type exceptionType, string because = "", params object[] becauseArgs) { return((await assertions.ThrowAsync <Exception>(because, becauseArgs)).Which.Should().BeAssignableTo(exceptionType)); }