Beispiel #1
0
        public void Create_RegistroCreadoExitosamente_RetornaTrue()
        {
            //Arrange
            Template objtemplate = new Template();

            objtemplate.Name        = "Prueba";
            objtemplate.Description = "Prueba";

            //Mock
            Mock <ICreatorRepository <Template> > creatorRepository    = new Mock <ICreatorRepository <Template> >();
            Mock <IValidatorService <Template> >  validatorService     = new Mock <IValidatorService <Template> >();
            Mock <IGetterDateRepository>          getterDateRepository = new Mock <IGetterDateRepository>();

            getterDateRepository.Setup(x => x.GetDateTime()).Returns(DateTime.UtcNow);

            creatorRepository.Setup(x => x.Create(It.IsAny <Template>()));

            //SUT
            var SUT = new ClassCreatorService(creatorRepository.Object, validatorService.Object, getterDateRepository.Object);

            SUT.Create(objtemplate);

            // Assert
            creatorRepository.Verify(x => x.Create(objtemplate), Times.Once);
        }
Beispiel #2
0
        public void Create_RecordCreated_ReturnGuid()
        {
            //Arrange
            Template objtemplate = new Template();

            objtemplate.Id          = new Guid("23CD9099-DCC2-4CD5-CEB5-08D7961EA229");
            objtemplate.Name        = "Prueba";
            objtemplate.Description = "Prueba";

            //Mock
            Mock <ICreatorRepository <Template> > creatorRepository    = new Mock <ICreatorRepository <Template> >();
            Mock <IValidatorService <Template> >  validatorService     = new Mock <IValidatorService <Template> >();
            Mock <IGetterDateRepository>          getterDateRepository = new Mock <IGetterDateRepository>();

            getterDateRepository.Setup(x => x.GetDateTime()).Returns(DateTime.UtcNow);

            creatorRepository.Setup(x => x.Create(It.IsAny <Template>())).Returns(objtemplate.Id);

            //SUT
            var  SUT = new ClassCreatorService(creatorRepository.Object, validatorService.Object, getterDateRepository.Object);
            Guid id  = SUT.Create(objtemplate);

            //Assert
            Assert.IsType <Guid>(id);
        }
Beispiel #3
0
        public void Create_RegistroNoCreado_ReturnFalse()
        {
            //Mock
            Mock <ICreatorRepository <Template> > creatorRepository    = new Mock <ICreatorRepository <Template> >();
            Mock <IValidatorService <Template> >  validatorService     = new Mock <IValidatorService <Template> >();
            Mock <IGetterDateRepository>          getterDateRepository = new Mock <IGetterDateRepository>();

            validatorService.Setup(x => x.Validate(It.IsAny <Template>())).Throws(new ValidationException("El campo nombre no debe estar vacío."));
            getterDateRepository.Setup(x => x.GetDateTime()).Returns(DateTime.UtcNow);

            creatorRepository.Setup(x => x.Create(It.IsAny <Template>()));

            //SUT
            var SUT = new ClassCreatorService(creatorRepository.Object, validatorService.Object, getterDateRepository.Object);

            try
            {
                SUT.Create(It.IsAny <Template>());
            }
            catch (Exception)
            { }

            // Assert
            creatorRepository.Verify(x => x.Create(It.IsAny <Template>()), Times.Never);
        }
Beispiel #4
0
        public void CreatorService_InstancedParameters_NotException()
        {
            //Mock
            Mock <ICreatorRepository <Template> > creatorRepository    = new Mock <ICreatorRepository <Template> >();
            Mock <IValidatorService <Template> >  validatorService     = new Mock <IValidatorService <Template> >();
            Mock <IGetterDateRepository>          getterDateRepository = new Mock <IGetterDateRepository>();

            //SUT
            var SUT = new ClassCreatorService(creatorRepository.Object, validatorService.Object, getterDateRepository.Object);

            // Assert
            Assert.IsType <ClassCreatorService>(SUT);
        }
Beispiel #5
0
        public void Create_ErrorEnValidacion_GeneraExcepcion()
        {
            //Arrange
            Template objTemplate = new Template();

            //Mock
            Mock <ICreatorRepository <Template> > creatorRepository    = new Mock <ICreatorRepository <Template> >();
            Mock <IValidatorService <Template> >  validatorService     = new Mock <IValidatorService <Template> >();
            Mock <IGetterDateRepository>          getterDateRepository = new Mock <IGetterDateRepository>();

            validatorService.Setup(x => x.Validate(objTemplate)).Throws(new ValidationException("El campo nombre no debe estar vacío."));
            getterDateRepository.Setup(x => x.GetDateTime()).Returns(DateTime.UtcNow);

            //SUT
            var SUT = new ClassCreatorService(creatorRepository.Object, validatorService.Object, getterDateRepository.Object);

            // Assert
            Assert.Throws <ValidationException>(() => SUT.Create(objTemplate));
        }