Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,28 @@ public class when_comparing_two_sets_of_items : concern
Establish c = () =>
items = Enumerable.Range(1, 3).ToList();

public class and_the_sets_are_different : when_comparing_two_sets_of_items
public class and_the_sets_have_different_items : when_comparing_two_sets_of_items
{
Because b = () =>
spec.catch_exception(() => EnumerableAssertionExtensions.ShouldContainOnlyInOrder(items,3, 2, 1));
spec.catch_exception(() => items.ShouldContainOnlyInOrder(3, 2, 1));

It should_get_an_exception_when_trying_to_make_an_assertion = () =>
spec.exception_thrown.ShouldBeAn<SpecificationException>();
}

public class and_the_expected_set_is_longer_than_actual : when_comparing_two_sets_of_items
{
Because b = () =>
spec.catch_exception(() => items.ShouldContainOnlyInOrder(1, 2, 3, 4));

It should_get_an_exception_when_trying_to_make_an_assertion = () =>
spec.exception_thrown.ShouldBeAn<SpecificationException>();
}

public class and_the_expected_set_is_shorter_than_actual : when_comparing_two_sets_of_items
{
Because b = () =>
spec.catch_exception(() => items.ShouldContainOnlyInOrder(1, 2));

It should_get_an_exception_when_trying_to_make_an_assertion = () =>
spec.exception_thrown.ShouldBeAn<SpecificationException>();
Expand All @@ -29,7 +47,7 @@ public class and_the_sets_are_different : when_comparing_two_sets_of_items
public class and_the_sets_are_the_same : when_comparing_two_sets_of_items
{
Because b = () =>
EnumerableAssertionExtensions.ShouldContainOnlyInOrder(items,1, 2, 3);
items.ShouldContainOnlyInOrder(1, 2, 3);
} ;

It should_not_get_an_exception_when_trying_to_make_the_assertion = () => { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,34 @@ public static void ShouldContainOnlyInOrder<T>(this IEnumerable<T> items, params
public static void ShouldContainOnlyInOrder<T>(this IEnumerable<T> items, IEnumerable<T> ordered_items)
{
var source = new List<T>(items);
if (ordered_items.Where((item, index) => ! source[index].Equals(item)).Any())
var it = ordered_items.GetEnumerator();
var index = 0;

while (it.MoveNext())
{
if (index >= source.Count)
{
throw new SpecificationException(
"The set of items should only contain the items in the order {0}\r\nbut it is actually shorter and does not contain: {1}"
.format_using(ordered_items.EachToUsefulString(), ordered_items.Except(items).EachToUsefulString()));
}

if (!source[index].Equals(it.Current))
{
throw new SpecificationException(
"The set of items should only contain the items in the order {0}\r\nbut it actually contains the items: {1}"
.format_using(ordered_items.EachToUsefulString(), items.EachToUsefulString()));
}

++index;
}

if (index < source.Count)
{
throw new SpecificationException(
"The set of items should only contain the items in the order {0}\r\nbut it actually contains the items:{1}"
.format_using(new object[] {ordered_items.EachToUsefulString(), items.EachToUsefulString()}));
"The set of items should only contain the items in the order {0}\r\nbut it is actually longer and additionally contains: {1}"
.format_using(ordered_items.EachToUsefulString(), items.Except(ordered_items).EachToUsefulString()));

}
}
}
Expand Down