// TODO: überall multi "where"-statements wie hier machen public static AndConstraint<TAssertions> BeEquivalentWithSameOrdering<TSubject, TAssertions>( this CollectionAssertions<TSubject, TAssertions> assertions, params object?[] expectation) where TSubject : IEnumerable where TAssertions : CollectionAssertions<TSubject, TAssertions> { return assertions.BeEquivalentTo(expectation, options => options.WithStrictOrdering()); }
// Temporary placeholder for https://github.com/fluentassertions/fluentassertions/issues/1179 public static AndConstraint <TAssertions> AllSatisfy <T, TAssertions>( this CollectionAssertions <IEnumerable <T>, TAssertions> assertions, Action <T> inspector, string because = "", params object[] becauseArgs) where TAssertions : CollectionAssertions <IEnumerable <T>, TAssertions> { if (inspector == null) { throw new ArgumentNullException(nameof(inspector)); } Execute.Assertion.BecauseOf(because, becauseArgs) .WithExpectation("Expected {context:collection} to satisfy inspector{reason}, ") .ForCondition(assertions.Subject != null) .FailWith("but collection is <null>.") .Then.ForCondition(assertions.Subject.Any()) .FailWith("but collection is empty.") .Then.ClearExpectation(); string[] strArray = assertions.CollectFailuresFromInspectors(inspector); if (strArray.Any()) { string formattedFailReason = Environment.NewLine + string.Join(Environment.NewLine, strArray.Select(x => x.IndentLines())); Execute.Assertion.BecauseOf(because, becauseArgs) .FailWith( "Expected {context:collection} to satisfy all inspectors{reason}, but inspector is not satisfied:" + formattedFailReason); } return(new AndConstraint <TAssertions>((TAssertions)assertions)); }
private static string[] CollectFailuresFromInspectors <T, TAssertions>( this CollectionAssertions <IEnumerable <T>, TAssertions> assertions, Action <T> inspector) where TAssertions : CollectionAssertions <IEnumerable <T>, TAssertions> { using (AssertionScope assertionScope1 = new AssertionScope()) { int num = 0; foreach (var obj in assertions.Subject) { string[] strArray; using (AssertionScope assertionScope2 = new AssertionScope()) { inspector(obj); strArray = assertionScope2.Discard(); } if (strArray.Length != 0) { string str = string.Join(Environment.NewLine, strArray.Select(x => x.IndentLines().TrimEnd('.'))); assertionScope1.AddPreFormattedFailure($"At index {num}:{Environment.NewLine}{str}"); } ++num; } return(assertionScope1.Discard()); } }
private static string[] CollectFailuresFromInspectors <T, TAssertions>( this CollectionAssertions <IEnumerable <T>, TAssertions> assertions, Action <T> inspector) where TAssertions : CollectionAssertions <IEnumerable <T>, TAssertions> { using (AssertionScope assertionScope1 = new AssertionScope()) { int num = 0; foreach (var obj in assertions.Subject) { string[] strArray; using (AssertionScope assertionScope2 = new AssertionScope()) { inspector(obj); strArray = assertionScope2.Discard(); } if (strArray.Length != 0) { string str = string.Join(Environment.NewLine, strArray.Select(x => x.IndentLines().TrimEnd('.'))); string valueText = ""; if (obj != null && obj.GetType().GetMethod("ToString")?.DeclaringType != typeof(object)) { valueText = $" with value {obj}"; } assertionScope1.AddPreFormattedFailure($"At index {num}{valueText}:{Environment.NewLine}{str}"); } ++num; } return(assertionScope1.Discard()); } }
public static AndConstraint <TAssertions> BeSequenceEquivalentTo <TExpectation, TSubject, TAssertions>( this CollectionAssertions <TSubject, TAssertions> collectionAssertions, IEnumerable <TExpectation> expectation, string because = "", params object[] becauseArgs) where TSubject : IEnumerable where TAssertions : CollectionAssertions <TSubject, TAssertions> { return(collectionAssertions.BeEquivalentTo(expectation, options => options.WithStrictOrdering(), because, becauseArgs)); }