public void UpdaterState_ParamsValid_UpdateRecod() { //Arrange Template template = new Template(); template.Id = new Guid("00000000-0000-0000-0000-000000000000"); template.Name = "prueba"; template.Description = "prueba"; template.AddedDate = DateTime.UtcNow; template.ModifiedDate = DateTime.UtcNow; template.IsActive = false; //Moq Mock <IUpdaterRepository <Template> > updaterRepository = new Mock <IUpdaterRepository <Template> >(); Mock <IFinderService <Template> > finderService = new Mock <IFinderService <Template> >(); Mock <IValidatorService <Template> > validatorService = new Mock <IValidatorService <Template> >(); Mock <IGetterDateRepository> getterDateRepository = new Mock <IGetterDateRepository>(); updaterRepository.Setup((repository) => repository.Update(template)); finderService.Setup((srvfinder) => srvfinder.Get(template.Id)).Returns(template); validatorService.Setup((srvValidator) => srvValidator.Validate(template)); getterDateRepository.Setup((repository) => repository.GetDateTime()).Returns(DateTime.UtcNow); //SUT var SUT = new ClassUpdaterService(updaterRepository.Object, finderService.Object, validatorService.Object, getterDateRepository.Object); SUT.UpdateState(template.Id, true); //Assert updaterRepository.Verify((v) => v.Update(template), Times.Once); }
public void UpdaterService_ReceiveDependencyValid_InstantiateDependencies() { // Mock Mock <IUpdaterRepository <Template> > updaterRepository = new Mock <IUpdaterRepository <Template> >(); Mock <IFinderService <Template> > finderService = new Mock <IFinderService <Template> >(); Mock <IValidatorService <Template> > validadorService = new Mock <IValidatorService <Template> >(); Mock <IGetterDateRepository> getDate = new Mock <IGetterDateRepository>(); //SUT var SUT = new ClassUpdaterService(updaterRepository.Object, finderService.Object, validadorService.Object, getDate.Object); //Assert Assert.NotNull(SUT); }
public void UpdaterState_ParamsNull_Exception() { //Arrange Template template = new Template(); //Moq Mock <IUpdaterRepository <Template> > updaterRepository = new Mock <IUpdaterRepository <Template> >(); Mock <IFinderService <Template> > finderService = new Mock <IFinderService <Template> >(); Mock <IValidatorService <Template> > validatorService = new Mock <IValidatorService <Template> >(); Mock <IGetterDateRepository> getterDateRepository = new Mock <IGetterDateRepository>(); finderService.Setup((srvfinder) => srvfinder.Get(template.Id)).Throws(new GettingException("Records no found.")); //SUT var SUT = new ClassUpdaterService(updaterRepository.Object, finderService.Object, validatorService.Object, getterDateRepository.Object); //Assert Assert.Throws <GettingException>(() => SUT.UpdateState(template.Id, true)); }
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); }