public void DeleteSaborServiceTest() { //Arrange Sabor sabor = null; //Fake do repositório var repositoryFake = new Mock<ISaborRepository>(); repositoryFake.Setup(r => r.Delete(1)).Returns(sabor); ISaborService service = new SaborService(repositoryFake.Object); //Action var saborFake = service.Delete(1); //Asserts repositoryFake.Verify(r => r.Delete(1)); Assert.IsNull(saborFake); }
public void RetrieveSaborServiceTest() { //Arrange Sabor sabor = ObjectMother.GetSabor(); //Fake do repositório var repositoryFake = new Mock<ISaborRepository>(); repositoryFake.Setup(r => r.Get(1)).Returns(sabor); ISaborService service = new SaborService(repositoryFake.Object); //Action var saborFake = service.Retrieve(1); //Assert repositoryFake.Verify(r => r.Get(1)); Assert.IsNotNull(saborFake); }
public void CreateSaborServiceValidationAndPersistenceTest() { //Arrange Sabor sabor = ObjectMother.GetSabor(); //Fake do repositório var repositoryFake = new Mock<ISaborRepository>(); repositoryFake.Setup(r => r.Save(sabor)).Returns(sabor); //Fake do dominio var saborFake = new Mock<Sabor>(); saborFake.As<IObjectValidation>().Setup(b => b.Validate()); ISaborService service = new SaborService(repositoryFake.Object); //Action service.Create(saborFake.Object); //Assert saborFake.As<IObjectValidation>().Verify(b => b.Validate()); repositoryFake.Verify(r => r.Save(saborFake.Object)); }