SweetMock 0.9.41
dotnet add package SweetMock --version 0.9.41
NuGet\Install-Package SweetMock -Version 0.9.41
<PackageReference Include="SweetMock" Version="0.9.41" />
<PackageVersion Include="SweetMock" Version="0.9.41" />
<PackageReference Include="SweetMock" />
paket add SweetMock --version 0.9.41
#r "nuget: SweetMock, 0.9.41"
#:package SweetMock@0.9.41
#addin nuget:?package=SweetMock&version=0.9.41
#tool nuget:?package=SweetMock&version=0.9.41
Sweet Mock
A source generator for creating mocks and fixtures for testing. SweetMock automatically generates fixture and mock implementations of interfaces or classes to help in unit testing by providing a way to simulate the behavior of complex dependencies.
[Fixture<ShoppingBasket>]
[Fact]
public async Task TheGuideShouldAlwaysBeAvailable()
{
// Arrange
var userGuid = Guid.NewGuid();
var fixture = Fixture.ShoppingBasket(config =>
{
config.user.Id(userGuid);
var basket1 = Mock.IBasket(c => c.Add());
config.basketRepo
.TryGetUserBasket(Task.FromResult(true), basket1)
.Save();
config.bookRepo
.IsAvailable(true)
.InStock(42)
.GetByISBN(new Book("isbn 0-434-00348-4", "The Hitch Hiker's Guide to the Galaxy", "Douglas Adams"));
config.messageBroker.SendMessage();
});
var sut = fixture.CreateShoppingBasket();
// Act
await sut.AddBookToBasket("isbn 0-434-00348-4", CancellationToken.None);
// Assert
var sendMessage = Assert.Single(fixture.Calls.messageBroker.SendMessage(arguments => arguments.userId == userGuid));
Assert.Equal("The book The Hitch Hiker's Guide to the Galaxy by Douglas Adams was added to your basket", sendMessage.message);
}
For more details see the documentation
Installation
Install the package via NuGet:
dotnet add package SweetMock
Features
SweetMock offers a comprehensive set of features designed to streamline unit testing in C# projects. Its source generator code simplifies security scanning and ensures that mock implementations are both fast, reliable and maintainable.
The fixture system enables bulk creation of mock dependencies, making it easy to set up complex test scenarios while direct access to creating individual mock object allows for more advanced scenarios.
SweetMock supports both interface and class mocking, providing flexibility for a wide range of dependency types. Built-in mocks cover common scenarios, reducing the need for custom implementations.
Extensive logging features allow for detailed assertions, helping you verify interactions and outcomes with precision.
Additionally, SweetMock is test framework agnostic, working seamlessly with XUnit, NUnit, TUnit, and other popular frameworks.
Requirements
- C# 12.0 (.net 8 and above)
License
This project is licensed under MIT License
Project Links
| 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. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- SweetMock.BaseFiles (>= 0.9.41)
- SweetMock.SourceGenerator (>= 0.9.41)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on SweetMock:
| Package | Downloads |
|---|---|
|
SweetMock.Extensions.TimeProvider
A lightweight extension library for SweetMock for mocking TimeProvider in .NET tests. Control time precisely in your tests without complex setup. |
|
|
SweetMock.Extensions.Http
A comprehensive extension library for mocking HttpClient and IHttpClientFactory in .NET tests using the SweetMock framework. |
|
|
SweetMock.Extensions.Logging
A powerful extension library for mocking ILogger in .NET tests using the SweetMock framework. Capture, filter, and verify log messages with ease. |
|
|
SweetMock.Extensions.Options
A comprehensive extension library for mocking IOptions, IOptionsSnapshot, and IOptionsMonitor in .NET tests using the SweetMock framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.