Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created July 27, 2011 06:12
Show Gist options
  • Save timwingfield/1108778 to your computer and use it in GitHub Desktop.
Save timwingfield/1108778 to your computer and use it in GitHub Desktop.
Setting up a Mock with Moq
[TestFixture]
public class When_saving_a_vehicle_in_the_view_model_with_a_vehicle : Specification
{
private VehicleViewModel _viewModel;
private Mock<IVehicleRepository> _repository;
protected override void before_each()
{
_repository = new Mock<IVehicleRepository>();
_viewModel = new VehicleViewModel(_repository.Object);
_viewModel.Name = "New Vehicle";
}
protected override void because()
{
_viewModel.Save();
}
[Test]
public void then_save_on_the_repository_should_be_called()
{
_repository.Verify(x => x.Save(It.IsAny<Vehicle>()), Times.Exactly(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment