コード例 #1
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[]>());
        }
コード例 #2
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[]>());
        }