Example #1
0
 public void FullMatch_fails_when_testValue_matches_regex_pattern_but_lenght_is_different()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.FullMatch("mbTest", new Regex(@"[\w]{7}")));
     Assert.Count(1, failures);
     Assert.AreEqual("\"mbTest\"", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("\"[\\\\w]{7}\"", failures[0].LabeledValues[1].FormattedValue.ToString());
 }
Example #2
0
        public void KeyedPairs_Failure_LeftLongerThanRight()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "b" }
            },
                    new Dictionary <int, string> {
                { 2, "b" }
            },
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Expected the left and right dictionaries to have the same number of items.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left Dictionary Count", "2"),
                new AssertionFailure.LabeledValue("Right Dictionary Count", "1"),
                new AssertionFailure.LabeledValue("Left Dictionary", "[1: \"a\", 2: \"b\"]"),
                new AssertionFailure.LabeledValue("Right Dictionary", "[2: \"b\"]")
            }, failures[0].LabeledValues);

            Assert.Count(0, failures[0].InnerFailures);
        }
Example #3
0
        public void KeyedPairs_Failure_AtIndex()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "b" }
            },
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "c" }
            },
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Assertion failed on two pairs with a particular key in both dictionaries.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Key", "2"),
                new AssertionFailure.LabeledValue("Left Dictionary", "[1: \"a\", 2: \"b\"]"),
                new AssertionFailure.LabeledValue("Right Dictionary", "[1: \"a\", 2: \"c\"]")
            }, failures[0].LabeledValues);

            Assert.Count(1, failures[0].InnerFailures);
        }
Example #4
0
 public void AreEqualIgnoreCase_fails_when_one_of_the_values_is_null()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.AreEqual("test", null, StringComparison.InvariantCultureIgnoreCase));
     Assert.Count(1, failures);
     Assert.AreEqual("{InvariantCultureIgnoreCase}", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("\"test\"", failures[0].LabeledValues[1].FormattedValue.ToString());
     Assert.AreEqual("null", failures[0].LabeledValues[2].FormattedValue.ToString());
 }
Example #5
0
        public void Pairs_Success_AllPassAssertion()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.Pairs(new[] { 1, 2, 3 }, new[] { -1, 2, 0 }, Assert.GreaterThanOrEqualTo,
                                        "Hello {0}.", "World"));

            Assert.Count(0, failures);
        }
Example #6
0
        public void Pairs_Success_BothEmpty()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.Pairs(new int[] { }, new int[] { }, Assert.GreaterThanOrEqualTo,
                                        "Hello {0}.", "World"));

            Assert.Count(0, failures);
        }
Example #7
0
 public void AreEqualIgnoreCase_fails_with_custom_message()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.AreEqual(null, "test", "{0} message {1}", "MB1", "Mb2", StringComparison.InvariantCultureIgnoreCase));
     Assert.Count(1, failures);
     Assert.AreEqual("null", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("\"test\"", failures[0].LabeledValues[1].FormattedValue.ToString());
     Assert.AreEqual("MB1 message Mb2", failures[0].Message);
 }
Example #8
0
 public void NotLike_fails_when_testValue_does_not_match_regex_pattern()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.NotLike("mbTest", new Regex(@"[\w]+")));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected a string to not contain a full or partial match of a regular expression pattern.", failures[0].Description);
     Assert.AreEqual("Actual Value", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("\"mbTest\"", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Regex Pattern", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("\"[\\\\w]+\"", failures[0].LabeledValues[1].FormattedValue.ToString());
 }
Example #9
0
 public void EndsWith_fails_when_testValue_does_not_start_with_pattern()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.EndsWith("mbTest", "jb"));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected string to end with the specified text.", failures[0].Description);
     Assert.AreEqual("Actual Value", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("\"mbTest\"", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Expected Text", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("\"jb\"", failures[0].LabeledValues[1].FormattedValue.ToString());
 }
Example #10
0
 public void FullMatch_fails_when_testValue_does_not_match_regex_pattern()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.FullMatch("mbTest", new Regex(@"[\d]{6}")));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected a string to exactly match a regular expression pattern.", failures[0].Description);
     Assert.AreEqual("Actual Value", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("\"mbTest\"", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Regex Pattern", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("\"[\\\\d]{6}\"", failures[0].LabeledValues[1].FormattedValue.ToString());
 }
Example #11
0
        public void KeyedPairs_Success_BothEmpty()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string>(),
                    new Dictionary <int, string>(),
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(0, failures);
        }
Example #12
0
 public void AreEqualIgnoreCase_fails_when_simple_values_different()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.AreEqual("test", "tEsm", StringComparison.InvariantCultureIgnoreCase));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected values to be equal according to string comparison type.", failures[0].Description);
     Assert.AreEqual("Comparison Type", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("{InvariantCultureIgnoreCase}", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Expected Value", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("\"test\"", failures[0].LabeledValues[1].FormattedValue.ToString());
     Assert.AreEqual("Actual Value", failures[0].LabeledValues[2].Label);
     Assert.AreEqual("\"tEsm\"", failures[0].LabeledValues[2].FormattedValue.ToString());
 }
