summaryrefslogtreecommitdiff
path: root/spec/assertions.cs
blob: 8c71ad62b9ba4648778ef4026ae9209a6aca545b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using Machine.Specifications;

namespace specs
{
    static public class Assertions
    {
        static public void should_be_equal_to<T>(this T item_to_validate, T expected_value)
        {
            item_to_validate.ShouldEqual(expected_value);
        }

        static public void should_be_the_same_instance_as<T>(this T left, T right)
        {
            ReferenceEquals(left, right).ShouldBeTrue();
        }

        static public void should_be_null<T>(this T item)
        {
            item.ShouldBeNull();
        }

        static public void should_not_be_null<T>(this T item) where T : class
        {
            item.ShouldNotBeNull();
        }

        static public void should_be_greater_than<T>(this T actual, T expected) where T : IComparable
        {
            actual.ShouldBeGreaterThan(expected);
        }

        static public void should_be_less_than(this int actual, int expected)
        {
            actual.ShouldBeLessThan(expected);
        }

        static public void should_contain<T>(this IEnumerable<T> items_to_peek_in_to, T items_to_look_for)
        {
            items_to_peek_in_to.Contains(items_to_look_for).should_be_true();
        }

        static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for)
        {
            items_to_peek_into.Contains(item_to_look_for).should_be_false();
        }

        //static public void should_be_an_instance_of<T>(this object item)
        //{
            //item.should_be_an_instance_of(typeof (T));
        //}

        //static public void should_be_an_instance_of(this object item, Type type)
        //{
            //item.ShouldBe(type);
        //}

        static public void should_have_thrown<TheException>(this Action action) where TheException : Exception
        {
            typeof (TheException).ShouldBeThrownBy(action);
        }

        static public void should_be_true(this bool item)
        {
            item.ShouldBeTrue();
        }

        static public void should_be_false(this bool item)
        {
            item.ShouldBeFalse();
        }

        static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
        {
            foreach (var item_to_find in items_to_find)
            {
                items.should_contain(item_to_find);
            }
        }

        static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind)
        {
            items.Count().should_be_equal_to(itemsToFind.Length);
            items.should_contain(itemsToFind);
        }

        static public void should_be_equal_ignoring_case(this string item, string other)
        {
            item.ShouldBeEqualIgnoringCase(other);
        }
    }
}