示例#1
0
 public static Byte[] ToBytes(this OutputDebugString outputDebugString)
 {
     return(BitConverter.GetBytes(outputDebugString.ProcessId)
            .Concat(Encoding.UTF8.GetBytes(outputDebugString.Message))
            .Concat(new Byte[] { 0 })
            .ToArray());
 }
        public void TraceLevelFromMessage(String level, SystemEventLevel systemEventlevel)
        {
            processRetriever.Setup(mock => mock.GetProcessById(123)).Returns(new UnknownProcess(123));

            var message = new OutputDebugString("xUnit Source", 123, String.Format("<log4net:event level=\"{0}\"></log4net:event>", level));
            var e       = messageParser.Parse(message);

            Assert.Equal(systemEventlevel, e.Level);
        }
        public void RenderMessageIfNoParserFound()
        {
            var message    = new OutputDebugString("MySource", 123, "My Message");
            var resetEvent = new ManualResetEvent(false);

            renderer.Setup(mock => mock.Render(It.IsAny <SystemEvent>())).Callback(() => resetEvent.Set());
            parser.Setup(mock => mock.CanParseMessage("My Message")).Returns(false);

            processor.Process(message);

            Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(1)), "ManualResetEvent not signalled within expected time.");

            renderer.Verify(mock => mock.Render(It.Is((SystemEvent e) => e.ProcessName == "Process #123")), Times.Once());
            parser.Verify(mock => mock.Parse(message), Times.Never());
        }