public void Asserts_Success_ExpectedValues_SubsetOf_ActualValues( IEnumerable <KeyValuePair <string, object> > expectedValues, IEnumerable <KeyValuePair <string, object> > actualValues) { // Act && Assert LogValuesAssert.Contains(expectedValues, actualValues); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }