public static Continuation AssertCollectionHasNotTooManyItems <T>(this IAssertionScope scope, ICollection <object> subject, ICollection <T> expectation) { return(scope .ForCondition(subject.Count <= expectation.Count) .FailWith(", but {0}{3}contains {1} item(s) more than{3}{2}.", subject, subject.Count - expectation.Count, expectation, Environment.NewLine)); }
public static Continuation AssertEitherCollectionIsNotEmpty <T>(this IAssertionScope scope, ICollection <object> subject, ICollection <T> expectation) { return(scope .ForCondition((subject.Count > 0) || (expectation.Count == 0)) .FailWith(", but found an empty collection.") .Then .ForCondition((subject.Count == 0) || (expectation.Count > 0)) .FailWith(", but {0}{2}contains {1} item(s).", subject, subject.Count, Environment.NewLine)); }
/// <summary> /// Asserts that the thrown exception has a message that matches <paramref name = "expectedWildcardPattern" />. /// </summary> /// <param name = "expectedWildcardPattern"> /// The wildcard pattern with which the exception message is matched, where * and ? have special meanings. /// </param> /// <param name = "because"> /// A formatted phrase as is supported by <see cref = "string.Format(string,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 = "becauseArgs"> /// Zero or more objects to format using the placeholders in <see cref = "because" />. /// </param> public virtual ExceptionAssertions <TException> WithMessage(string expectedWildcardPattern, string because = "", params object[] becauseArgs) { IAssertionScope assertion = Execute.Assertion.BecauseOf(because, becauseArgs).UsingLineBreaks; assertion .ForCondition(Subject.Any()) .FailWith("Expected exception with message {0}{reason}, but no exception was thrown.", expectedWildcardPattern); outerMessageAssertion.Execute(Subject.Select(exc => exc.Message).ToArray(), expectedWildcardPattern, because, becauseArgs); return(this); }
public AndConstraint <object> BeGenerated() { var type = Subject.GetType(); var assertion = GetAssertion(type); Scope = Execute.Assertion; // Assert the value and output any fail messages var message = assertion.Invoke(null, type, Subject); Scope = Scope .ForCondition(message == null) .FailWith(message) .Then; return(new AndConstraint <object>(Subject)); }