WestDiscGolf.MoqExtensions
1.0.2
dotnet add package WestDiscGolf.MoqExtensions --version 1.0.2
NuGet\Install-Package WestDiscGolf.MoqExtensions -Version 1.0.2
<PackageReference Include="WestDiscGolf.MoqExtensions" Version="1.0.2" />
<PackageVersion Include="WestDiscGolf.MoqExtensions" Version="1.0.2" />
<PackageReference Include="WestDiscGolf.MoqExtensions" />
paket add WestDiscGolf.MoqExtensions --version 1.0.2
#r "nuget: WestDiscGolf.MoqExtensions, 1.0.2"
#:package WestDiscGolf.MoqExtensions@1.0.2
#addin nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.2
#tool nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.2
MoqExtensions
Extension method for using Moq with Microsoft.Extensions.Logging
Forked from https://github.com/WestDiscGolf/Random/tree/master/LoggerUnitTests
Original Blog Post | Package request
Installing KeyValueRepo
You should install MoqExtensions with NuGet:
Install-Package WestDiscGolf.MoqExtensions
Or via the .NET Core command line interface:
dotnet add package WestDiscGolf.MoqExtensions
Either command, from Package Manager Console or .NET Core CLI, will download and install all required dependencies.
Contributing
- PRs should be against the
developbranch. - Merged PRs to
developwill trigger a[version]-ci-[buildnumber]deployment to nuget, assuming all unit tests pass. - Merged PRs to
mainwill trigger a [version] deployment to nuget, assuming all of the tests pass. - Merges to all other pranches will trigger a
CIaction to run all unit tests
Versioning
The package version is defined in the MoqExtensions.csproj file, using .NET SDK style structure. We follow semantic versioning for this package.
Usage
Use these extensions when working with Moq and Microsoft.Extensions.Logging.ILogger<> since Microsoft's implementation of the ILogger mostly relies on extension methods, and not on methods defined in the actual ILogger interface. This extension method takes a "mock around" approach - to get around the ILogger extension methods and to assert against what they are doing beneath the abstractions.
Examples
More examples in LoggerTest.cs
[Fact]
public void VerifyWasCalledWithReusableExtension()
{
// Arrange
var loggerMock = new Mock<ILogger<PleaseTestMe>>();
var sut = new PleaseTestMe(loggerMock.Object);
// Act
sut.RunMe();
// Assert
loggerMock.VerifyDebugWasCalled();
}
[Fact]
public void VerifyWasCalledWithReusableExtensionWithMessage()
{
// Arrange
var loggerMock = new Mock<ILogger<PleaseTestMe>>();
var sut = new PleaseTestMe(loggerMock.Object);
// Act
sut.RunMe();
// Assert
loggerMock.VerifyDebugWasCalled("Logging this ...");
}
[Fact]
public void VerifyLoopTest_2()
{
// Arrange
var loggerMock = new Mock<ILogger<PleaseTestMe>>();
var sut = new PleaseTestMe(loggerMock.Object);
// Act
sut.RunMeLoop();
// Assert
loggerMock.VerifyLogging("Logging Multiple Times ...", LogLevel.Debug, Times.Exactly(3));
}
More examples in LoggerTest.cs
Change Log
- 1.0.2 - readme and links updated to correct blog page
- 1.0.1 - added .NET 7
- 1.0.0 - ininitial release
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.1)
- Moq (>= 4.13.1)
-
net7.0
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.1)
- Moq (>= 4.13.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on WestDiscGolf.MoqExtensions:
| Package | Downloads |
|---|---|
|
Calebs.KeyValueRepoTests
a set of tests that all IKeyValueRepo implementations should pass. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.2 | 476 | 5/18/2023 |
| 1.0.2-ci-13 | 257 | 5/18/2023 |
| 1.0.1 | 276 | 5/15/2023 |
| 1.0.1-ci-12 | 265 | 5/15/2023 |
| 1.0.1-ci-11 | 258 | 5/15/2023 |
| 1.0.0 | 276 | 5/14/2023 |
| 1.0.0-ci-9 | 265 | 5/14/2023 |
| 1.0.0-ci-8 | 258 | 5/14/2023 |
| 1.0.0-ci-10 | 256 | 5/15/2023 |