示例#1
0
 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));
 }
示例#2
0
 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);
 }
示例#3
0
 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);
 }
示例#4
0
 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));
 }
示例#5
0
 public static ContinuationOfGiven <T[]> AssertCollectionsHaveSameCount <T>(this GivenSelector <IEnumerable <T> > givenSelector, int length)
 {
     return(givenSelector
            .AssertCollectionIsNotEmpty(length > 0)
            .Then
            .AssertCollectionHasEnoughItems(length)
            .Then
            .AssertCollectionHasNotTooManyItems(length));
 }
示例#6
0
 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));
 }
示例#7
0
 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));
 }
示例#8
0
 public static ContinuationOfGiven <IEnumerable <T> > AssertCollectionIsNotNullOrEmpty <T>(this GivenSelector <IEnumerable <T> > givenSelector)
 {
     return(givenSelector
            .AssertCollectionIsNotNull()
            .Then
            .AssertCollectionIsNotEmpty());
 }
示例#9
0
 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));
 }
示例#10
0
 public static ContinuationOfGiven <Arr> AssertArrIsNotNull(this GivenSelector <Arr> givenSelector) =>
 givenSelector
 .ForCondition(items => !(items is null))
示例#11
0
 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)));
 }
示例#12
0
 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);
示例#13
0
 public ContinuationOfGiven(GivenSelector <TSubject> parent, AssertionScope scope)
 {
     this.parent = parent;
     this.scope  = scope;
 }
示例#14
0
 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));
 }
示例#15
0
 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));
 }
示例#17
0
 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>."));
 }
示例#18
0
 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));
 }
示例#19
0
 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));
 }
示例#20
0
 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));
 }
示例#21
0
 public static ContinuationOfGiven <IDictionary <TKey, TValue> > AssertDictionaryIsNotNullOrEmpty <TKey, TValue>(this GivenSelector <IDictionary <TKey, TValue> > givenSelector)
 {
     return(givenSelector
            .AssertDictionaryIsNotNull()
            .Then
            .AssertDictionaryIsNotEmpty());
 }
示例#22
0
 public ContinuationOfGiven(GivenSelector <TSubject> parent, bool succeeded)
 {
     this.parent    = parent;
     this.succeeded = succeeded;
 }
示例#23
0
 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);