Ejemplo n.º 1
0
        public void CredentialsDtoValidatorEmptyServiceIdPromocodeNotValid()
        {
            //Arrange
            var activateBonusDto = new ActivateBonusDto {
            };

            //Act
            var validationResult = new ActivateBonusDtoValidator().Validate(activateBonusDto);

            //Assert
            Assert.Equal(2, validationResult.Errors.Count);
            Assert.True(validationResult.Errors.Count(x => x.PropertyName == "ServiceId") == 1);
            Assert.True(validationResult.Errors.Count(x => x.PropertyName == "Promocode") == 1);
        }
Ejemplo n.º 2
0
        public void ActivateBonusDtoValidatorValid()
        {
            //Arrange
            var activateBonusDto = new ActivateBonusDto
            {
                ServiceId = Guid.NewGuid(),
                Promocode = "itpromocode"
            };

            //Act
            var validationResult = new ActivateBonusDtoValidator().Validate(activateBonusDto);

            //Assert
            Assert.Empty(validationResult.Errors);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ActivateBonusAsync(ActivateBonusDto activateBonusDto)
        {
            var validationResult = new ActivateBonusDtoValidator().Validate(activateBonusDto);

            if (!validationResult.IsValid)
            {
                return(UnprocessableEntity(new ExceptionMessage(validationResult.Errors.Select(x => x.ErrorMessage))));
            }

            var userId = Guid.Parse(User.Identity.Name);
            var canBeProcessedResult = await _servicesService.BonusCanBeActivatedAsync(userId, activateBonusDto);

            if (!canBeProcessedResult.CanBeProcessed)
            {
                return(StatusCode(canBeProcessedResult.StatusCode, new ExceptionMessage(canBeProcessedResult.RejectionReason)));
            }

            await _servicesService.ActivateBonusAsync(userId, activateBonusDto);

            return(NoContent());
        }