public void ReceiveMSMQMessage()
        {
            SendMessageToQ(CommonUtil.MsgBody);

            msmqDistributor.CheckForMessages();

            Assert.AreEqual(1, MockLogSink.Count);
            Assert.AreEqual(CommonUtil.MsgBody, MockLogSink.GetLastEntry().Message, "Body");
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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 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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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");
        }
Пример #8
0
        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 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();
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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"]);
        }
Пример #14
0
        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");
        }
Пример #15
0
        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;
        }
Пример #16
0
        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);
        }