Example #1
0
        public async Task ShouldReturnDictionaryWithParams()
        {
            // Arrange
            string   UDID          = Fixture.Create <string>();
            string   Address       = Fixture.Create <string>();
            string   Town          = Fixture.Create <string>();
            string   PostCode      = Fixture.Create <string>();
            string   Country       = Fixture.Create <string>();
            string   Notes         = Fixture.Create <string>();
            DateTime LastHeartBeat = Fixture.Create <DateTime>();
            string   Cause         = Fixture.Create <string>();
            string   MailTo        = Fixture.Create <string>();

            EmailParameters emailParams = Fixture.Build <EmailParameters>()
                                          .With(x => x.Address, Address)
                                          .With(x => x.Cause, Cause)
                                          .With(x => x.Town, Town)
                                          .With(x => x.PostCode, PostCode)
                                          .With(x => x.Country, Country)
                                          .With(x => x.Notes, Notes)
                                          .With(x => x.MailTo, MailTo)
                                          .With(x => x.LastHeartBeat, LastHeartBeat)
                                          .With(x => x.UDID, UDID)
                                          .Without(x => x.EmailsTo)
                                          .Create();

            Dictionary <string, string> expected = new Dictionary <string, string> {
                { "address", Address },
                { "cause", Cause },
                { "town", Town },
                { "postcode", PostCode },
                { "country", Country },
                { "notes", Notes },
                { "mailto", MailTo },
                { "lastheartbeat", LastHeartBeat.ToString() },
                { "udid", UDID },
                { "emailsto", null }
            };

            // Act
            var actual = MailerParser.PrepareDictionaryParams(emailParams);

            //Assert
            Assert.Equal(expected, actual);
        }
Example #2
0
        public async Task <MailSendingModel> PrepareEmail(EmailParameters emailParams)
        {
            MailSendingModel email = new MailSendingModel();

            emailParams.MailTo = _toMail;

            Dictionary <string, string> parameters = MailerParser.PrepareDictionaryParams(emailParams);

            var emailtemplate = (await _messagetTemplateRepository.GetAsync(Filtering(emailParams.Cause)))
                                .OrderByDescending(x => x.CreateOn)
                                .FirstOrDefault();

            if (emailtemplate != null)
            {
                email.Subject = MailerParser.ProcessTemplate(emailtemplate.Subject, parameters);
                email.From    = new EmailAddress(_from);
                email.To.AddRange(_to?.Select(x => new EmailAddress(x)) ?? new List <EmailAddress>());
                //email.To.AddRange(emailParams.EmailsTo?.Select(x => new EmailAddress(x)) ?? new List<EmailAddress>());/
                email.HtmlContent = MailerParser.ProcessTemplate(emailtemplate.MessageBody, parameters);
                return(email);
            }
            throw new ArgumentNullException("Message", "Email template not found");
        }