public async Task Render_returns_email_string_with_img_created_by_view()
        {
            var email = new Email("Test");
            var cid   = email.ImageEmbedder.ReferenceImage("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");

            var mvcViewOptions = new Mock <Microsoft.Extensions.Options.IOptions <MvcViewOptions> >();

            //var tmp = controller.Resolver.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
            //ICompositeViewEngine engine = new CompositeViewEngine(mvcViewOptions.Object);

            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView(_ => _.ViewData[ImageEmbedder.ViewDataKey] != null ? "True" : "False");

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view));

            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(email);

            actualEmailString.ShouldBe("True");

            viewEngine.Verify();
        }
        public async Task Render_throws_exception_when_email_view_not_found()
        {
            var viewEngine = new Mock <IRazorViewEngine>();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.NotFound("Test", new[] { "Test" }));
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            await Assert.ThrowsAsync <TemplateServiceException>(() => renderer.RenderAsync(new Email("Test")));

            viewEngine.Verify();
        }
Ejemplo n.º 3
0
        public async Task Render_throws_exception_when_email_view_retrievepath_not_found()
        {
            var viewEngine = new Mock <IRazorViewEngine>();

            viewEngine.Setup(e => e.GetView(It.IsAny <string>(), "~/Views/TestFolder/Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.NotFound("~/Views/TestFolder/Test", new[] { "Test" })).Verifiable();

            var logger                       = new Mock <ILogger <TemplateService> >();
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            var hostingEnvironment           = new Mock <IWebHostEnvironment>();
            ITemplateService templateService = new TemplateService(logger.Object, viewEngine.Object, serviceProvider.Object, tempDataProvider.Object, hostingEnvironment.Object);
            var renderer                     = new EmailViewRender(templateService);

            await Assert.ThrowsAsync <TemplateServiceException>(() => renderer.RenderAsync(new Email("~/Views/TestFolder/Test")));

            viewEngine.Verify();
        }
        public async Task Render_returns_email_string_created_by_view()
        {
            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view));

            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            ITemplateService templateService = new TemplateService(viewEngine.Object, serviceProvider.Object, tempDataProvider.Object);
            var renderer = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(new Email("Test"));

            actualEmailString.ShouldBe("Fake");

            viewEngine.Verify();
        }
Ejemplo n.º 5
0
        public async Task Render_returns_email_string_created_by_view_generic_host()
        {
            var viewEngine = new Mock <IRazorViewEngine>();
            var view       = new FakeView();

            viewEngine.Setup(e => e.FindView(It.IsAny <ActionContext>(), "Test", It.IsAny <bool>()))
            .Returns(ViewEngineResult.Found("Test", view)).Verifiable();

            var logger                       = new Mock <ILogger <TemplateService> >();
            var serviceProvider              = new Mock <IServiceProvider>();
            var tempDataProvider             = new Mock <ITempDataProvider>();
            var hostingEnvironment           = new Mock <Microsoft.Extensions.Hosting.IHostEnvironment>();
            ITemplateService templateService = new TemplateService(logger.Object, viewEngine.Object, serviceProvider.Object, tempDataProvider.Object, hostingEnvironment.Object);
            var renderer                     = new EmailViewRender(templateService);

            var actualEmailString = await renderer.RenderAsync(new Email("Test"));

            actualEmailString.ShouldBe("Fake");

            viewEngine.Verify();
        }
Ejemplo n.º 6
0
        /// <summary>Creates a new <see cref="EmailService"/>, using the given view engines.</summary>
        public static EmailService Create(IServiceProvider serviceProvider, Func <SmtpClient> createSmtpClient = null)
        {
            EmailViewRender emailViewRender = serviceProvider.GetRequiredService <EmailViewRender>();

            return(new EmailService(emailViewRender, createSmtpClient: createSmtpClient));
        }