main
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using JetBrains.Annotations;
  5using NUnit.Framework;
  6
  7namespace tests
  8{
  9    static public class AssertionExtensions
 10    {
 11        [AssertionMethod]
 12        static public void should_be_equal_to<T>(this T item_to_validate, T expected_value)
 13        {
 14            Assert.AreEqual(expected_value, item_to_validate);
 15        }
 16
 17        [AssertionMethod]
 18        static public void should_not_be_equal_to<T>(this T item_to_validate, T expected_value)
 19        {
 20            Assert.AreNotEqual(expected_value, item_to_validate);
 21        }
 22
 23        [AssertionMethod]
 24        static public void should_be_the_same_instance_as<T>(this T left, T right)
 25        {
 26            Assert.IsTrue(ReferenceEquals(left, right));
 27        }
 28
 29        [AssertionMethod]
 30        static public void should_be_null<T>(this T item)
 31        {
 32            Assert.IsNull(item);
 33        }
 34
 35        [AssertionMethod]
 36        static public void should_not_be_null<T>(this T item) where T : class
 37        {
 38            Assert.IsNotNull(item);
 39        }
 40
 41        [AssertionMethod]
 42        static public void should_be_greater_than<T>(this T actual, T expected) where T : IComparable
 43        {
 44            Assert.Greater(actual, expected);
 45        }
 46
 47        [AssertionMethod]
 48        static public void should_be_less_than(this int actual, int expected)
 49        {
 50            Assert.Less(actual, expected);
 51        }
 52
 53        [AssertionMethod]
 54        static public void should_contain<T>(this IEnumerable<T> items_to_peek_in_to, T items_to_look_for)
 55        {
 56            items_to_peek_in_to.Contains(items_to_look_for).should_be_true();
 57        }
 58
 59        [AssertionMethod]
 60        static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for)
 61        {
 62            items_to_peek_into.Contains(item_to_look_for).should_be_false();
 63        }
 64
 65        [AssertionMethod]
 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        [AssertionMethod]
 72        static public void should_be_an_instance_of(this object item, Type type)
 73        {
 74            Assert.IsInstanceOfType(type, item);
 75        }
 76
 77        [AssertionMethod]
 78        static public void should_have_thrown<TheException>(this Action action) where TheException : Exception
 79        {
 80            try
 81            {
 82                action();
 83                Assert.Fail("the_exception_was_not_thrown");
 84            }
 85            catch (Exception e)
 86            {
 87                should_be_an_instance_of<TheException>(e);
 88            }
 89        }
 90
 91        [AssertionMethod]
 92        static public void should_be_true(this bool item)
 93        {
 94            Assert.IsTrue(item);
 95        }
 96
 97        [AssertionMethod]
 98        static public void should_be_false(this bool item)
 99        {
100            Assert.IsFalse(item);
101        }
102
103        [AssertionMethod]
104        static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
105        {
106            foreach (var item_to_find in items_to_find)
107            {
108                items.should_contain(item_to_find);
109            }
110        }
111
112        [AssertionMethod]
113        static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind)
114        {
115            items.Count().should_be_equal_to(itemsToFind.Length);
116            items.should_contain(itemsToFind);
117        }
118
119        [AssertionMethod]
120        static public void should_be_equal_ignoring_case(this string item, string other)
121        {
122            StringAssert.AreEqualIgnoringCase(item, other);
123        }
124    }
125}