Пример #1
0
        /// <summary>
        /// Asserts that the current method is async
        ///
        /// </summary>
        /// <param name="methodInfoAssertion">The targetted MethodInfoAssertion</param>
        /// <param name="because">A formatted phrase as is supported by <see cref="M:System.String.Format(System.String,System.Object[])"/> explaining why the assertion
        ///             is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param>
        /// <param name="reasonArgs">Zero or more objects to format using the placeholders in <see cref="!:because"/>.</param>
        public static AndConstraint <MethodInfoAssertions> BeAsync(this MethodInfoAssertions methodInfoAssertion, string because = "", params object[] reasonArgs)
        {
            Execute.Assertion
            .ForCondition(methodInfoAssertion.Subject.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null)
            .BecauseOf(because, reasonArgs)
            .FailWith("Expected method {0} to be async, but it is not.", methodInfoAssertion.Subject.Name);

            return(new AndConstraint <MethodInfoAssertions>(methodInfoAssertion));
        }
        /// <summary>Asserts that a method is not <see langword="null"/>.</summary>
        /// <param name="source">The source.</param>
        /// <param name="reason">The reason.</param>
        /// <param name="reasonArgs">The reason arguments.</param>
        /// <returns>The constraint.</returns>
        public static AndConstraint <MethodInfoAssertions> NotBeNullFixed(this MethodInfoAssertions source, string reason, params object[] reasonArgs)
        {
            var actual = source.Subject;

            Execute.Assertion.ForCondition(actual != null)
            .BecauseOf(reason, reasonArgs)
            .FailWith("Expected not null{reason}, but found null.");

            return(new AndConstraint <MethodInfoAssertions>(source));
        }
        /// <summary>Asserts that a method matches the expected value.</summary>
        /// <param name="source">The source value.</param>
        /// <param name="expected">The expected method.</param>
        /// <param name="reason">The reason.</param>
        /// <param name="reasonArgs">The reason arguments.</param>
        /// <returns>The constraint.</returns>
        public static AndConstraint <MethodInfoAssertions> Be(this MethodInfoAssertions source, MethodInfo expected, string reason, params object[] reasonArgs)
        {
            var actual = source.Subject;

            Execute.Assertion.ForCondition(Object.ReferenceEquals(actual, expected))
            .BecauseOf(reason, reasonArgs)
            .FailWith("Expected '{0}'{reason}, but found {1}.", ((expected != null) ? expected.Name : "(null)"), ((actual != null) ? actual.Name : "(null)"));

            return(new AndConstraint <MethodInfoAssertions>(source));
        }
 /// <summary>Asserts that a method is not <see langword="null"/>.</summary>
 /// <param name="source">The source.</param>
 /// <returns>The constraint.</returns>
 public static AndConstraint <MethodInfoAssertions> NotBeNullFixed(this MethodInfoAssertions source)
 {
     return(NotBeNullFixed(source, ""));
 }
 /// <summary>Asserts that a method matches the expected value.</summary>
 /// <param name="source">The source value.</param>
 /// <param name="expected">The expected method.</param>
 /// <returns>The constraint.</returns>
 public static AndConstraint <MethodInfoAssertions> Be(this MethodInfoAssertions source, MethodInfo expected)
 {
     return(Be(source, expected, ""));
 }