Esempio n. 1
0
        public void AppendShouldProduceLog()
        {
            var file          = "file1.txt";
            var appender      = new FileAppender(file);
            var streamFactory = new Mock <IStreamFactory>();
            var stream        = new MemoryStream();
            var streamWriter  = new StreamWriter(stream);

            streamFactory.Setup(x => x.CreateStreamWriter(It.IsAny <string>())).Returns(streamWriter);
            appender.SetField("_factory", streamFactory.Object);
            appender.Append(BuidLogEvent("My Topic", "My Message"));
            streamWriter.Flush();

            var res      = GetResult(stream);
            var expected = _dateString
                           + " - [Info] My Topic: My Message ["
                           + Thread.CurrentThread.ManagedThreadId + "]"
                           + Environment.NewLine;

            Assert.Equal(expected, res);

            appender.Append(BuidLogEvent("My Topic2", "My Message2"));
            streamWriter.Flush();
            res = GetResult(stream);
            appender.Dispose();
            expected = _dateString
                       + " - [Info] My Topic2: My Message2 ["
                       + Thread.CurrentThread.ManagedThreadId + "]"
                       + Environment.NewLine;
            Assert.Equal(expected, res);
        }
Esempio n. 2
0
        public void IntegrationTestWithFileShouldProduceExpectedResult()
        {
            var file     = "file.txt";
            var appender = new FileAppender(file);

            appender.Append(BuidLogEvent("My Topic", "My Message"));
            appender.Dispose();
            var reader   = File.OpenText(file);
            var result   = reader.ReadToEnd();
            var expected = _dateString
                           + " - [Info] My Topic: My Message ["
                           + Thread.CurrentThread.ManagedThreadId + "]"
                           + Environment.NewLine;

            Assert.Equal(expected, result);
        }