public void Has_items_with_matchers()
        {
            var aaaMatcher = new CustomMatcher <string>("aaa", s => s == "aaa");
            var bbbMatcher = new CustomMatcher <string>("bbb", s => s == "bbb");

            Assert.That(new[] { "aaa", "bbb", "ccc" }, Has.Items <string>(aaaMatcher, bbbMatcher));
        }
Ejemplo n.º 2
0
        public void No_match_if_string_does_not_contain_substring()
        {
            var matcher = Contains.String("bob");

            var matches = matcher.Matches("the cat sat on the mat");

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 3
0
        public void No_match_if_string_does_not_end_with_substring()
        {
            var matcher = Starts.With("bob");

            var matches = matcher.Matches("the cat sat on the mat");

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 4
0
        public void No_match_if_inner_matcher_matches()
        {
            var isNot = new IsNot <string>(always);

            var matches = isNot.Matches("test");

            Assert.That(matches, Is.EqualTo(false));
        }
Ejemplo n.º 5
0
        public void No_match_if_action_does_not_throw()
        {
            var matcher = new ThrowsMatcher <ArgumentException>();

            var match = matcher.Matches(() => { });

            NHAssert.That(match, Is.False());
        }
Ejemplo n.º 6
0
        public void No_match_if_action_throws_different_exception()
        {
            var matcher = new ThrowsMatcher <NullReferenceException>();

            var match = matcher.Matches(DoIt);

            NHAssert.That(match, Is.False());
        }
Ejemplo n.º 7
0
        public void No_match_if_null()
        {
            var matcher = Is.InstanceOf(typeof(ShaneLong));

            var matches = matcher.Matches(null);

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 8
0
        public void No_match_if_null()
        {
            var matcher = Is.NotNull <string>();

            var matches = matcher.Matches(null);

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 9
0
        public void No_match_if_thrown_exception_does_not_match_predicate()
        {
            var matcher = new ThrowsMatcher <ArgumentNullException>().With(e => e.Message == "something else");

            var matches = matcher.Matches(DoIt);

            NHAssert.That(matches, Is.False());
        }
Ejemplo n.º 10
0
        public void Describe_matcher()
        {
            var matcher     = new ThrowsMatcher <ArgumentNullException>();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            NHAssert.That(description.ToString(), Is.EqualTo("the block to throw an exception of type System.ArgumentNullException"));
        }
Ejemplo n.º 11
0
        public void Describe_to()
        {
            var matcher     = Is.InstanceOf(typeof(ShaneLong));
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("an instance of NHamcrest.Tests.Core.IsInstanceOfTests+ShaneLong"));
        }
Ejemplo n.º 12
0
        public void Describe_mismatch()
        {
            var matcher     = Starts.With("bob");
            var description = new StringDescription();

            matcher.DescribeMismatch("the cat sat on the mat", description);

            Assert.That(description.ToString(), Is.EqualTo("was \"the cat sat on the mat\""));
        }
Ejemplo n.º 13
0
        public void Describe_to()
        {
            var matcher     = Starts.With("bob");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("a string starting with \"bob\""));
        }
Ejemplo n.º 14
0
        public void No_match_if_something_else()
        {
            var simonChurch = new SimonChurch();
            var matcher     = Is.InstanceOf(typeof(ShaneLong));

            var matches = matcher.Matches(simonChurch);

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 15
0
        public void Describe_to()
        {
            var matcher     = Is.Null <string>();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("null"));
        }
Ejemplo n.º 16
0
        public void Description_adds_not()
        {
            var matcher     = Is.Not(always);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("not Always"));
        }
Ejemplo n.º 17
0
        public void Describe_mismatch_if_action_does_not_throw()
        {
            var matcher     = new ThrowsMatcher <ArgumentException>();
            var description = new StringDescription();

            matcher.DescribeMismatch(() => { }, description);

            NHAssert.That(description.ToString(), Is.EqualTo("no exception was thrown"));
        }
Ejemplo n.º 18
0
        public void Default_description()
        {
            var matcher     = Is.Anything();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("ANYTHING"));
        }
Ejemplo n.º 19
0
        public void Describe_mismatch_when_null()
        {
            var matcher     = Is.InstanceOf(typeof(ShaneLong));
            var description = new StringDescription();

            matcher.DescribeMismatch(null, description);

            Assert.That(description.ToString(), Is.EqualTo("null"));
        }
Ejemplo n.º 20
0
        public void Describe_to()
        {
            var matcher     = Contains.String("bob");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("a string containing \"bob\""));
        }
        public void Describe_mismatch()
        {
            var matcher     = Has.Item(Is.EqualTo("aaa"));
            var description = new StringDescription();

            matcher.DescribeMismatch(new [] { "bbb", "ddd" }, description);

            Assert.That(description.ToString(), Is.EqualTo("was \"bbb\", was \"ddd\""));
        }
Ejemplo n.º 22
0
        public void Describe_to()
        {
            var matcher     = Every.Item(_startsWithA);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("every item starts with an A"));
        }
        public void Describe_to_appends_matcher_description()
        {
            var matcher     = Has.Item(Is.EqualTo("aaa"));
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("a collection containing \"aaa\""));
        }
Ejemplo n.º 24
0
        public void Describe_mismatch_if_thrown_exception_does_not_match_predicate()
        {
            var matcher     = new ThrowsMatcher <ArgumentNullException>().With(e => e.Message == "something else");
            var description = new StringDescription();

            matcher.DescribeMismatch(DoIt, description);

            NHAssert.That(description.ToString(), Starts.With("the exception was of the correct type, but did not match the predicate"));
        }
Ejemplo n.º 25
0
        public void Describe_mismatch_if_action_throws_different_exception()
        {
            var matcher     = new ThrowsMatcher <NullReferenceException>();
            var description = new StringDescription();

            matcher.DescribeMismatch(DoIt, description);

            NHAssert.That(description.ToString(), Starts.With("an exception of type System.ArgumentNullException was thrown"));
        }
Ejemplo n.º 26
0
        public void Describe_to()
        {
            var a           = new A();
            var matcher     = Is.SameAs(a);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("SameAs(NHamcrest.Tests.Core.IsSameTests+A)"));
        }
Ejemplo n.º 27
0
        public void No_match_if_different_object()
        {
            var a       = new A();
            var a1      = new A();
            var matcher = Is.SameAs(a1);

            var matches = matcher.Matches(a);

            Assert.That(matches, Is.False());
        }
Ejemplo n.º 28
0
        public void Appends_description()
        {
            const string test        = "test";
            var          matcher     = Is.Anything(test);
            var          description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo(test));
        }
Ejemplo n.º 29
0
        public void Describe_mismatch()
        {
            var simonChurch = new SimonChurch();
            var matcher     = Is.InstanceOf(typeof(ShaneLong));
            var description = new StringDescription();

            matcher.DescribeMismatch(simonChurch, description);

            const string errorMessage = "Simon Church is an instance of NHamcrest.Tests.Core.IsInstanceOfTests+SimonChurch not" +
                                        " NHamcrest.Tests.Core.IsInstanceOfTests+ShaneLong";

            Assert.That(description.ToString(), Is.EqualTo(errorMessage));
        }
Ejemplo n.º 30
0
 public void Match_if_string_ends_with_substring()
 {
     Assert.That("the cat sat on the mat", Starts.With("the"));
 }