public async Task <BurnRuleResponse> UpdateAsync([FromBody] BurnRuleEditRequest request)
        {
            try
            {
                var burnRuleToUpdate = _mapper.Map <BurnRuleModel>(request);

                await _burnRuleService.UpdateAsync(burnRuleToUpdate);

                return(new BurnRuleResponse()
                {
                    ErrorCode = CampaignServiceErrorCodes.None,
                    Id = burnRuleToUpdate.Id
                });
            }
            catch (EntityNotValidException e)
            {
                _log.Info(string.Format(Phrases.EntityNotValid, "Burn rule", request.Id), context: request.Id);

                return(new BurnRuleResponse()
                {
                    ErrorCode = CampaignServiceErrorCodes.EntityNotValid,
                    ErrorMessage = e.Message
                });
            }
            catch (EntityNotFoundException e)
            {
                _log.Info(string.Format(Phrases.EntityWithIdNotFound, "Burn rule", request.Id), context: request.Id);

                return(new BurnRuleResponse()
                {
                    ErrorCode = CampaignServiceErrorCodes.EntityNotFound,
                    ErrorMessage = e.Message
                });
            }
        }
        public void When_BurnRuleHaveTwoTitleContentInEnglish_Expect_AnErrorForUniqueContentThrown()
        {
            var burnRule = new BurnRuleEditRequest()
            {
                Title            = "title",
                Description      = "description",
                BurnRuleContents = new List <BurnRuleContentEditRequest>()
                {
                    new BurnRuleContentEditRequest()
                    {
                        RuleContentType = RuleContentType.Title,
                        Localization    = Localization.En,
                        Value           = "value"
                    },
                    new BurnRuleContentEditRequest()
                    {
                        RuleContentType = RuleContentType.Title,
                        Localization    = Localization.En,
                        Value           = "value1"
                    }
                }
            };

            var result =
                _burnRuleEditRequestValidator.ShouldHaveValidationErrorFor(c => c.BurnRuleContents, burnRule);

            result.WithErrorMessage(Phrases.RuleContentDescriptionNotNull);
        }
        public void When_BurnRuleIdNotPassed_Expect_AnErrorIsThrown()
        {
            var burnRule = new BurnRuleEditRequest()
            {
                Title       = "ti",
                Description = "description"
            };

            _burnRuleEditRequestValidator.ShouldHaveValidationErrorFor(c => c.Id, burnRule);
        }
        public void When_BurnRuleDoesNotHaveContents_Expect_AnErrorForMissingContentThrown()
        {
            var burnRule = new BurnRuleEditRequest()
            {
                Title       = "title",
                Description = "description"
            };

            var result =
                _burnRuleEditRequestValidator.ShouldHaveValidationErrorFor(c => c.BurnRuleContents, burnRule);

            result.WithErrorMessage(Phrases.RuleContentTypeNotNull);
        }
        public void When_BurnRuleTitleUnderTwoSymbols_Expect_AnErrorForLengthThrown()
        {
            var burnRule = new BurnRuleEditRequest()
            {
                Title       = "ti",
                Description = "description"
            };

            var result =
                _burnRuleEditRequestValidator.ShouldHaveValidationErrorFor(c => c.Title, burnRule);

            result.WithErrorMessage("The length of 'Title' must be at least 3 characters. You entered 2 characters.");
        }
        public void When_BurnRuleTitleNotPassed_Expect_AnErrorForMissingTitleThrown()
        {
            var burnRule = new BurnRuleEditRequest()
            {
                Description      = "description",
                BurnRuleContents = new List <BurnRuleContentEditRequest>()
                {
                    new BurnRuleContentEditRequest()
                    {
                        RuleContentType = RuleContentType.Title,
                        Localization    = Localization.En,
                        Value           = "value"
                    }
                }
            };

            var result =
                _burnRuleEditRequestValidator.ShouldHaveValidationErrorFor(c => c.Title, burnRule);

            result.WithErrorMessage("'Title' must not be empty.");
        }