public void ReceiveMSMQMessage() { SendMessageToQ(CommonUtil.MsgBody); msmqDistributor.CheckForMessages(); Assert.AreEqual(1, MockLogSink.Count); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message, "Body"); }
public void HandleTest() { Assert.IsFalse(ExceptionPolicy.HandleException(new Exception("TEST EXCEPTION"), "Logging Policy")); Assert.AreEqual("TestCat", MockLogSink.GetLastEntry().Category); Assert.AreEqual(5, MockLogSink.GetLastEntry().EventId); Assert.AreEqual(Severity.Error, MockLogSink.GetLastEntry().Severity); Assert.AreEqual("TestTitle", MockLogSink.GetLastEntry().Title); //Console.Write(MockLogSink.MessageBody); }
public void ConstructorProducesValidLogMessage() { using (new Tracer(Context, testCategory1, testActivityId1)) { } Assert.AreEqual(2, MockLogSink.Count); AssertLogEntryIsValid(MockLogSink.GetEntry(0), Tracer.startTitle, testCategory1, testActivityId1, true); AssertLogEntryIsValid(MockLogSink.GetEntry(1), Tracer.endTitle, testCategory1, testActivityId1, false); }
public void LogMessageContainsProperMethodName() { using (Tracer tracer = new Tracer(Context, Tracer.defaultCategory, null)) { Assert.IsNotNull(tracer); } Assert.AreEqual(2, MockLogSink.Count); AssertStringContainsString(MockLogSink.GetEntry(0).Message, MethodInfo.GetCurrentMethod().Name); AssertStringContainsString(MockLogSink.GetEntry(1).Message, MethodInfo.GetCurrentMethod().Name); }
public void AddItemThenLog() { Logger.SetContextItem("AppVersion", "1234"); LogEntry log = new LogEntry(); log.Category = "MockCategoryOne"; Logger.Write(log); Assert.AreEqual(1, MockLogSink.GetLastEntry().ExtendedProperties.Count); Assert.AreEqual("1234", MockLogSink.GetLastEntry().ExtendedProperties["AppVersion"]); }
public void ReuseLogEntryForMultipleWrites() { log.Category = "MockCategoryOne"; log.Message = "apples"; Logger.Write(log); Assert.AreEqual("apples", MockLogSink.GetLastEntry().Message); log.Message = "oranges"; Logger.Write(log); Assert.AreEqual("oranges", MockLogSink.GetLastEntry().Message); }
public void SendMessageInProc() { InProcLogDistributionStrategy ip = new InProcLogDistributionStrategy(); ip.ConfigurationName = "InProc"; ip.Initialize(new LoggingConfigurationView(Context)); LogEntry msg = CommonUtil.GetDefaultLogEntry(); msg.Category = "MockCategoryOne"; ip.SendLog(msg); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message); }
public void SendTwoMessagesWithPauseReceiving() { SendMessageToQ(CommonUtil.MsgBody); SendMessageToQ(CommonUtil.MsgBody + " 4 5 6"); // By setting StopRecieving = true, only one message will be processed from the Q msmqDistributor.StopReceiving = true; msmqDistributor.CheckForMessages(); // confirm that the second message was NOT processed by the sink Assert.AreEqual(1, MockLogSink.Count); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message); msmqDistributor.CheckForMessages(); }
public void ReceiveTwoMessages() { SendMessageToQ(CommonUtil.MsgBody); SendMessageToQ(CommonUtil.MsgBody + " 4 5 6"); Assert.AreEqual(2, CommonUtil.GetNumberOfMessagesOnQueue()); msmqDistributor.CheckForMessages(); Assert.AreEqual(0, CommonUtil.GetNumberOfMessagesOnQueue()); // confirm that the second message was processed by the sink Assert.AreEqual(2, MockLogSink.Count); Assert.AreEqual(CommonUtil.MsgBody + " 4 5 6", MockLogSink.GetLastEntry().Message); }
public void AddItemsAndDictionaryThenLog() { Logger.SetContextItem("AppVersion", "1234"); Logger.SetContextItem("BuildNumber", "5678"); LogEntry log = new LogEntry(); log.Category = "MockCategoryOne"; log.ExtendedProperties = CommonUtil.GetPropertiesHashtable(); Logger.Write(log); Assert.AreEqual(5, MockLogSink.GetLastEntry().ExtendedProperties.Count); Assert.AreEqual("1234", MockLogSink.GetLastEntry().ExtendedProperties["AppVersion"]); Assert.AreEqual("5678", MockLogSink.GetLastEntry().ExtendedProperties["BuildNumber"]); }
public void SendMessageToManySinks() { const string category = "MockCategoryMany"; // build a message LogEntry msg = CommonUtil.GetDefaultLogEntry(); msg.Category = category; logDistributor.ProcessLog(msg); Assert.AreEqual(2, MockLogSink.Count); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message, "Body"); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message, "Body"); }
public void SendToCustomLogEntrySinkAndMockSink() { SetInProcDistributionStrategy(); CustomLogEntry customEntry = GetCustomLogEntry(); customEntry.Category = "MixedCategory"; Logger.Write(customEntry); Assert.AreEqual(CustomLogEntrySink.fullMessage, MockLogSink.FormatLogEntry(MockLogSink.GetLastEntry())); Assert.AreEqual(CustomLogEntrySink.Body, MockLogSink.GetLastEntry().Message); Assert.AreEqual(CustomLogEntrySink.EventID, MockLogSink.GetLastEntry().EventId); Assert.AreEqual(CustomLogEntrySink.Category, MockLogSink.GetLastEntry().Category); }
public void FlushItems() { Logger.SetContextItem("AppVersion", "1234"); Logger.SetContextItem("BuildNumber", "5678"); LogEntry log = new LogEntry(); log.Category = "MockCategoryOne"; log.ExtendedProperties = CommonUtil.GetPropertiesHashtable(); Logger.FlushContextItems(); Logger.Write(log); Assert.AreEqual(3, MockLogSink.GetLastEntry().ExtendedProperties.Count); Assert.IsNull(MockLogSink.GetLastEntry().ExtendedProperties["AppVersion"]); Assert.IsNull(MockLogSink.GetLastEntry().ExtendedProperties["BuildNumber"]); }
public void AddObjectAsContextItem() { ContextObject obj = new ContextObject(); Logger.SetContextItem("object", obj); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Category = "MockCategoryOne"; Logger.Write(log); string result = MockLogSink.GetLastEntry().ExtendedProperties["object"].ToString(); string expected = obj.ToString(); Assert.AreEqual(expected, result); }
public void SendToMockSink() { SetInProcDistributionStrategy(); CustomLogEntry customLog = GetCustomLogEntry(); Logger.Write(customLog); CustomLogEntry deserializedLog = (CustomLogEntry)MockLogSink.GetLastEntry(); Assert.AreEqual(customLog.AcmeCoField1, deserializedLog.AcmeCoField1); Assert.AreEqual(customLog.AcmeCoField2, deserializedLog.AcmeCoField2); Assert.AreEqual(customLog.AcmeCoField3, deserializedLog.AcmeCoField3); Assert.AreEqual(customLog.Category, deserializedLog.Category); Assert.AreEqual(customLog.Message, deserializedLog.Message); }
public void NestedConstructorProducesFourCorrectLogMessages() { using (new Tracer(Context, testCategory1, null)) { string activityId = Tracer.CurrentActivityId; using (new Tracer(Context, testCategory1, null)) { Assert.AreEqual(activityId, Tracer.CurrentActivityId); } } Assert.AreEqual(4, MockLogSink.Count); AssertLogEntryIsValid(MockLogSink.GetEntry(0), Tracer.startTitle, testCategory1, null, true); AssertLogEntryIsValid(MockLogSink.GetEntry(1), Tracer.startTitle, testCategory1, null, true); AssertLogEntryIsValid(MockLogSink.GetEntry(2), Tracer.endTitle, testCategory1, null, false); AssertLogEntryIsValid(MockLogSink.GetEntry(3), Tracer.endTitle, testCategory1, null, false); }
public void SendMessageToOneSink() { const string category = "MockCategoryOne"; // build a message LogEntry msg = CommonUtil.GetDefaultLogEntry(); msg.Category = category; logDistributor.ProcessLog(msg); Assert.AreEqual(1, MockLogSink.Count); Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message, "Body"); Assert.AreEqual(CommonUtil.MsgTitle, MockLogSink.GetLastEntry().Title, "Header"); Assert.AreEqual(category, MockLogSink.GetLastEntry().Category, "Category"); Assert.AreEqual(CommonUtil.MsgEventID, MockLogSink.GetLastEntry().EventId, "EventID"); Assert.AreEqual(Severity.Unspecified, MockLogSink.GetLastEntry().Severity, "Severity"); }
public void MissingDefaultFormatter() { DistributorSettings settings = (DistributorSettings)Context.GetConfiguration(DistributorSettings.SectionName); string originalFormatter = settings.DefaultFormatter; settings.DefaultFormatter = null; LogEntry entry = CommonUtil.GetDefaultLogEntry(); entry.Category = "AppError"; logDistributor.ProcessLog(entry); string eventLogEntry = CommonUtil.GetLastEventLogEntry(); Assert.IsTrue(eventLogEntry.IndexOf(SR.MissingDefaultFormatter) > -1, "formatter message"); Assert.AreEqual(entry.Message, MockLogSink.GetLastEntry().Message, "message"); Assert.AreEqual(entry.Category, MockLogSink.GetLastEntry().Category, "categry"); settings.DefaultFormatter = originalFormatter; }
public void ActivityIdsAreUniqueOnEachThread() { // This will put two events into the sink using testCategory2 and testActivityId2 using (new Tracer(Context, testCategory2, testActivityId2)) { // This will put two events into the sink using testCategory1 and testActivityId1 CrossThreadTestRunner t = new CrossThreadTestRunner(new ThreadStart(this.DoOtherThreadWork)); t.Run(); // Confirm that the Tracer on this thread has the expected activityID Assert.AreEqual(testActivityId2, Tracer.CurrentActivityId); } Assert.AreEqual(null, Tracer.CurrentActivityId); Assert.AreEqual(4, MockLogSink.Count); AssertLogEntryIsValid(MockLogSink.GetEntry(0), Tracer.startTitle, testCategory2, testActivityId2, true); AssertLogEntryIsValid(MockLogSink.GetEntry(1), Tracer.startTitle, testCategory1, testActivityId1, true); AssertLogEntryIsValid(MockLogSink.GetEntry(2), Tracer.endTitle, testCategory1, testActivityId1, false); AssertLogEntryIsValid(MockLogSink.GetEntry(3), Tracer.endTitle, testCategory2, testActivityId2, false); }
public void CustomContextByteArrayObject() { Guid expectedGuid = Guid.NewGuid(); byte[] byteArray = expectedGuid.ToByteArray(); Logger.SetContextItem("bytes", byteArray); LogEntry log = CommonUtil.GetDefaultLogEntry(); log.Category = "MockCategoryOne"; Logger.Write(log); // get body and parse out the byte array and go back to the guid form string guidArray = MockLogSink.GetLastEntry().ExtendedProperties["bytes"].ToString(); byteArray = Convert.FromBase64String(guidArray); Guid resultGuid = new Guid(byteArray); Assert.AreEqual(expectedGuid, resultGuid); }
public void TearDown() { MockLogSink.Clear(); }
public void TearDown() { SetInProcDistributionStrategy(); MockLogSink.Clear(); }
public void Teardown() { Logger.FlushContextItems(); MockLogSink.Clear(); }
public void TearDown() { CommonUtil.DeletePrivateTestQ(); MockLogSink.Clear(); }