Skip to content

Commit

Permalink
Minor unit test tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jun 22, 2023
1 parent 36ffe22 commit dfec477
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ public void SendData_ShouldNotCallAuditLog_UnlessAuditLogIsEnabled(bool isEnable

var collectorWire = CreateHttpCollectorWire();

// ensure that .ForContext() just returns the mock logger instance
var mockForContextLogger = Mock.Create<ILogger>();
Mock.Arrange(() => _mockILogger.ForContext(Arg.AnyString, Arg.AnyObject, false))
.Returns(() => _mockILogger);
.Returns(() => mockForContextLogger);

AuditLog.IsAuditLogEnabled = isEnabled;

// Act
var response = collectorWire.SendData("test_method", connectionInfo, serializedData, Guid.NewGuid());

// Assert
Mock.Assert(() => _mockILogger.Fatal(Arg.AnyString), isEnabled ? Occurs.Exactly(3) : Occurs.Never());
Mock.Assert(() => mockForContextLogger.Fatal(Arg.AnyString), isEnabled ? Occurs.Exactly(3) : Occurs.Never());
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Agent/UnitTests/Core.UnitTest/Logging/AuditLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public void ExcludeAuditLog_DisablesAuditLog()
[TestCase(true)]
public void Log_OnlyLogsWhenAuditLogEnabled(bool logEnabled)
{
// ensure that .ForContext() just returns the mock logger instance
var mockForContextLogger = Mock.Create<ILogger>();
Mock.Arrange(() => _mockILogger.ForContext(Arg.AnyString, Arg.AnyObject, false))
.Returns(() => _mockILogger);
.Returns(() => mockForContextLogger);

AuditLog.IsAuditLogEnabled = logEnabled;

var message = "This is an audit message";

AuditLog.Log(message);

Mock.Assert(() => _mockILogger.Fatal(message), logEnabled ? Occurs.Once() : Occurs.Never());
Mock.Assert(() => mockForContextLogger.Fatal(message), logEnabled ? Occurs.Once() : Occurs.Never());
}
}
}

0 comments on commit dfec477

Please sign in to comment.