public void ShouldNotHaveExceptionWhereThereIsntOne() { LoggingTarget target = CreateTarget(); target.DoSomethingElse("hey there"); AssertContains("Exception: @@BEGIN EXCEPTION@@@@END EXCEPTION@@"); }
public void ShouldDefaultTo0ForEventId() { LoggingTarget target = CreateTarget(); target.DoSomethingElse("boo!"); AssertContains("Event ID: 0\r\n"); }
public void ShouldDefaultSeverityToInformation() { LoggingTarget target = CreateTarget(); target.DoSomething(15, "xxx", 654.0); AssertContains("Severity: Information"); }
public void ShouldNotReportReturnValueWhenTargetMethodIsVoid() { LoggingTarget target = CreateTarget(); target.DoSomethingElse("dummy"); AssertContains(string.Format("Return value: {0}", Environment.NewLine)); }
public void ShouldNotIncludeCallStackByDefault() { LoggingTarget target = CreateTarget(); target.DoSomething(5, "xy", 8.0); AssertContains(string.Format("@@BEGIN CALL STACK@@@@END CALL STACK@@{0}", Environment.NewLine)); }
public void ShouldBeAbleToChangeEventId() { LoggingTarget target = CreateTarget(); callHandler.EventId = 42; target.DoSomething(2, "three", 4.0); AssertContains("Event ID: 42\r\n"); }
public void ShouldbeAbleToSetSeverity() { LoggingTarget target = CreateTarget(); callHandler.Severity = TraceEventType.Critical; target.DoSomething(15, "xxx", 654.0); AssertContains("Severity: Critical"); }
public void ShouldNotLogReturnValueIfIncludeParametersIsFalse() { LoggingTarget target = CreateTarget(); callHandler.LogBeforeCall = false; callHandler.IncludeParameters = false; target.DoSomething(1, "two", 3.0); AssertContains("Return value: \r\n"); }
public void ShouldIncludeCallTimeByDefault() { LoggingTarget target = CreateTarget(); target.DoSomething(3, "bar", 43.2); AssertIsNotMatch(string.Format(@"{0}.+{1}{2}", afterMessage, beginCallTimeMarker, endCallTimeMarker)); }
public void ShouldLogBeforeAndAfter() { LoggingTarget target = CreateTarget(); target.DoSomething(3, "Not two", 6.02e23); AssertContains(beforeMessage); AssertContains(afterMessage); }
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"); }
public void ShouldBeAbleToSetPriority() { LoggingTarget target = CreateTarget(); callHandler.Priority = 15; target.DoSomething(14, "yyy", 543.0); AssertContains(string.Format("Priority: 15{0}", Environment.NewLine)); }
public void ShouldLogBeforeOnly() { LoggingTarget target = CreateTarget(); callHandler.LogAfterCall = false; target.DoSomething(5, "Why", 42.0); AssertContains(beforeMessage); AssertDoesNotContain(afterMessage); }
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)); }
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@@"); }
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)); }
public void ShouldBeAbleToTurnCallTimeOff() { LoggingTarget target = CreateTarget(); callHandler.IncludeCallTime = false; target.DoSomething(5, "zzz", 6.02e23); AssertIsMatch( string.Format(@"{0}.+{1}{2}", afterMessage, beginCallTimeMarker, endCallTimeMarker)); }
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@@"); }
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()); } } }
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)); }
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); }