public void Static_ToString_returns_self_described_value()
        {
            const string description = "test";

            var text = StringDescription.ToString(new SelfDescribingValue <string>(description));

            Assert.AreEqual(description, text);
        }
Exemple #2
0
        public void Description_can_be_formatted()
        {
            var matcher = originalMatcher.DescribedAs("{0}, {1}", "Hello", "World!");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual("Hello, World!", description.ToString());
        }
Exemple #3
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"));
        }
Exemple #4
0
        public static void ShouldHaveDescription(this ISelfDescribing matcher, string expected)
        {
            var description = new StringDescription();

            matcher.DescribeTo(description);
            var actual = description.ToString();

            Xunit.Assert.Equal(expected, actual);
        }
        public void Describe_mismatch()
        {
            var matcher = Ends.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\""));
        }
Exemple #6
0
        public void Describe_mismatch_if_thrown_exception_does_not_match_predicate()
        {
            var matcher = new Throws<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"));
        }
        public void Append_string()
        {
            var description = new StringDescription(new StringBuilder());
            const string value = "test";

            description.AppendText(value);

            Assert.AreEqual(value, description.ToString());
        }
Exemple #8
0
        public void Use_mismatch_description_when_not_null()
        {
            var matcher     = new TestNonNullDiagnosingMatcher(s => false);
            var description = new StringDescription();

            matcher.DescribeMismatch("", description);

            Assert.Equal("TestNonNullDiagnosingMatcher.MatchesSafely", description.ToString());
        }
Exemple #9
0
        public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, string expected)
        {
            var description = new StringDescription();

            matcher.DescribeMismatch(value, description);
            var actual = description.ToString();

            Xunit.Assert.Equal(expected, actual);
        }
        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\""));
        }
        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 DescribeTo()
        {
            var matcher     = new CombinableMatcher <string>(_failingMatcher);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.Equal("Failing matcher", description.ToString());
        }
Exemple #13
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"));
        }
Exemple #14
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"));
        }
Exemple #15
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"));
        }
Exemple #16
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"));
        }
Exemple #17
0
        public void Description_can_be_formatted()
        {
            var matcher     = originalMatcher.DescribedAs("{0}, {1}", "Hello", "World!");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual("Hello, World!", description.ToString());
        }
Exemple #18
0
        public void Describe_mismatch_safely()
        {
            var matcher     = new TestNonNullMatcher(s => false);
            var description = new StringDescription();

            matcher.DescribeMismatchSafely2("something", description);

            Assert.Equal("was \"something\"", description.ToString());
        }
        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"));
        }
        public void DescribeTo()
        {
            var matcher = new CombinableMatcher<string>(failingMatcher);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual("Failing matcher", description.ToString(), "Expected no match if either matcher fails.");
        }
        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"));
        }
Exemple #22
0
        public void Describe_to()
        {
            var matcher     = Is.Null <string>();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("null"));
        }
Exemple #23
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"));
        }
        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\""));
        }
        public void Append_char()
        {
            var description = new StringDescription(new StringBuilder());
            const char value = 't';

            description.AppendValue(value);

            Assert.AreEqual("\"t\"", description.ToString());
        }
Exemple #26
0
        public void Describe_matcher()
        {
            var matcher = new Throws<ArgumentNullException>();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            NHAssert.That(description.ToString(), Is.EqualTo("the block to throw an exception of type System.ArgumentNullException"));
        }
Exemple #27
0
        private static void WriteActual <T>(T actual, IMatcher <T> matcher, TextWriter writer)
        {
            writer.Write("  But ");
            var mismatchDescription = new StringDescription();

            matcher.DescribeMismatch(actual, mismatchDescription);
            writer.Write(mismatchDescription.ToString());
            writer.WriteLine();
        }
        public void Describe_mismatch()
        {
            var matcher = Has.Item("aaa");
            var description = new StringDescription();

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

            Assert.That(description.ToString(), Is.EqualTo("was bbb, was ddd"));
        }
Exemple #29
0
        public void Describe_to()
        {
            var matcher     = new TestMatcher("");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.Equal("", description.ToString());
        }
Exemple #30
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"));
        }
Exemple #31
0
        public void Use_base_mismatch_description_when_null()
        {
            var matcher     = new TestNonNullDiagnosingMatcher(s => true);
            var description = new StringDescription();

            matcher.DescribeMismatch(null, description);

            Assert.Equal("was null", description.ToString());
        }
Exemple #32
0
        public void Describe_mismatch_if_action_does_not_throw()
        {
            var matcher = new Throws<ArgumentException>();
            var description = new StringDescription();

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

            NHAssert.That(description.ToString(), Is.EqualTo("no exception was thrown"));
        }
        public void Describe_to()
        {
            var matcher = Ends.With("bob");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("a string ending with \"bob\""));
        }
