diff --git a/Infrastructure.Test/EmailTemplates/Test.html b/Infrastructure.Test/EmailTemplates/Test.html new file mode 100644 index 00000000..baf11369 --- /dev/null +++ b/Infrastructure.Test/EmailTemplates/Test.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Infrastructure.Test/EmailTemplates/TestWithParams.html b/Infrastructure.Test/EmailTemplates/TestWithParams.html new file mode 100644 index 00000000..c1e346a3 --- /dev/null +++ b/Infrastructure.Test/EmailTemplates/TestWithParams.html @@ -0,0 +1,13 @@ + + + + + + + + +

+ Hello {1}. +

+ + diff --git a/Infrastructure.Test/Infrastructure.Test.csproj b/Infrastructure.Test/Infrastructure.Test.csproj index 2258e57a..ae36f410 100644 --- a/Infrastructure.Test/Infrastructure.Test.csproj +++ b/Infrastructure.Test/Infrastructure.Test.csproj @@ -44,4 +44,13 @@ + + + Always + + + Always + + + diff --git a/Infrastructure.Test/Services/MailTemplates/MailTemplateTest.cs b/Infrastructure.Test/Services/MailTemplates/MailTemplateTest.cs new file mode 100644 index 00000000..e6980806 --- /dev/null +++ b/Infrastructure.Test/Services/MailTemplates/MailTemplateTest.cs @@ -0,0 +1,75 @@ +using System; +using System.Reflection; +using Kaizen.Core.Services; +using Kaizen.Infrastructure.Services.MailTemplates; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Moq; +using NUnit.Framework; + +namespace Infrastructure.Test.Services.MailTemplates +{ + [TestFixture] + public class MailTemplateTest + { + private IMailTemplate _mailTemplate; + private Mock _hostEnvironment; + + protected ServiceProvider ServiceProvider { get; private set; } + + [OneTimeSetUp] + public void Init() + { + ServiceCollection services = new ServiceCollection(); + services.AddLogging(); + + ServiceProvider = services.BuildServiceProvider(); + } + + [SetUp] + public void SetUp() + { + _hostEnvironment = new Mock(); + + string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + _hostEnvironment.Setup(h => h.ContentRootPath).Returns(path); + + _mailTemplate = new MailTemplate(_hostEnvironment.Object, + ServiceProvider.GetService>()); + } + + [Test] + public void Load_An_Existing_Template_Without_Params() + { + string template = _mailTemplate.LoadTemplate("Test.html"); + + Assert.IsNotNull(template); + Assert.IsTrue(template.Length > 0); + } + + [Test] + public void Load_An_Existing_Template_With_Params() + { + string template = _mailTemplate.LoadTemplate("TestWithParams.html", "World"); + + Assert.IsNotNull(template); + Assert.IsTrue(template.Length > 0); + Assert.IsTrue(template.Contains("Hello World.")); + } + + [Test] + public void Load_Non_Existent_Template() + { + try + { + string template = _mailTemplate.LoadTemplate("NonExistentTemplate.html"); + Assert.Fail("The template to search should not exist."); + } + catch (ArgumentException e) + { + Assert.AreEqual("Email template NonExistentTemplate.html does not exists.", e.Message); + } + } + } +}