Ejemplo n.º 1
0
        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});
        }
Ejemplo n.º 2
0
        public void Constructor_throws_if_passed_null_encoder()
        {
            var byteWriter = Substitute.For<IByteWriter>();

              // ReSharper disable once UnusedVariable
              var logWriter = new LogWriter(null, new[] {byteWriter});
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        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[]>());
        }
Ejemplo n.º 6
0
        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[]>());
        }