Пример #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);
        }
Пример #2
0
        public async Task ShouldReturnParsedStringWithParams()
        {
            // Arrange
            string template = "Tedsf {test1}, sdfaf{test2}";
            string test1    = Fixture.Create <string>();
            string test2    = Fixture.Create <string>();

            string expected = $"Tedsf {test1}, sdfaf{test2}";

            Dictionary <string, string> dict = new Dictionary <string, string> {
                { "test1", test1 },
                { "test2", test2 }
            };

            // Act
            var actual = MailerParser.ProcessTemplate(template, dict);

            //Assert
            Assert.Equal(expected, actual);
        }
Пример #3
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");
        }