public void CanAddCake() { var repo = Substitute.For <ICakeRepository>(); repo.Add(new Cake()).ReturnsForAnyArgs(true); repo.Update(new Cake()).ReturnsForAnyArgs(false); var controller = new CakeController(repo); var id = Guid.NewGuid(); Assert.IsTrue(controller.Put(id, new Cake { Id = id, Name = "Test cake", Added = DateTime.UtcNow })); repo.Received().Add(Arg.Any <Cake>()); }
public void CanUpdateCake() { var repo = Substitute.For <ICakeRepository>(); repo.Update(new Cake()).ReturnsForAnyArgs(true); var controller = new CakeController(repo); var id = Guid.NewGuid(); repo.GetById(id).Returns(new Cake { Id = id, Name = "Test cake", Added = DateTime.UtcNow }); controller.Put(id, new Cake { Id = id, Name = "Test cake update", Added = DateTime.UtcNow }); repo.Received().Update(Arg.Any <Cake>()); }