Esempio n. 1
0
        public async Task TrySendEmailAsync_ShouldUseSubjectAndBody_IfNoTemplateIdProvided()
        {
            // arrange
            var args = new EmailMessageParams
            {
                ApplicationId = _fixture.ApplicationId,
                To            = new List <string> {
                    "*****@*****.**"
                },
                Data = new Dictionary <string, object> {
                    { "Name", "Someone" }
                },
                Subject     = "Hi {{Name}}",
                BodyEncoded = EmailMessageParams.EncodeBody("Hi {{Name}}")
            };

            var template = await _fixture.Database.FindTemplateAsync(_fixture.TemplateId);

            var expected = await MustacheTemplateTransformer.Instance.TransformTemplateAsync(
                new EmailTemplate(
                    args.Subject,
                    args.GetBody()),
                args.Data,
                args.GetCulture());

            // act
            var success = await _target.TrySendEmailAsync(args);

            // assert
            _transport.Verify(m => m.SendAsync(It.Is <SenderParams>(p =>
                                                                    p.Subject == expected.Subject && p.Body == expected.Body)));
        }
        private EmailMessageParams BuildMessage(PostEmailRequest args)
        {
            const string EmptyData = "{}";

            return(new EmailMessageParams
            {
                To = args.To,
                CC = args.CC,
                Bcc = args.Bcc,
                LogLevel = args.LogLevel,
                TemplateId = args.Template,
                Subject = args.Subject,
                BodyEncoded = EmailMessageParams.EncodeBody(args.Body),
                Data = JObject.Parse(args.Data ?? EmptyData).ToObject <Dictionary <string, object> >()
            });
        }
Esempio n. 3
0
        public async Task TrySendEmailAsync_ShouldUseRawSubjectAndBody_IfNoTemplateIdAndNoDataProvided()
        {
            // arrange
            var args = new EmailMessageParams
            {
                ApplicationId = _fixture.ApplicationId,
                To            = new List <string> {
                    "*****@*****.**"
                },
                Subject     = "Hi Bob",
                BodyEncoded = EmailMessageParams.EncodeBody("Hi Bob")
            };

            var template = await _fixture.Database.FindTemplateAsync(_fixture.TemplateId);

            var expected = new EmailTemplate(args.Subject, args.Subject);

            // act
            var success = await _target.TrySendEmailAsync(args);

            // assert
            _transport.Verify(m => m.SendAsync(It.Is <SenderParams>(p =>
                                                                    p.Subject == expected.Subject && p.Body == expected.Body)));
        }