public Guid Add(AddMessageTemplate model) { var validationResult = _messageTemplateQueries.GetValidationResult(model); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } using (var scope = CustomTransactionScope.GetTransactionScope()) { var messageTemplate = Mapper.Map <MessageTemplate>(model); messageTemplate.Brand = _messagingRepository.Brands.Single(x => x.Id == model.BrandId); messageTemplate.Language = _messagingRepository.Languages.Single(x => x.Code == model.LanguageCode); messageTemplate.Created = DateTimeOffset.Now.ToBrandOffset(messageTemplate.Brand.TimezoneId); messageTemplate.CreatedBy = _actorInfoProvider.Actor.UserName; _messagingRepository.MessageTemplates.Add(messageTemplate); _messagingRepository.SaveChanges(); _eventBus.Publish(new MessageTemplateAddedEvent(Mapper.Map <Interface.Data.MessageTemplate>(messageTemplate)) { EventCreated = DateTimeOffset.Now.ToBrandOffset(messageTemplate.Brand.TimezoneId), }); scope.Complete(); return(messageTemplate.Id); } }
public AddMessageTemplate CreateAddMessageTemplateData( Guid?brandId = null, string cultureCode = null, MessageType?messageType = null, MessageDeliveryMethod?messageDeliveryMethod = null, string content = null, string subject = null) { var brand = brandId.HasValue ? _messagingRepository.Brands.Include(x => x.Languages).Single(x => x.Id == brandId.Value) : _messagingRepository.Brands.Include(x => x.Languages).First(); messageDeliveryMethod = messageDeliveryMethod ?? TestDataGenerator.GetRandomMessageDeliveryMethod(); var addMessageTemplateData = new AddMessageTemplate { BrandId = brand.Id, LanguageCode = cultureCode ?? brand.Languages.First().Code, MessageType = messageType ?? TestDataGenerator.GetRandomMessageType(), MessageDeliveryMethod = messageDeliveryMethod.Value, TemplateName = TestDataGenerator.GetRandomString(), Subject = messageDeliveryMethod == MessageDeliveryMethod.Email ? subject ?? TestDataGenerator.GetRandomString() : null }; addMessageTemplateData.MessageContent = content ?? string.Format("Test Message - {0} {1}", addMessageTemplateData.MessageType, addMessageTemplateData.MessageDeliveryMethod); return(addMessageTemplateData); }
public void Can_fail_missing_required_fields_email() { var data = new AddMessageTemplate { BrandId = Brand.Id, MessageType = TestDataGenerator.GetRandomMessageType(), MessageDeliveryMethod = MessageDeliveryMethod.Email, }; var result = MessageTemplateQueries.GetValidationResult(data); Assert.That(result.Errors.Count, Is.EqualTo(4)); Assert.That(result.Errors.All(x => x.ErrorMessage == Enum.GetName(typeof(MessagingValidationError), MessagingValidationError.Required))); Assert.That(result.Errors.SingleOrDefault(x => x.PropertyName == "LanguageCode"), Is.Not.Null); Assert.That(result.Errors.SingleOrDefault(x => x.PropertyName == "TemplateName"), Is.Not.Null); Assert.That(result.Errors.SingleOrDefault(x => x.PropertyName == "Subject"), Is.Not.Null); Assert.That(result.Errors.SingleOrDefault(x => x.PropertyName == "MessageContent"), Is.Not.Null); }
public ValidationResult GetValidationResult(AddMessageTemplate model) { return(new AddMessageTemplateValidator(_messagingRepository, this).Validate(model)); }