WestDiscGolf.MoqExtensions
1.0.0-ci-10
See the version list below for details.
dotnet add package WestDiscGolf.MoqExtensions --version 1.0.0-ci-10
NuGet\Install-Package WestDiscGolf.MoqExtensions -Version 1.0.0-ci-10
<PackageReference Include="WestDiscGolf.MoqExtensions" Version="1.0.0-ci-10" />
paket add WestDiscGolf.MoqExtensions --version 1.0.0-ci-10
#r "nuget: WestDiscGolf.MoqExtensions, 1.0.0-ci-10"
// Install WestDiscGolf.MoqExtensions as a Cake Addin #addin nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.0-ci-10&prerelease // Install WestDiscGolf.MoqExtensions as a Cake Tool #tool nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.0-ci-10&prerelease
MoqExtensions
Extension method for using Moq with Microsoft.Extensions.Logging
Forked from https://github.com/WestDiscGolf/Random/tree/master/LoggerUnitTests
Original Blog Post | Tracking 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
develop
branch. - Merged PRs to
develop
will trigger a[version]-ci-[buildnumber]
deployment to nuget, assuming all unit tests pass. - Merged PRs to
main
will trigger a [version] deployment to nuget, assuming all of the tests pass. - Merges to all other pranches will trigger a
CI
action 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
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. |
-
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 | 286 | 5/18/2023 |
1.0.2-ci-13 | 119 | 5/18/2023 |
1.0.1 | 142 | 5/15/2023 |
1.0.1-ci-12 | 129 | 5/15/2023 |
1.0.1-ci-11 | 126 | 5/15/2023 |
1.0.0 | 140 | 5/14/2023 |
1.0.0-ci-9 | 127 | 5/14/2023 |
1.0.0-ci-8 | 126 | 5/14/2023 |
1.0.0-ci-10 | 125 | 5/15/2023 |