![]() |
VOOZH | about |
dotnet add package Stashbox.FakeItEasy --version 4.8.0
NuGet\Install-Package Stashbox.FakeItEasy -Version 4.8.0
<PackageReference Include="Stashbox.FakeItEasy" Version="4.8.0" />
<PackageVersion Include="Stashbox.FakeItEasy" Version="4.8.0" />Directory.Packages.props
<PackageReference Include="Stashbox.FakeItEasy" />Project file
paket add Stashbox.FakeItEasy --version 4.8.0
#r "nuget: Stashbox.FakeItEasy, 4.8.0"
#:package Stashbox.FakeItEasy@4.8.0
#addin nuget:?package=Stashbox.FakeItEasy&version=4.8.0Install as a Cake Addin
#tool nuget:?package=Stashbox.FakeItEasy&version=4.8.0Install as a Cake Tool
👁 Appveyor build status
👁 GitHub Workflow Status
👁 Sourcelink
Mocking framework integrations for Stashbox that provide automatic mock creation for your services in unit tests.
| Moq | FakeItEasy | NSubstitute | RhinoMocks |
|---|---|---|---|
| 👁 NuGet Version |
👁 NuGet Version |
👁 NuGet Version |
👁 NuGet Version |
You can use the auto mock framework by creating a StashMoq instance wrapped in a using statement, on its disposal it will call Verify() on all the configured expectations.
//begin a test scope
using (var stash = StashMoq.Create())
{
//configure a mock dependency
stash.Mock<IDependency>().Setup(m => m.Test()).Returns("test");
//configure the mock again
//this call will get the same mock back as the first request
stash.Mock<IDependency>().Setup(m => m.Test2());
//get the tested service filled with auto created mocks (except the configured ones)
var service = stash.Get<IService>();
//call the tested method, imagine that this will invoke the Test() method of an IDependency
var result = service.Test();
//check the result
Assert.Equal("test", result);
} //StashMoq will call the Verify() method on all configured expectations on its dispose
You can also set the
verifyAllparameter ofStashMoqwith that it will call theVerifyAll()on the used mock repository.StashMoq.Create(verifyAll: true)
You can set which mock behavior should be used by the framework by default.
using (var stash = StashMoq.Create(MockBehavior.Strict)) //the default will be strict
{
//this mock will be strict
stash.Mock<IDependency>().Setup(m => m.Test()).Returns("test");
//you can also override the default config, this mock will be loose
stash.Mock<IDependency2>(MockBehavior.Loose).Setup(...);
}
You can use the auto mock framework by creating a StashItEasy instance wrapped in a using statement.
//begin a test scope
using (var stash = StashItEasy.Create())
{
//configure a mock dependency
var fake = stash.Fake<IDependency>();
//configure the call
A.CallTo(() => fake.Test()).Returns("test");
//get the tested service filled with auto created fakes (except the configured ones)
var service = stash.Get<IService>();
//call the tested method, imagine that this will invoke the Test() method of the IDependency
var result = service.Test();
//check the call
A.CallTo(() => fake.Test()).MustHaveHappened();
//check the result
Assert.Equal("test", result);
}
You can set what fake options should be used by the framework by default.
using (var stash = StashItEasy.Create(x => x.Strict())) //the default will be strict
{
//this fake will be strict
stash.Fake<IDependency>();
//you can also override the default config
stash.Fake<IDependency>(x => x.Implements<IDependency3>());
}
You can use the auto mock framework by creating a StashSubstitute instance wrapped in a using statement.
//begin a test scope
using (var stash = StashSubstitute.Create())
{
//configure a mock dependency
var sub = stash.Sub<IDependency>(); //for multiple interface implementations use the overloads of this method
sub.Test().Returns("test");
//get the tested service filled with auto created mocks (except the configured ones)
var service = stash.Get<IService>();
//call the tested method, imagine that this will invoke the Test() method of an IDependency
var result = service.Test();
//check the call
sub.Recieved().Test();
//check the result
Assert.Equal("test", result);
}
You can also get a partial mock with the
stash.Partial<IDependency>()call.
You can use the auto mock framework by creating a StashRhino instance wrapped in a using statement, on its disposal it will call VerifyAllExpectations() on all the configured expectations.
//begin a test scope
using (var stash = StashRhino.Create())
{
//configure a mock dependency
stash.Mock<IDependency>().Expect(x => x.Test()).Returns("test");
//configure the mock again
//this call will get the same mock back as the first request
stash.Mock<IDependency>().Expect(m => m.Test2());
//get the tested service filled with auto created mocks (except the configured ones)
var service = stash.Get<IService>();
//call the tested method, imagine that this will invoke the Test() method of an IDependency
var result = service.Test();
//check the result
Assert.Equal("test", result);
} //StashRhino will call the VerifyAllExpectations() method on all configured expectations on its dispose
You can also request different mock types from StashRhino:
using (var stash = StashRhino.Create())
{
//this will create a dynamic mock
stash.Mock<IDependency>();
//this will create a strict mock
stash.Strict<IDependency>();
//this will create a partial mock
stash.Partial<IDependency>();
}
var service = stash.GetWithConstructorArgs<Service>(mockObject1, mockObject2);
//you can also use a placeholder argument where you don't want to set a concrete object
var service = stash.GetWithConstructorArgs<Service>(StashArg.Any<IMock>(), mockObject2);
If you use an argument placeholder with a non-mockable type, the framework will throw a
NonMockableTypeException.
//this will inject the `mockObject1` into the created `Service` everywhere it fits by its type
var service = stash.GetWithParamOverrides<Service>(mockObject1);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net45 net45 is compatible. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.8.0 | 2,384 | 10/1/2024 |
| 4.7.1 | 1,522 | 4/8/2024 |
| 4.7.0 | 1,084 | 6/21/2023 |
| 4.6.0 | 337 | 6/5/2023 |
| 4.5.2 | 1,048 | 3/29/2023 |
| 4.5.1 | 377 | 3/29/2023 |
| 4.5.0 | 416 | 2/28/2023 |
| 4.4.1 | 512 | 1/20/2023 |
| 4.4.0 | 480 | 12/6/2022 |
| 4.3.2 | 493 | 11/29/2022 |
| 4.3.1 | 684 | 10/14/2022 |
| 4.3.0 | 589 | 10/12/2022 |
| 4.2.3 | 604 | 9/9/2022 |
| 4.2.2 | 684 | 6/2/2022 |
| 4.2.1 | 1,102 | 5/17/2022 |
| 4.2.0 | 627 | 5/3/2022 |
| 4.1.2 | 1,169 | 3/12/2022 |
| 4.1.1 | 660 | 3/12/2022 |
| 4.1.0 | 664 | 3/7/2022 |
| 4.0.1 | 843 | 2/10/2022 |