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