Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
test(back-end): Add MailTemplate tests
Browse files Browse the repository at this point in the history
See also: #119
  • Loading branch information
CarlosPavajeau committed Jan 15, 2021
1 parent a513b46 commit 7b233f1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Infrastructure.Test/EmailTemplates/Test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>

</body>
</html>
13 changes: 13 additions & 0 deletions Infrastructure.Test/EmailTemplates/TestWithParams.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>
Hello {1}.
</p>
</body>
</html>
9 changes: 9 additions & 0 deletions Infrastructure.Test/Infrastructure.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@
<Folder Include="Identity\" />
</ItemGroup>

<ItemGroup>
<None Update="EmailTemplates\Test.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EmailTemplates\TestWithParams.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
75 changes: 75 additions & 0 deletions Infrastructure.Test/Services/MailTemplates/MailTemplateTest.cs
Original file line number Diff line number Diff line change
@@ -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<IHostEnvironment> _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<IHostEnvironment>();

string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
_hostEnvironment.Setup(h => h.ContentRootPath).Returns(path);

_mailTemplate = new MailTemplate(_hostEnvironment.Object,
ServiceProvider.GetService<ILogger<MailTemplate>>());
}

[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);
}
}
}
}

0 comments on commit 7b233f1

Please sign in to comment.