Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }