コード例 #1
0
ファイル: LogWriterTest.cs プロジェクト: mmurdoch/Logging
        public void Constructor_throws_if_passed_null_writer()
        {
            var encoder = Substitute.For<ILogEncoder>();

              // ReSharper disable once UnusedVariable
              var logWriter = new LogWriter(encoder, new IByteWriter[] {null});
        }
コード例 #2
0
ファイル: LogWriterTest.cs プロジェクト: mmurdoch/Logging
        public void Constructor_throws_if_passed_null_encoder()
        {
            var byteWriter = Substitute.For<IByteWriter>();

              // ReSharper disable once UnusedVariable
              var logWriter = new LogWriter(null, new[] {byteWriter});
        }
コード例 #3
0
ファイル: LogWriterTest.cs プロジェクト: mmurdoch/Logging
        public void Default_stack_frames_to_encode_is_three()
        {
            var encoder = Substitute.For<ILogEncoder>();
              var byteWriter = Substitute.For<IByteWriter>();

              var logWriter = new LogWriter(encoder, new[] {byteWriter});

              Assert.AreEqual(3, logWriter.StackFramesToEncode);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: mmurdoch/Logging
        private static void Main(string[] args)
        {
            var logEncoder = new XmlLogEncoder();
              var byteWriter = new LazyStreamByteWriter(FileStreamFactory.CreateApplicationDataFileStream);
              var logWriter = new LogWriter(logEncoder, new[] {byteWriter});
              Logger.AddLogWriter(logWriter);

              Logger.Log(LogLevel.Error, "message");
        }
コード例 #5
0
ファイル: LogWriterTest.cs プロジェクト: mmurdoch/Logging
        public void Log_encodes_using_encoder_then_writes_using_all_byte_writers()
        {
            const LogLevel level = LogLevel.Error;
              const string message = "Test Message";
              var stackTrace = Substitute.For<StackTrace>();

              var encoder = Substitute.For<ILogEncoder>();

              var byteWriter1 = Substitute.For<IByteWriter>();
              var byteWriter2 = Substitute.For<IByteWriter>();

              var logWriter = new LogWriter(encoder, new[] {byteWriter1, byteWriter2}) {StackFramesToEncode = 4};

              logWriter.Log(level, message, stackTrace);

              encoder.Received(1).EncodeLogMessage(level, message, stackTrace, logWriter.StackFramesToEncode);
              byteWriter1.Received(1).WriteBytes(Arg.Any<byte[]>());
              byteWriter2.Received(1).WriteBytes(Arg.Any<byte[]>());
        }
コード例 #6
0
ファイル: LogWriterTest.cs プロジェクト: mmurdoch/Logging
        public void Write_does_not_occur_if_encoder_returns_null_bytes()
        {
            const LogLevel level = LogLevel.Error;
              const string message = "Test Message";
              var stackTrace = Substitute.For<StackTrace>();

              var encoder = Substitute.For<ILogEncoder>();
              var byteWriter = Substitute.For<IByteWriter>();

              var logWriter = new LogWriter(encoder, new[] {byteWriter});
              logWriter.StackFramesToEncode = 4;

              encoder.EncodeLogMessage(Arg.Any<LogLevel>(), Arg.Any<string>(), Arg.Any<StackTrace>(), Arg.Any<int>()).Returns(x => null);

              logWriter.Log(level, message, stackTrace);

              encoder.Received(1).EncodeLogMessage(Arg.Any<LogLevel>(), Arg.Any<string>(), Arg.Any<StackTrace>(), Arg.Any<int>());
              byteWriter.DidNotReceive().WriteBytes(Arg.Any<byte[]>());
        }