public void UpdatesExistingBooking() { Vote Vote = new Vote { VoteId = 1, EndDate = new DateTime(2017, 10, 10), YesNoQuestion = "Questions?", Deleted = false, Yes = 1, No = 2 }; //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(un => un.VoteRepository.GetByID(It.IsAny <int>())) .Returns(Vote); //Además, seteamos las expectativas para los métodos que deben llamarse luego mockUnitOfWork.Setup(un => un.VoteRepository.Update(It.IsAny <Vote>())); mockUnitOfWork.Setup(un => un.Save()); VoteValidator VoteValidator = new VoteValidator(mockUnitOfWork.Object); //act VoteValidator.PutVote(1, Vote); //Assert mockUnitOfWork.Verify(un => un.VoteRepository.Update(It.IsAny <Vote>()), Times.Exactly(1)); mockUnitOfWork.Verify(un => un.Save(), Times.Exactly(1)); }
public void DoesntUpdateNonExistingVote() { //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(un => un.VoteRepository.GetByID(It.IsAny <int>())).Returns(() => null); mockUnitOfWork.Setup(un => un.VoteRepository.Update(It.IsAny <Vote>())); //mockUnitOfWork.Setup(un => un.Save()); IVoteValidator VoteValidator = new VoteValidator(mockUnitOfWork.Object); //act VoteValidator.PutVote(0, new Vote() { }); //Assert //Retorna exception }