Пример #1
0
        public void ShouldProcessTemplateNonProd()
        {
            string        emailTo      = "*****@*****.**";
            string        bodyPrefix   = "Mock Body";
            string        environment  = "mock environment";
            string        expectedBody = $"{bodyPrefix} {environment}";
            EmailTemplate template     = new EmailTemplate()
            {
                Subject    = "Mock Subject",
                Body       = $"{bodyPrefix} ${{Environment}}",
                FormatCode = EmailFormat.Text,
                Priority   = EmailPriority.Standard,
            };
            Dictionary <string, string> d = new Dictionary <string, string>();
            var mockWebHosting            = new Mock <IWebHostEnvironment>();

            // mockWebHosting.Setup(s => s.IsProduction()).Returns(false);
            mockWebHosting.Setup(s => s.EnvironmentName).Returns(environment);
            IEmailQueueService emailService = new EmailQueueService(
                new Mock <ILogger <EmailQueueService> >().Object,
                new Mock <IBackgroundJobClient>().Object,
                new Mock <IEmailDelegate>().Object,
                new Mock <IMessagingVerificationDelegate>().Object,
                mockWebHosting.Object);
            Email actual = emailService.ProcessTemplate(emailTo, template, d);

            Assert.True(actual.Body == expectedBody);
        }
Пример #2
0
        public void ShouldProcessTemplate()
        {
            string emailTo = "*****@*****.**";
            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("SUBJECT", "Test Subject");
            d.Add("PARM1", "PARM1");
            d.Add("PARM2", "PARM2");
            d.Add("PARM3", "PARM3");
            EmailTemplate template = new EmailTemplate()
            {
                Subject    = "Subject=${SUBJECT}",
                Body       = "PARM1=${PARM1}, PARM2=${PARM2}, PARM3=${PARM3}",
                FormatCode = EmailFormat.Text,
                Priority   = EmailPriority.Standard,
            };
            Email expected = new Email()
            {
                To      = emailTo,
                Subject = "Subject=Test Subject",
                Body    = "PARM1=PARM1, PARM2=PARM2, PARM3=PARM3"
            };
            IEmailQueueService emailService = new EmailQueueService(
                new Mock <ILogger <EmailQueueService> >().Object,
                new Mock <IBackgroundJobClient>().Object,
                new Mock <IEmailDelegate>().Object,
                new Mock <IMessagingVerificationDelegate>().Object,
                new Mock <IWebHostEnvironment>().Object);
            Email actual = emailService.ProcessTemplate(emailTo, template, d);

            expected.Id = actual.Id;
            Assert.True(expected.IsDeepEqual(actual));
        }