Repository navigation
Usage Cheatsheet
Robert Coltheart edited this page May 8, 2019
·
6 revisions
- Machine.Fakes.Moq
- Machine.Fakes.NSubstitute
- Machine.Fakes.FakeItEasy
- Machine.Fakes.RhinoMocks - no support for .NET Core
class When_using_a_car : WithSubject<Car>
{
Because of = () =>
Subject.StartCar();
}class When_using_a_car : WithSubject<Car>
{
static bool engine_off;
Establish context = () =>
The<IEngine>()
.WhenToldTo(x => x.TurnOff(Param.IsAny<MethodUsed>()))
.Return(true);
Because of = () =>
engine_off = Subject.StopCar();
It should_turn_off_engine = () =>
engine_off.ShouldBeTrue();
}Establish context = () =>
The<IEngine>()
.WhenToldTo(x => x.TurnOff(Param.IsAny<MethodUsed>()))
.Throw(new InvalidOperationException());It should_turn_off_engine_once = () =>
The<IEngine>()
.WasToldTo(x => x.TurnOff(Param.IsAny<MethodUsed>()))
.OnlyOnce();It should_turn_off_engine_once = () =>
The<IEngine>()
.WasNotToldTo(x => x.TurnOff(Param.IsAny<MethodUsed>()));public class Car
{
public Car(IEngine engine)
{
}
}
class When_using_a_car : WithSubject<Car>
{
Establish context = () =>
Configure(x => x.For<IEngine>().Use<RotaryEngine>());
}Only works on void return methods.
Establish context = () =>
The<IEngine>()
.WhenToldTo(x => x.Service(Param.IsAny<bool>(), Param.IsAny<int>()))
.Callback<bool, int>((x, y) =>
{
is_full_service = x;
tires_count = y;
});Only works on void return methods.
Establish context = () =>
{
bool changed;
The<IEngine>()
.WhenToldTo(x => x.ChangeTire(1, out changed))
.AssignOutAndRefParameters(true);
};In the above changed will be set to true.
Getting Started
Test Runners
Guidelines