コード例 #1
0
        public void should_allow_asserting_on_info()
        {
            var logSpy          = new LoggingSpy();
            var expectedContent = new { Some = "Content" };

            logSpy.Logger.Info(expectedContent);

            logSpy.AssertDidInfo(expectedContent);
        }
コード例 #2
0
        public void should_not_allow_expected_to_have_extra_content_at_any_depth()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = "Content", Extra = new { Content = "blah" } };

            logSpy.Logger.Info(content);

            Assert.False(logSpy.DidInfo(new { Some = "Content", Extra = new { Content = "blah", Extra = true } }));
        }
コード例 #3
0
        public void should_not_throw_assertion_failed_if_log_matches()
        {
            var logSpy          = new LoggingSpy();
            var expectedContent = new { Some = "Content" };

            logSpy.Logger.Info(expectedContent);

            logSpy.AssertDidInfo(expectedContent);
        }
コード例 #4
0
        public void should_allow_matching_by_predicates()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = 12 };

            logSpy.Logger.Info(content);

            logSpy.AssertDidInfo(new { Some = new Predicate <int>(n => n == 12) });
        }
コード例 #5
0
        public void should_allow_actual_to_have_extra_content()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = "Content", Extra = "Content" };

            logSpy.Logger.Info(content);

            Assert.True(logSpy.DidInfo(new { Some = "Content" }));
        }
コード例 #6
0
        public void should_allow_exceptions_to_be_matched()
        {
            var logSpy  = new LoggingSpy();
            var content = new Exception("Something went wrong");

            logSpy.Logger.Error(content);

            Assert.True(logSpy.DidError(content));
        }
コード例 #7
0
        public void should_allow_asserting_on_unboxed_arrays()
        {
            var logSpy          = new LoggingSpy();
            var expectedContent = new { Some = new[] { 1, 2 } };

            logSpy.Logger.Info(expectedContent);

            logSpy.AssertDidInfo(expectedContent);
        }
コード例 #8
0
        public void should_not_match_complex_and_value_type()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = new { Complex = false } };

            logSpy.Logger.Info(content);

            Assert.False(logSpy.DidInfo(new { Some = "Content" }));
        }
コード例 #9
0
        public void should_allow_matching_of_same_shape()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = "Content" };

            logSpy.Logger.Info(content);

            Assert.True(logSpy.DidInfo(new { Some = "Content" }));
        }
コード例 #10
0
        public void should_be_false_when_no_matching_log_found(object actual, object expected)
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = actual };

            logSpy.Logger.Info(content);

            Assert.False(logSpy.DidInfo(new { Some = expected }));
        }
コード例 #11
0
        public void should_allow_asserting_on_errors()
        {
            var logSpy          = new LoggingSpy();
            var expectedContent = new { Some = "Content" };

            logSpy.Logger.Error(expectedContent);

            Assert.True(logSpy.DidError(expectedContent));
        }
コード例 #12
0
        public void should_allow_predicates_to_be_mismatched <T>(T val)
        {
            var logSpy  = new LoggingSpy();
            var content = new { Something = val };

            logSpy.Logger.Info(content);

            Assert.False(logSpy.DidInfo(new { Something = new Predicate <string>(n => n == null ? val != null : !n.Equals(val)) }));
        }
コード例 #13
0
        public void should_allow_asserting_on_warnings()
        {
            var logSpy          = new LoggingSpy();
            var expectedContent = new { Some = "Content" };

            logSpy.Logger.Warn(expectedContent);

            logSpy.AssertDidWarn(expectedContent);
        }
コード例 #14
0
        public void should_not_assert_when_at_least_one_matching_log_found()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = "Thing" };

            logSpy.Logger.Info(new { Other = "Content" });
            logSpy.Logger.Info(content);

            logSpy.AssertDidInfo(new { Some = "Thing" });
        }
コード例 #15
0
        public void should_assert_when_no_matching_log_found(object actual, object expected)
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = actual };

            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
                                                   logSpy.AssertDidInfo(new { Some = expected })
                                                   );
        }
