main
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Linq.Expressions;
5using gorilla.utility;
6using Machine.Specifications;
7
8namespace specs
9{
10 static public class Assertions
11 {
12 static public void should_be_equal_to<T>(this T item_to_validate, T expected_value)
13 {
14 item_to_validate.ShouldEqual(expected_value);
15 }
16
17 static public void should_be_the_same_instance_as<T>(this T left, T right)
18 {
19 ReferenceEquals(left, right).ShouldBeTrue();
20 }
21
22 static public void should_be_null<T>(this T item)
23 {
24 item.ShouldBeNull();
25 }
26
27 static public void should_not_be_null<T>(this T item) where T : class
28 {
29 item.ShouldNotBeNull();
30 }
31
32 static public void should_be_greater_than<T>(this T actual, T expected) where T : IComparable
33 {
34 actual.ShouldBeGreaterThan(expected);
35 }
36
37 static public void should_be_less_than(this int actual, int expected)
38 {
39 actual.ShouldBeLessThan(expected);
40 }
41
42 static public void should_contain<T>(this IEnumerable<T> items_to_peek_in_to, T items_to_look_for)
43 {
44 items_to_peek_in_to.Contains(items_to_look_for).should_be_true();
45 }
46
47 static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
48 {
49 foreach (var item_to_find in items_to_find)
50 {
51 items.should_contain(item_to_find);
52 }
53 }
54
55 static public void should_contain<T>(this IEnumerable<T> items, Expression<Func<T, bool>> criteria)
56 {
57 if (items.Any(criteria.Compile())) return;
58 throw new ArgumentException("Could not find {0}".format(criteria));
59 }
60
61 static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for)
62 {
63 items_to_peek_into.Contains(item_to_look_for).should_be_false();
64 }
65
66 static public void should_be_an_instance_of<T>(this object item)
67 {
68 item.should_be_an_instance_of(typeof (T));
69 }
70
71 static public void should_be_an_instance_of(this object item, Type type)
72 {
73 item.ShouldBe(type);
74 }
75
76 static public void should_have_thrown<TheException>(this Action action) where TheException : Exception
77 {
78 typeof (TheException).ShouldBeThrownBy(action);
79 }
80
81 static public void should_be_true(this bool item)
82 {
83 item.ShouldBeTrue();
84 }
85
86 static public void should_be_false(this bool item)
87 {
88 item.ShouldBeFalse();
89 }
90
91
92 static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind)
93 {
94 items.Count().should_be_equal_to(itemsToFind.Length);
95 items.should_contain(itemsToFind);
96 }
97
98 static public void should_be_equal_ignoring_case(this string item, string other)
99 {
100 item.ShouldBeEqualIgnoringCase(other);
101 }
102 }
103}