示例#1
0
        public void ShouldNotHaveExceptionWhereThereIsntOne()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomethingElse("hey there");
            AssertContains("Exception: @@BEGIN EXCEPTION@@@@END EXCEPTION@@");
        }
示例#2
0
        public void ShouldDefaultTo0ForEventId()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomethingElse("boo!");
            AssertContains("Event ID: 0\r\n");
        }
示例#3
0
        public void ShouldDefaultSeverityToInformation()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomething(15, "xxx", 654.0);
            AssertContains("Severity: Information");
        }
示例#4
0
        public void ShouldNotReportReturnValueWhenTargetMethodIsVoid()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomethingElse("dummy");
            AssertContains(string.Format("Return value: {0}", Environment.NewLine));
        }
示例#5
0
        public void ShouldNotIncludeCallStackByDefault()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomething(5, "xy", 8.0);

            AssertContains(string.Format("@@BEGIN CALL STACK@@@@END CALL STACK@@{0}", Environment.NewLine));
        }
示例#6
0
        public void ShouldBeAbleToChangeEventId()
        {
            LoggingTarget target = CreateTarget();

            callHandler.EventId = 42;
            target.DoSomething(2, "three", 4.0);
            AssertContains("Event ID: 42\r\n");
        }
示例#7
0
        public void ShouldbeAbleToSetSeverity()
        {
            LoggingTarget target = CreateTarget();

            callHandler.Severity = TraceEventType.Critical;

            target.DoSomething(15, "xxx", 654.0);
            AssertContains("Severity: Critical");
        }
示例#8
0
        public void ShouldNotLogReturnValueIfIncludeParametersIsFalse()
        {
            LoggingTarget target = CreateTarget();

            callHandler.LogBeforeCall     = false;
            callHandler.IncludeParameters = false;
            target.DoSomething(1, "two", 3.0);
            AssertContains("Return value: \r\n");
        }
示例#9
0
        public void ShouldIncludeCallTimeByDefault()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomething(3, "bar", 43.2);

            AssertIsNotMatch(string.Format(@"{0}.+{1}{2}",
                                           afterMessage, beginCallTimeMarker, endCallTimeMarker));
        }
示例#10
0
        public void ShouldLogBeforeAndAfter()
        {
            LoggingTarget target = CreateTarget();

            target.DoSomething(3, "Not two", 6.02e23);

            AssertContains(beforeMessage);
            AssertContains(afterMessage);
        }
示例#11
0
        public void ShouldFormatCategoryReplacements()
        {
            LoggingTarget target = CreateTarget();

            callHandler.Categories.Add("Type {type}");
            callHandler.Categories.Add("Namespace {namespace}");
            target.DoSomething(54, "werw", 5340.34);
            AssertContains("Log Category: General, PIAB, Type LoggingTarget, Namespace Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.Tests");
        }
示例#12
0
        public void ShouldBeAbleToSetPriority()
        {
            LoggingTarget target = CreateTarget();

            callHandler.Priority = 15;

            target.DoSomething(14, "yyy", 543.0);

            AssertContains(string.Format("Priority: 15{0}", Environment.NewLine));
        }
示例#13
0
        public void ShouldLogBeforeOnly()
        {
            LoggingTarget target = CreateTarget();

            callHandler.LogAfterCall = false;

            target.DoSomething(5, "Why", 42.0);

            AssertContains(beforeMessage);
            AssertDoesNotContain(afterMessage);
        }
示例#14
0
        public void CallGetsLogged()
        {
            LoggingTarget target = CreateTarget();

            Assert.IsTrue(string.IsNullOrEmpty(writer.ToString()));

            target.DoSomething(1, "two", 3.0);
            string logString = writer.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(logString));
        }
示例#15
0
        public void ShouldIncludeCallStackAfter()
        {
            LoggingTarget target = CreateTarget();

            callHandler.IncludeCallStack = true;
            callHandler.LogBeforeCall    = false;
            callHandler.LogAfterCall     = true;

            target.DoSomething(2, "foo", 42.0);

            AssertIsMatch(@"@@BEGIN CALL STACK@@.+?@@END CALL STACK@@");
        }
示例#16
0
        public void ShouldLogReturnValue()
        {
            LoggingTarget target = CreateTarget();

            int    one   = 5;
            string two   = "xy";
            double three = 8.0;

            target.DoSomething(one, two, three);

            AssertContains(string.Format("Return value: {1}: {0} {2}{3}", one, two, three, Environment.NewLine));
        }
示例#17
0
        public void ShouldBeAbleToTurnCallTimeOff()
        {
            LoggingTarget target = CreateTarget();

            callHandler.IncludeCallTime = false;

            target.DoSomething(5, "zzz", 6.02e23);
            AssertIsMatch(
                string.Format(@"{0}.+{1}{2}",
                              afterMessage,
                              beginCallTimeMarker,
                              endCallTimeMarker));
        }
示例#18
0
        public void ShouldRecordExceptionInLog()
        {
            LoggingTarget target = CreateTarget();

            try
            {
                target.DoSomethingBad();
                Assert.Fail("Should not get here, should have exception");
            }
            catch (ApplicationException) { }

            AssertIsMatch("Exception: @@BEGIN EXCEPTION@@[^@]+@@END EXCEPTION@@");
        }
示例#19
0
        public void ShouldIncludeParametersByDefault()
        {
            LoggingTarget target = CreateTarget();

            int    one   = 5;
            string two   = "xy";
            double three = 8.0;

            target.DoSomething(one, two, three);

            AssertContains(string.Format("one = {0}{1}", one, Environment.NewLine));
            AssertContains(string.Format("two = {0}{1}", two, Environment.NewLine));
            AssertContains(string.Format("three = {0}{1}", three, Environment.NewLine));
        }
        public void ShouldLogOnlyToCategoriesGivenInConfig()
        {
            using (var configSource = new FileConfigurationSource("LogCallHandler.config", false))
            {
                using (var eventLog = new EventLogTracker("Application"))
                {
                    using (var injector = new PolicyInjector(configSource))
                    {
                        LoggingTarget target = injector.Create <LoggingTarget>();
                        target.DoSomething(1, "two", 3.0);
                    }

                    Assert.AreEqual(1, eventLog.NewEntries().Select(le => le.Category == "Default Category").Count());
                }
            }
        }
示例#21
0
        public void ShouldExcludeParameters()
        {
            LoggingTarget target = CreateTarget();

            callHandler.IncludeParameters = false;

            int    one   = 5;
            string two   = "xy";
            double three = 8.0;

            target.DoSomething(one, two, three);

            AssertDoesNotContain(string.Format("one = {0}{1}", one, Environment.NewLine));
            AssertDoesNotContain(string.Format("two = {0}{1}", two, Environment.NewLine));
            AssertDoesNotContain(string.Format("three = {0}{1}", three, Environment.NewLine));
        }
示例#22
0
        public void ShouldLogOnlyToCategoriesGivenInConfig()
        {
            FileConfigurationSource configSource =
                new FileConfigurationSource("LogCallHandler.config");

            EventLog eventLog = new EventLog("Application");

            int beforeEventLogEntries = eventLog.Entries.Count;

            LoggingTarget target = PolicyInjection.Create <LoggingTarget>(configSource);

            target.DoSomething(1, "two", 3.0);

            int afterEventLogEntries = eventLog.Entries.Count;

            Assert.AreEqual(beforeEventLogEntries + 1, afterEventLogEntries);
        }