コード例 #16
0
        public void should_allow_asserting_on_unboxed_arrays_in_requestlog()
        {
            var logSpy          = new LoggingSpy();
            var requestLog      = logSpy.Logger.StartRequestLog();
            var expectedContent = new { Some = new[] { 1, 2 } };

            requestLog.Add(expectedContent);

            requestLog.Complete();

            logSpy.AssertDidInfo(expectedContent);
        }
コード例 #17
0
        public void should_allow_fields_to_be_ignored_with_null()
        {
            var logSpy  = new LoggingSpy();
            var content = new TestData()
            {
                Prop1 = 2, Prop2 = "to ignore"
            };

            logSpy.Logger.Info(content);

            Assert.True(logSpy.DidInfo(new TestData()
            {
                Prop1 = 2, Prop2 = null
            }));
        }
コード例 #18
0
        public void should_not_allow_null_fields_to_match_non_null()
        {
            var logSpy  = new LoggingSpy();
            var content = new TestData()
            {
                Prop1 = 2, Prop2 = null
            };

            logSpy.Logger.Info(content);

            Assert.False(logSpy.DidInfo(new TestData()
            {
                Prop1 = 2, Prop2 = "Something here"
            }));
        }
コード例 #19
0
        public void should_not_treat_dictionaries_as_collections()
        {
            var logSpy     = new LoggingSpy();
            var requestLog = logSpy.Logger.StartRequestLog();

            requestLog.Add(new Dictionary <string, object> {
                { "Blah", 1 }
            });

            requestLog.Complete();

            logSpy.AssertDidInfo(new Dictionary <string, object>()
            {
                { "Blah", new Predicate <int>(num => num >= 0) }
            });
        }
コード例 #20
0
        public void should_state_name_of_not_matching_fields(object actual, object expected)
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = actual };

            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(new { Some = expected });
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some", exception.Message);
                    throw;
                }
            });
        }
コード例 #21
0
        public void should_show_deep_path_of_fields()
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = new { Deep = new {  } } };

            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(new { Some = new { Deep = new { Field = "Field" } } });
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some.Deep.Field", exception.Message);
                    throw;
                }
            });
        }
コード例 #22
0
        public void should_state_name_of_fields_with_predicate_not_matching <T>(T val)
        {
            var logSpy  = new LoggingSpy();
            var content = new { Some = val };

            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(new { Some = new Predicate <T>(n => false) });
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some", exception.Message);
                    throw;
                }
            });
        }
コード例 #23
0
        public void should_allow_asserting_on_unboxed_arrays_fail_due_to_different_values()
        {
            var logSpy          = new LoggingSpy();
            var actualContent   = new { Some = new[] { 1, 2 } };
            var expectedContent = new { Some = new[] { 1, 3 } };

            logSpy.Logger.Info(actualContent);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(expectedContent);
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some[1]", exception.Message);
                    throw;
                }
            });
        }
コード例 #24
0
        public void should_state_name_of_not_matching_collections_failed_due_to_length()
        {
            var logSpy          = new LoggingSpy();
            var actualContent   = new { Some = new[] { 1, 2 } };
            var expectedContent = new { Some = new[] { 1, 2, 3 } };

            logSpy.Logger.Info(actualContent);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(expectedContent);
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some", exception.Message);
                    throw;
                }
            });
        }
コード例 #25
0
        public void should_state_name_of_missing_fields()
        {
            var logSpy  = new LoggingSpy();
            var content = new { };

            logSpy.Logger.Info(new { Other = "Content" });
            logSpy.Logger.Info(content);

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(new { Some = "Field", Second = 34 });
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some", exception.Message);
                    Assert.Contains("Second", exception.Message);
                    throw;
                }
            });
        }
コード例 #26
0
        public void should_allow_asserting_on_unboxed_arrays_fail_due_to_order_in_requestlog()
        {
            var logSpy          = new LoggingSpy();
            var requestLog      = logSpy.Logger.StartRequestLog();
            var actualContent   = new { Some = new[] { 1, 2 } };
            var expectedContent = new { Some = new[] { 2, 1 } };

            requestLog.Add(actualContent);

            requestLog.Complete();

            Assert.Throws <LoggingAssertionFailed>(() =>
            {
                try
                {
                    logSpy.AssertDidInfo(expectedContent);
                }
                catch (LoggingAssertionFailed exception)
                {
                    Assert.Contains("Some", exception.Message);
                    throw;
                }
            });
        }