public static ContinuationOfGiven <T[]> AssertCollectionDoesNotMissItems <T>(this GivenSelector <T[]> givenSelector, IEnumerable <T> expected, string message = null) { message = message ?? "but could not find item(s) {0}."; return(givenSelector .ForCondition(items => !expected.Except(items).Any()) .FailWith(message, expected.Except)); }
public static void AssertCollectionsHaveSameItems <TActual, TExpected>(this GivenSelector <TActual[]> givenSelector, TExpected[] expected, Func <TActual[], TExpected[], int> findIndex) { givenSelector .Given(actual => new { Items = actual, Index = findIndex(actual, expected) }) .ForCondition(diff => diff.Index == -1) .FailWith("but {0} differs at index {1}.", diff => diff.Items, diff => diff.Index); }
public static void AssertDictionaryHaveSameValues <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector, IDictionary <TKey, TValue> expected, string message = null) { message = message ?? "but {0} differs at keys {1}."; givenSelector .Given(items => new { Items = items, Keys = items.Keys.Where(key => !EqualityComparer <TValue> .Default.Equals(items[key], expected[key])).ToList() }) .ForCondition(diff => !diff.Keys.Any()) .FailWith(message, diff => diff.Items, diff => diff.Keys); }
public static ContinuationOfGiven <T[]> AssertCollectionHasEnoughItems <T>(this GivenSelector <T[]> givenSelector, int length, string message = null) { message = message ?? "but {0} contains {1} item(s) less."; return(givenSelector .Given(items => items.ToArray()) .ForCondition(items => items.Length >= length) .FailWith(message, items => items, items => length - items.Length)); }
public static ContinuationOfGiven <T[]> AssertCollectionsHaveSameCount <T>(this GivenSelector <IEnumerable <T> > givenSelector, int length) { return(givenSelector .AssertCollectionIsNotEmpty(length > 0) .Then .AssertCollectionHasEnoughItems(length) .Then .AssertCollectionHasNotTooManyItems(length)); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotNull <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector, string message = null) { message = message ?? "but found dictionary is <null>."; return(givenSelector .ForCondition(items => !ReferenceEquals(items, null)) .FailWith(message)); }
public static ContinuationOfGiven <IEnumerable <T> > AssertCollectionIsNotEmpty <T>(this GivenSelector <IEnumerable <T> > givenSelector, bool isNotEmpty = true, string message = null) { message = message ?? "but found empty collection."; return(givenSelector .ForCondition(items => items.Any() || !isNotEmpty) .FailWith(message)); }
public static ContinuationOfGiven <IEnumerable <T> > AssertCollectionIsNotNullOrEmpty <T>(this GivenSelector <IEnumerable <T> > givenSelector) { return(givenSelector .AssertCollectionIsNotNull() .Then .AssertCollectionIsNotEmpty()); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryDoesNotHaveAdditionalKeys <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector, IDictionary <TKey, TValue> expected, string message = null, params Func <IDictionary <TKey, TValue>, object>[] args) { message = message ?? "but found additional keys {0}."; args = (args != null && args.Length > 0) ? args : new[] { new Func <IDictionary <TKey, TValue>, object>(items => items.Keys.Except(expected.Keys)) }; return(givenSelector .ForCondition(items => !items.Keys.Except(expected.Keys).Any()) .FailWith(message, args)); }
public static ContinuationOfGiven <Arr> AssertArrIsNotNull(this GivenSelector <Arr> givenSelector) => givenSelector .ForCondition(items => !(items is null))
public static ContinuationOfGiven <T[]> AssertDictionaryDoesNotHaveAdditionalItems <T>(this GivenSelector <T[]> givenSelector, IEnumerable <T> expected, string message = null) { message = message ?? "but found additional item(s) {0}."; return(givenSelector .ForCondition(items => !items.Except(expected).Any()) .FailWith(message, items => items.Except(expected))); }
public static void AssertArrsHaveSameValues(this GivenSelector <Arr> givenSelector, Arr expected) => givenSelector .Given(actual => GetFirstDifferenceWith(actual, expected)) .ForCondition(diff => diff.HasValue) .FailWith("but differs at position {0}.", diff => diff.Value);
public ContinuationOfGiven(GivenSelector <TSubject> parent, AssertionScope scope) { this.parent = parent; this.scope = scope; }
public static ContinuationOfGiven <T[]> AssertCollectionHasNotTooManyItems <T>(this GivenSelector <IEnumerable <T> > givenSelector, int length, string message = null) { return(givenSelector .Given(items => items.ToArray()) .AssertCollectionHasNotTooManyItems(length, message)); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotNull <TKey, TValue>(this GivenSelector <Dictionary <TKey, TValue> > givenSelector, string message = null) { return(givenSelector .Given <IDictionary <TKey, TValue> >(d => d) .AssertDictionaryIsNotNull(message)); }
private static ContinuationOfGiven <TActual[]> AssertCollectionLength <TActual, TExpected>(this GivenSelector <TActual[]> givenSelector, TActual[] actualItems, TExpected[] expectedItems) { return(givenSelector.ForCondition(items => items.Length > 0) .FailWith("but the collection is empty.") .Then .ForCondition(items => items.Length >= expectedItems.Length) .FailWith("but {0} contains {1} item(s) less.", actualItems, expectedItems.Length - actualItems.Length)); }
public static ContinuationOfGiven <IEnumerable <T> > AssertCollectionIsNotNull <T>(this GivenSelector <IEnumerable <T> > givenSelector) { return(givenSelector .ForCondition(items => !ReferenceEquals(items, null)) .FailWith("but found collection is <null>.")); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotEmpty <TKey, TValue>(this GivenSelector <Dictionary <TKey, TValue> > givenSelector, bool isNotEmpty = true, string message = null) { return(givenSelector .Given <IDictionary <TKey, TValue> >(d => d) .AssertDictionaryIsNotEmpty(isNotEmpty, message)); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotEmpty <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector, bool isNotEmpty = true, string message = null) { message = message ?? "but found empty dictionary."; return(givenSelector .ForCondition(items => items.Any()) .FailWith(message)); }
public static ContinuationOfGiven <T[]> AssertDictionaryDoesNotHaveAdditionalItems <T>(this GivenSelector <IEnumerable <T> > givenSelector, IEnumerable <T> expected, string message = null) { return(givenSelector .Given(items => items.ToArray()) .AssertDictionaryDoesNotHaveAdditionalItems(expected, message)); }
public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotNullOrEmpty <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector) { return(givenSelector .AssertDictionaryIsNotNull() .Then .AssertDictionaryIsNotEmpty()); }
public ContinuationOfGiven(GivenSelector <TSubject> parent, bool succeeded) { this.parent = parent; this.succeeded = succeeded; }
public static ContinuationOfGiven <Arr> AssertEitherArrHaveSameSizeAndElementType(this GivenSelector <Arr> givenSelector, Size size, int elementType) => givenSelector .ForCondition(items => items.Size != size) .FailWith("but found size {0}.", items => items.Size) .Then .ForCondition(items => items.ElementType != elementType) .FailWith("but found {0}.", items => items.ElementType);