예제 #1
0
 public void Asserts_Success_ExpectedValues_SubsetOf_ActualValues(
     IEnumerable <KeyValuePair <string, object> > expectedValues,
     IEnumerable <KeyValuePair <string, object> > actualValues)
 {
     // Act && Assert
     LogValuesAssert.Contains(expectedValues, actualValues);
 }
예제 #2
0
        public void DefaultComparer_Performs_CaseSensitiveComparision(
            IEnumerable <KeyValuePair <string, object> > expectedValues,
            IEnumerable <KeyValuePair <string, object> > actualValues)
        {
            // Act && Assert
            var equalException = Assert.Throws <EqualException>(
                () => LogValuesAssert.Contains(expectedValues, actualValues));

            Assert.Equal(GetString(expectedValues), equalException.Expected);
            Assert.Equal(GetString(actualValues), equalException.Actual);
        }
예제 #3
0
        public void Asserts_Failure_ExpectedValues_MoreThan_ActualValues(
            IEnumerable <KeyValuePair <string, object> > expectedValues,
            IEnumerable <KeyValuePair <string, object> > actualValues)
        {
            // Act && Assert
            var equalException = Assert.Throws <EqualException>(
                () => LogValuesAssert.Contains(expectedValues, actualValues));

            Assert.Equal(GetString(expectedValues), equalException.Expected);
            Assert.Equal(GetString(actualValues), equalException.Actual);
        }
예제 #4
0
        public void Asserts_Success_OnSpecifiedKeyAndValue()
        {
            // Arrange
            var actualLogValues = new[]
            {
                new KeyValuePair <string, object>("RouteConstraint", "Something"),
                new KeyValuePair <string, object>("RouteKey", "id"),
                new KeyValuePair <string, object>("RouteValue", "Failure"),
            };

            // Act && Assert
            LogValuesAssert.Contains("RouteKey", "id", actualLogValues);
        }
예제 #5
0
        public async Task ShouldBeginScopeWithParameter()
        {
            // Arrange

            // Act
            await _factory.CreateDefaultClient().GetAsync("/");

            // Assert
            var scope = Assert.Single(_sink.Scopes);

            // Assert specific parameters in the log scope
            LogValuesAssert.Contains("name", "GET", scope);
        }
예제 #6
0
        public async Task ShouldLogWithWorldAsPlace()
        {
            // Arrange

            // Act
            await _factory.CreateDefaultClient().GetAsync("/");

            // Assert
            var log = Assert.Single(_sink.LogEntries);

            // Assert specific parameters in the log entry
            LogValuesAssert.Contains("place", "World", log);
        }
예제 #7
0
        public async Task ShouldUseScopeWithParameter()
        {
            // Arrange

            // Act
            await _factory.CreateDefaultClient().GetAsync("/");

            // Assert
            Assert.Equal(1, _sink.Writes.Count);
            var log   = _sink.Writes.Single();
            var scope = Assert.IsAssignableFrom <IEnumerable <KeyValuePair <string, object> > >(log.Scope);

            // Assert specific parameters in the log scope
            LogValuesAssert.Contains("name", "GET", scope);
        }
예제 #8
0
        public async Task ShouldLogWithWorldAsPlace()
        {
            // Arrange

            // Act
            await _factory.CreateDefaultClient().GetAsync("/");

            // Assert
            Assert.Equal(1, _sink.Writes.Count);
            var log   = _sink.Writes.Single();
            var state = Assert.IsAssignableFrom <IEnumerable <KeyValuePair <string, object> > >(log.State);

            // Assert specific parameters in the log entry
            LogValuesAssert.Contains("place", "World", state);
        }
예제 #9
0
        public void DoSomethingLogsCorrectParameter()
        {
            // Arrange
            var loggerFactory = MELTBuilder.CreateLoggerFactory();
            var logger        = loggerFactory.CreateLogger <Sample>();
            var sample        = new Sample(logger);

            // Act
            sample.DoSomething();

            // Assert
            var log = Assert.Single(loggerFactory.LogEntries);

            // Assert specific parameters in the log entry
            LogValuesAssert.Contains("number", 42, log);
        }
예제 #10
0
        public void Asserts_Success_IgnoringOrderOfItems()
        {
            // Arrange
            var expectedLogValues = new[]
            {
                new KeyValuePair <string, object>("RouteConstraint", "Something"),
                new KeyValuePair <string, object>("RouteValue", "Failure"),
                new KeyValuePair <string, object>("RouteKey", "id")
            };
            var actualLogValues = new[]
            {
                new KeyValuePair <string, object>("RouteKey", "id"),
                new KeyValuePair <string, object>("RouteConstraint", "Something"),
                new KeyValuePair <string, object>("RouteValue", "Failure"),
            };

            // Act && Assert
            LogValuesAssert.Contains(expectedLogValues, actualLogValues);
        }
예제 #11
0
        public void DoSomethingLogsCorrectParameter()
        {
            // Arrange
            var sink          = new TestSink();
            var loggerFactory = new TestLoggerFactory(sink);
            var logger        = loggerFactory.CreateLogger <Sample>();
            var sample        = new Sample(logger);

            // Act
            sample.DoSomething();

            // Assert
            Assert.Equal(1, sink.Writes.Count);
            var log   = sink.Writes.Single();
            var state = Assert.IsAssignableFrom <IEnumerable <KeyValuePair <string, object> > >(log.State);

            // Assert specific parameters in the log entry
            LogValuesAssert.Contains("number", 42, state);
        }
예제 #12
0
        public void DoSomethingLogsUsingCorrectFormat()
        {
            // Arrange
            var sink          = new TestSink();
            var loggerFactory = new TestLoggerFactory(sink);
            var logger        = loggerFactory.CreateLogger <Sample>();
            var sample        = new Sample(logger);

            // Act
            sample.DoSomething();

            // Assert
            Assert.Equal(1, sink.Writes.Count);
            var log   = sink.Writes.Single();
            var state = Assert.IsAssignableFrom <IEnumerable <KeyValuePair <string, object> > >(log.State);

            // Assert the the log format template
            LogValuesAssert.Contains("{OriginalFormat}", "The answer is {number}", state);
        }
예제 #13
0
        public void DoExceptionalLogsException()
        {
            // Arrange
            var loggerFactory = MELTBuilder.CreateLoggerFactory();
            var logger        = loggerFactory.CreateLogger <Sample>();
            var sample        = new Sample(logger);

            // Act
            sample.DoExceptional();

            // Assert
            var log = Assert.Single(loggerFactory.LogEntries);

            // Assert the message rendered by a default formatter
            Assert.Equal("There was a problem", log.Message);
            // Assert specific parameters in the log entry
            LogValuesAssert.Contains("error", "problem", log);
            // Assert the exception
            var exception = Assert.IsType <ArgumentNullException>(log.Exception);

            Assert.Equal("foo", exception.ParamName);
        }