WestDiscGolf.MoqExtensions
1.0.1-ci-11
See the version list below for details.
dotnet add package WestDiscGolf.MoqExtensions --version 1.0.1-ci-11
NuGet\Install-Package WestDiscGolf.MoqExtensions -Version 1.0.1-ci-11
<PackageReference Include="WestDiscGolf.MoqExtensions" Version="1.0.1-ci-11" />
paket add WestDiscGolf.MoqExtensions --version 1.0.1-ci-11
#r "nuget: WestDiscGolf.MoqExtensions, 1.0.1-ci-11"
// Install WestDiscGolf.MoqExtensions as a Cake Addin #addin nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.1-ci-11&prerelease // Install WestDiscGolf.MoqExtensions as a Cake Tool #tool nuget:?package=WestDiscGolf.MoqExtensions&version=1.0.1-ci-11&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 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. |
-
net6.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 | 284 | 5/18/2023 |
1.0.2-ci-13 | 117 | 5/18/2023 |
1.0.1 | 140 | 5/15/2023 |
1.0.1-ci-12 | 127 | 5/15/2023 |
1.0.1-ci-11 | 124 | 5/15/2023 |
1.0.0 | 138 | 5/14/2023 |
1.0.0-ci-9 | 123 | 5/14/2023 |
1.0.0-ci-8 | 124 | 5/14/2023 |
1.0.0-ci-10 | 121 | 5/15/2023 |