Extensions.Logging.Mock
1.1.0
See the version list below for details.
dotnet add package Extensions.Logging.Mock --version 1.1.0
NuGet\Install-Package Extensions.Logging.Mock -Version 1.1.0
<PackageReference Include="Extensions.Logging.Mock" Version="1.1.0" />
paket add Extensions.Logging.Mock --version 1.1.0
#r "nuget: Extensions.Logging.Mock, 1.1.0"
// Install Extensions.Logging.Mock as a Cake Addin #addin nuget:?package=Extensions.Logging.Mock&version=1.1.0 // Install Extensions.Logging.Mock as a Cake Tool #tool nuget:?package=Extensions.Logging.Mock&version=1.1.0
Extensions.Logging.Mock
A unit-testing extension for verifying a logger mock.
Configuration
To configure the intrastructure you just have to call AddMock()
on the ILoggingBuilder
instance. when using AddLogging()
. This will add a custom ILoggerProvider
which will
return the underlying instance of the configured Mock<ILogger>
instance.
[TestFixture]
public class LoggerTests
{
public Mock<ILogger> MockLogger { get; set; }
public ILogger Logger { get; set; }
public ILogger<TestClass> GenericLogger { get; set; }
[SetUp]
public void SetUp()
{
this.MockLogger = new Mock<ILogger>();
IServiceCollection services = new ServiceCollection();
services.AddLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
builder.AddConsole();
builder.AddMock(this.MockLogger);
});
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
this.Logger = loggerFactory.CreateLogger("TestLogger");
this.GenericLogger = loggerFactory.CreateLogger<TestClass>();
}
}
Usage
To verify that the desired log methods was called just verify the mock instance using
VerifyLog().DebugWasCalled()
.
[Test]
public void ShouldVerifyDebugCalled()
{
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled();
}
To verify that the desired log methods message output equals a desired values just verify
the mock instance using VerifyLog().DebugWasCalled().MessageEquals("Log Message")
.
[Test]
public void ShouldVerifyDebugMessage()
{
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled().MessageEquals("Log Message");
}
To verify that the desired log method was called a certain amount of times just verify the mock instance
using VerifyLog().DebugWasCalled().Times(2)
.
[Test]
public void ShouldVerifyDebugCalledTimes()
{
this.Logger.LogDebug("Log Message");
this.Logger.LogDebug("Log Message");
this.MockLogger.VerifyLog().DebugWasCalled().Times(2);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- JetBrains.Annotations (>= 2021.3.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
- Microsoft.Extensions.Logging.Console (>= 6.0.0)
- Moq (>= 4.17.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.2 | 229 | 11/16/2024 |
9.0.1 | 110 | 11/14/2024 |
9.0.0 | 116 | 11/14/2024 |
1.2.4 | 349 | 11/1/2024 |
1.2.3 | 2,403 | 7/9/2024 |
1.2.2 | 1,329 | 3/19/2024 |
1.2.1 | 1,578 | 11/16/2023 |
1.2.0 | 19,141 | 1/18/2023 |
1.1.3 | 926 | 11/19/2022 |
1.1.2 | 804 | 10/12/2022 |
1.1.1 | 2,122 | 6/3/2022 |
1.1.0 | 885 | 5/7/2022 |
1.0.4 | 715 | 4/14/2022 |
1.0.3 | 442 | 4/12/2022 |
1.0.2 | 503 | 12/16/2021 |