Example #13
0
 public void StartsWith_with_comparison_type_fails_when_testValue_does_not_start_with_pattern()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.StartsWith("mbTest", "jb", StringComparison.OrdinalIgnoreCase));
     Assert.Count(1, failures);
     Assert.AreEqual("Expected string to start with the specified text.", failures[0].Description);
     Assert.AreEqual("Comparison Type", failures[0].LabeledValues[0].Label);
     Assert.AreEqual("{OrdinalIgnoreCase}", failures[0].LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Actual Value", failures[0].LabeledValues[1].Label);
     Assert.AreEqual("\"mbTest\"", failures[0].LabeledValues[1].FormattedValue.ToString());
     Assert.AreEqual("Expected Text", failures[0].LabeledValues[2].Label);
     Assert.AreEqual("\"jb\"", failures[0].LabeledValues[2].FormattedValue.ToString());
 }
Example #14
0
        public void KeyedPairs_Success_AllPassAssertion()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "c" }
            },
                    new Dictionary <int, string> {
                { 1, "a" }, { 2, "b" }
            },
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(0, failures);
        }
Example #15
0
        public void Pairs_Failure_RightNullButNotLeft()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.Pairs(new[] { -1, 2, 4 }, (int[])null, Assert.GreaterThanOrEqualTo,
                                        "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Expected the left and right sequences to either both be null or both be non-null.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left Sequence", "[-1, 2, 4]"),
                new AssertionFailure.LabeledValue("Right Sequence", "null")
            }, failures[0].LabeledValues);

            Assert.Count(0, failures[0].InnerFailures);
        }
Example #16
0
        public void Pairs_Failure_AtIndex()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.Pairs(new[] { 1, 2, 3 }, new[] { -1, 2, 4 }, Assert.GreaterThanOrEqualTo,
                                        "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Assertion failed on two values at a particular index within both sequences.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Index", "2"),
                new AssertionFailure.LabeledValue("Left Sequence", "[1, 2, 3]"),
                new AssertionFailure.LabeledValue("Right Sequence", "[-1, 2, 4]")
            }, failures[0].LabeledValues);

            Assert.Count(1, failures[0].InnerFailures);
        }
Example #17
0
        public void Pairs_Failure_LeftLongerThanRight()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.Pairs(new[] { 1, 2, 5, 0 }, new[] { -1, 2, 4 }, Assert.GreaterThanOrEqualTo,
                                        "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Expected the left and right sequences to have the same number of elements.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left Sequence Count", "4"),
                new AssertionFailure.LabeledValue("Right Sequence Count", "3"),
                new AssertionFailure.LabeledValue("Left Sequence", "[1, 2, 5, 0]"),
                new AssertionFailure.LabeledValue("Right Sequence", "[-1, 2, 4]")
            }, failures[0].LabeledValues);

            Assert.Count(0, failures[0].InnerFailures);
        }
Example #18
0
        public void KeyedPairs_Failure_RightNullButNotLeft()
        {
            AssertionFailure[] failures = AssertTest.Capture(
                () => Assert.Over.KeyedPairs(
                    new Dictionary <int, string>(),
                    (IDictionary <int, string>)null,
                    Assert.GreaterThanOrEqualTo,
                    "Hello {0}.", "World"));

            Assert.Count(1, failures);
            Assert.AreEqual("Expected the left and right dictionaries to either both be null or both be non-null.", failures[0].Description);
            Assert.AreEqual("Hello World.", failures[0].Message);
            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left Dictionary", "[]"),
                new AssertionFailure.LabeledValue("Right Dictionary", "null")
            }, failures[0].LabeledValues);

            Assert.Count(0, failures[0].InnerFailures);
        }
Example #19
0
 public void EndsWith_with_comparison_type_fail_test_with_custom_message()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.EndsWith("mbTest", "jb", StringComparison.OrdinalIgnoreCase, "{0} message {1}", "MB1", "Mb2"));
     Assert.Count(1, failures);
     Assert.AreEqual("MB1 message Mb2", failures[0].Message);
 }
Example #20
0
 public void EndsWith_with_comparison_type_fails_when_testValue_is_null()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.EndsWith(null, "", StringComparison.OrdinalIgnoreCase));
     Assert.Count(1, failures);
 }
Example #21
0
 public void EndsWith_fail_test_with_custom_message()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.EndsWith("mbTest", "jb", "{0} message {1}", "MB1", "Mb2"));
     Assert.Count(1, failures);
     Assert.AreEqual("MB1 message Mb2", failures[0].Message);
 }
Example #22
0
 public void EndsWith_fails_when_testValue_is_null()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.EndsWith(null, ""));
     Assert.Count(1, failures);
 }
Example #23
0
 public void NotLike_fail_test_with_custom_message()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.NotLike("mbTest", new Regex(@"[\w]{6}"), "{0} message {1}", "MB1", "Mb2"));
     Assert.Count(1, failures);
     Assert.AreEqual("MB1 message Mb2", failures[0].Message);
 }
Example #24
0
 public void NotLike_fails_when_testValue_is_null()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.NotLike(null, new Regex(@"[\w]+")));
     Assert.Count(1, failures);
 }
Example #25
0
 public void FullMatch_fails_when_testValue_is_null()
 {
     AssertionFailure[] failures = AssertTest.Capture(() => Assert.FullMatch(null, new Regex(@"[\d]{6}")));
     Assert.Count(1, failures);
 }