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)));
        }
Esempio n. 2
0
        public async Task TrySendEmailAsync_ShouldUseBaseTemplate_IfInvalidCultureProvided()
        {
            // arrange
            var args = new EmailMessageParams
            {
                Culture       = "zu-ZA",
                ApplicationId = _fixture.ApplicationId,
                TemplateId    = _fixture.TemplateId,
                To            = new List <string> {
                    "*****@*****.**"
                },
                Data = new Dictionary <string, object> {
                    { "Name", "Someone" }
                }
            };

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

            var expected = await MustacheTemplateTransformer.Instance.TransformTemplateAsync(
                new EmailTemplate(
                    template.SubjectTemplate,
                    template.BodyTemplate),
                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)));
        }