protected override void RunTestLog(log4net.ILog log) { log4net.GlobalContext.Properties["OurCompany.ApplicationName"] = "fubar"; log.Info(4); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); var procid = Process.GetCurrentProcess().Id; StringAssert.StartsWith(@"{""OurCompany.ApplicationName"":""fubar""", le, "log line"); StringAssert.Contains(@",""Host"":{", le, "log line"); StringAssert.Contains(@"""ProcessId"":" + procid, le, "log line"); StringAssert.Contains(@"""HostName"":""" + Environment.MachineName + @"""", le, "log line"); StringAssert.Contains(@"""A"":""L-INFO-log4net.Ext.Json.Xunit.Layout.Arrangements.Members""", le, "log line"); StringAssert.Contains(@"""B"":""" + DateTime.Now.Year + @"""", le, "log line"); StringAssert.Contains(@"""App"":""", le, "log line"); // fix #3, do not use member name as a default value StringAssert.DoesNotContain("empty1", le); StringAssert.DoesNotContain("empty2", le); }
protected override void RunTestLog(log4net.ILog log) { using (log4net.ThreadContext.Stacks["NDC"].Push("TestLog")) { log4net.ThreadContext.Properties["data"] = new { A = 1, B = new { X = "Y" } }; using (log4net.ThreadContext.Stacks["NDC"].Push("sub section")) { log.Info("OK"); } }; var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""data"":{", le, "le2 has structured message"); StringAssert.Contains(@"""X"":""Y""", le, "le2 has structured message"); StringAssert.Contains(@"""A"":1", le, "le2 has structured message"); StringAssert.Contains(@"""TestLog sub section""", le, "le1 has structured message"); StringAssert.DoesNotContain(@"""exception""", le, "le2 has no exception"); }
protected override void RunTestLog(log4net.ILog log) { var appenders = GetAppenders <TestAppender>(log.Logger); Assert.AreEqual(1, appenders.Length, "appenders Count"); var tapp = appenders.Single(); Assert.IsInstanceOf <SerializedLayout>(tapp.Layout, "layout type"); var layout = ((SerializedLayout)tapp.Layout); Assert.IsInstanceOf <JsonPatternConverter>(layout.SerializingConverter, "converter type"); var converter = ((JsonPatternConverter)layout.SerializingConverter); Assert.IsInstanceOf <JsonDotNetRenderer>(converter.Renderer, "renderer type"); var renderer = ((JsonDotNetRenderer)converter.Renderer); log.Info(new { A = 1, B = new { X = "Y" } }); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"{""message"":{""A"":1,""B"":{""X"":""Y""}}}", le, "le has structured message"); }
protected override void RunTestLog(log4net.ILog log) { log.Info(new { A = 1, B = new { X = "Y" } }); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""message"":""{ A = 1, B = { X = Y } }""", le, "le has structured message"); }
protected override void RunTestLog(log4net.ILog log) { log.Info(new { A = 1, B = new { X = DateTime.Parse("2014-01-01") } }); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""A"":1", le, "le has structured message"); StringAssert.Contains(@"""X"":""2014-01-01T00:00:00.0000000""", le, "le has structured message"); }
protected override void RunTestLog(log4net.ILog log) { using (log4net.ThreadContext.Stacks["NDC"].Push("TestLog")) { log4net.ThreadContext.Properties["data"] = new { A = 1, B = new { X = "Y" } }; using (log4net.ThreadContext.Stacks["NDC"].Push("sub section")) { try { throw new InvalidProgramException("test"); } catch (InvalidProgramException x) { log.Error("Exception caught", x); } } }; var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""data.A"":1", le, "le2 has structured message"); StringAssert.Contains(@"""data.B.X"":""Y""", le, "le2 has structured message"); StringAssert.Contains(@"""TestLog sub section""", le, "le1 has structured message"); StringAssert.Contains(@"""exception"":""System.InvalidProgramException: test", le, "le2 has structured message"); // curiously, the properties set within the NDC are still here... not my fault. log.Info(null); events = GetEventStrings(log.Logger); Assert.AreEqual(2, events.Length, "events Count"); le = events.Last(); Assert.IsNotNull(le, "loggingevent"); Assert.AreEqual(@"{""data.A"":1,""data.B.X"":""Y""}" + Environment.NewLine, le, "le2 has structured message"); }
public void Serialize(object value, string expectedJsonDotNet, string expectedHomeMade) { var wrJsonDotNet = new StringWriter(); _serializerJsonDotNet.RenderObject(null, value, wrJsonDotNet); var resultJsonDotNet = wrJsonDotNet.ToString(); StringAssert.StartsWith(expectedJsonDotNet, resultJsonDotNet, String.Format("JsonDotNet serialized {0}", value)); var wrHomeMade = new StringWriter(); _serializerHomeMade.RenderObject(null, value, wrHomeMade); var resultHomeMade = wrHomeMade.ToString(); StringAssert.StartsWith(expectedHomeMade, resultHomeMade, String.Format("HomeMade serialized {0}", value)); }
public void StartJob_ConfEntitysNotCreated_ExceptionThrown_ZeroValues() { var mockConfigReader = new Mock <IConfigReader>(); var mockConfigVerifier = new Mock <IConfigVerifier>(); var mockMailMonitor = new Mock <IMailMonitor>(); mockConfigReader .Setup(x => x.ReadConfig()) .Returns(new List <ConfigEntity>()); var businessLogic = new MailBusinessLogic(mockConfigReader.Object, mockConfigVerifier.Object, mockMailMonitor.Object); string message = "Файл конфигурации пуст!"; var ex = Assert.ThrowsAsync <ArgumentException>(() => businessLogic.StartJob(Token)); StringAssert.Contains(message, ex.Message); }
protected override void RunTestLog(log4net.ILog log) { log.Info(4); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""date"":", le, "log line has date"); StringAssert.Contains(@"""message"":", le, "log line has message"); StringAssert.Contains(@"""logger"":", le, "log line has logger"); StringAssert.Contains(@"""level"":", le, "log line has level"); }
protected override void RunTestLog(log4net.ILog log) { log.Info(4); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""EventTime"":", le, "log line has EventTime"); StringAssert.Contains(@"""Message"":", le, "log line has Message"); StringAssert.Contains(@"""Logger"":", le, "log line has Logger"); StringAssert.Contains(@"""Severity"":", le, "log line has Severity"); }
public void MailMonitor_StartMonitorTask_SeenUidsManager_Write_ExceptionThrown() { var mockMailProvider = new Mock <IMailProvider>(); var mockMailAction = new Mock <IMailAction>(); var mockSeenUidsManager = new Mock <ISeenUidsManager>(); mockMailProvider .Setup(x => x.GetAllMessages(ConfigEntity)) .Returns(MailTransfer); mockSeenUidsManager .Setup(x => x.Write(It.IsAny <ConfigEntity>(), It.IsAny <List <string> >(), It.IsAny <bool>())) .Returns(false); var mailMonitor = new MailMonitor(mockMailProvider.Object, mockMailAction.Object, mockSeenUidsManager.Object); string message = "Ошибка при сохранении Uid прочитанных писем"; var ex = Assert.Throws <ApplicationException>(() => mailMonitor.StartMonitorTask(ConfigEntity)); StringAssert.Contains(message, ex.Message); }
public void StartJob_Verify_Config_ExceptionThrown_ReturnFalse() { var mockConfigReader = new Mock <IConfigReader>(); var mockConfigVerifier = new Mock <IConfigVerifier>(); var mockMailMonitor = new Mock <IMailMonitor>(); List <ConfigEntity> configEntityList = new List <ConfigEntity> { ConfigEntity }; mockConfigReader .Setup(x => x.ReadConfig()) .Returns(configEntityList); mockConfigVerifier .Setup(x => x.Verify(configEntityList)) .Returns(false); var businessLogic = new MailBusinessLogic(mockConfigReader.Object, mockConfigVerifier.Object, mockMailMonitor.Object); string message = "Проверка завершена с ошибкой!"; var ex = Assert.ThrowsAsync <ArgumentException>(() => businessLogic.StartJob(Token)); StringAssert.Contains(message, ex.Message); }