Exemple #34
0
        public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, IMatcher <string> expectedMatcher)
        {
            var description = new StringDescription();

            matcher.DescribeMismatch(value, description);
            var actual = description.ToString();

            Assert.That(actual, expectedMatcher);
        }
Exemple #35
0
        public void Default_description()
        {
            var matcher = Is.Anything();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("ANYTHING"));
        }
        public void Describe_to_appends_matcher_description()
        {
            var matcher = Has.Item("aaa");
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("a collection containing aaa"));
        }
Exemple #37
0
        public void Description_is_concatenated_from_matchers()
        {
            var matcher = Matches.AllOf(new[] { failingMatcher, successfulMatcher });
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual("(Failing matcher and Successful matcher)", description.ToString());
        }
Exemple #38
0
        private static void WriteExpected(ISelfDescribing matcher, TextWriter writer)
        {
            writer.Write(TextMessageWriter.Pfx_Expected);
            var description = new StringDescription();

            matcher.DescribeTo(description);
            writer.Write(description.ToString());
            writer.WriteLine();
        }
        public void Append_string()
        {
            var          description = new StringDescription(new StringBuilder());
            const string value       = "test";

            description.AppendText(value);

            Assert.AreEqual(value, description.ToString());
        }
        public void Append_char()
        {
            var        description = new StringDescription(new StringBuilder());
            const char value       = 't';

            description.AppendValue(value);

            Assert.AreEqual("\"t\"", description.ToString());
        }
        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\""));
        }
        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\""));
        }
Exemple #43
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()
        {
            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"));
        }
Exemple #45
0
        public void Mismatch_description_appended_if_matcher_fails()
        {
            var matcher     = Matches.AllOf(_failingMatcher);
            var description = new StringDescription();

            matcher.DescribeMismatch("bob", description);

            Assert.Equal("Failing matcher was \"bob\"", description.ToString());
        }
Exemple #46
0
        public void Describe_mismatch_if_action_throws_different_exception()
        {
            var matcher = new Throws<NullReferenceException>();
            var description = new StringDescription();

            matcher.DescribeMismatch(DoIt, description);

            NHAssert.That(description.ToString(), Starts.With("an exception of type System.ArgumentNullException was thrown"));
        }
        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"));
        }
Exemple #48
0
        public void Mismatch_description_appended_if_matcher_fails()
        {
            var matcher = Matches.AllOf(new[] { failingMatcher });
            var description = new StringDescription();

            matcher.DescribeMismatch("bob", description);

            Assert.AreEqual("Failing matcher was bob", description.ToString());
        }
Exemple #49
0
        public void Describe_to()
        {
            var matcher = Is.Null<string>();
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.That(description.ToString(), Is.EqualTo("null"));
        }
Exemple #50
0
        public void DescribeTo()
        {
            var matcher     = new CombinableMatcher <string>(failingMatcher);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual("Failing matcher", description.ToString(), "Expected no match if either matcher fails.");
        }
Exemple #51
0
        public void Description_is_concatenated_from_matchers()
        {
            var matcher     = Matches.AllOf(_failingMatcher, _successfulMatcher);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.Equal("(Failing matcher and Successful matcher)", description.ToString());
        }
Exemple #52
0
        public void Description_is_overridden()
        {
            const string newDescription = "newDescription";
            var matcher = originalMatcher.DescribedAs(newDescription);
            var description = new StringDescription();

            matcher.DescribeTo(description);

            Assert.AreEqual(newDescription, description.ToString());
        }
Exemple #53
0
        public void Append_description()
        {
            const string test = "test";
            var isEqual = IsEqual<string>.EqualTo(test);
            var description = new StringDescription();

            isEqual.DescribeTo(description);

            Assert.AreEqual(description.ToString(), test);
        }
Exemple #54
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));
        }
Exemple #55
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)"));
        }
        public void Append_description()
        {
            const int six = 6;
            var greaterThan = Is.GreaterThanOrEqualTo(six);
            var description = new StringDescription();

            greaterThan.DescribeTo(description);

            Assert.AreEqual(description.ToString(), "greater than or equal to " + six);
        }
Exemple #57
0
        public void Append_description()
        {
            const int six = 6;
            var lessThan = Is.LessThan(six);
            var description = new StringDescription();

            lessThan.DescribeTo(description);

            Assert.AreEqual(description.ToString(), "less than " + six);
        }
        public void StringBuilder_passed_in_to_ctor_is_used()
        {
            var stringBuilder = new StringBuilder();
            var description = new StringDescription(stringBuilder);
            const string value = "test";

            stringBuilder.Append(value);

            Assert.AreEqual(value, description.ToString());
        }
        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));
        }