public void Update_ParamsValid_UpdateRecod() { //Arrange Template template = new Template() { Id = new Guid("05D5FD46-263E-E211-BFBA-1040F3A7A3B1"), Name = "Original", Description = "Original", AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, IsActive = true }; Template templateActualizado = new Template() { Id = new Guid("05D5FD46-263E-E211-BFBA-1040F3A7A3B1"), Name = "Actualizado", Description = "Actualizado", AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, IsActive = true }; //Moq Mock <IUpdaterRepository <Template> > updaterRepository = new Mock <IUpdaterRepository <Template> >(); Mock <IValidatorService <Template> > validatorService = new Mock <IValidatorService <Template> >(); Mock <IGetterDateRepository> getterDateRepository = new Mock <IGetterDateRepository>(); Mock <IFinderService <Template> > finderService = new Mock <IFinderService <Template> >(); getterDateRepository.Setup((repository) => repository.GetDateTime()).Returns(DateTime.UtcNow); validatorService.Setup((srvValidator) => srvValidator.Validate(template)); updaterRepository.Setup((repository) => repository.Update(template)); //SUT var SUT = new ClassUpdaterService(updaterRepository.Object, finderService.Object, validatorService.Object, getterDateRepository.Object); SUT.Update(template.Id, templateActualizado); updaterRepository.Verify((v) => v.Update(templateActualizado), Times.Once); //Assert Assert.True(template != templateActualizado); }
public void Update_InvokeRepository_SuccessInvoke() { //Arrange Template template = new Template() { Id = new Guid("05D5FD46-263E-E211-BFBA-1040F3A7A3B1"), Name = "Original", Description = "Original", AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, IsActive = true }; Template templateActualizado = new Template() { Id = new Guid("05D5FD46-263E-E211-BFBA-1040F3A7A3B1"), Name = "Actualizado", Description = "Actualizado", AddedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, IsActive = true }; //Moq Mock <IUpdaterRepository <Template> > updaterRepository = new Mock <IUpdaterRepository <Template> >(); Mock <IValidatorService <Template> > validatorService = new Mock <IValidatorService <Template> >(); Mock <IGetterDateRepository> getterDateRepository = new Mock <IGetterDateRepository>(); Mock <IFinderService <Template> > finderService = new Mock <IFinderService <Template> >(); //SUT var SUT = new ClassUpdaterService(updaterRepository.Object, finderService.Object, validatorService.Object, getterDateRepository.Object); SUT.Update(template.Id, templateActualizado); //Assert updaterRepository.Verify((v) => v.Update(templateActualizado), Times.Once); }