This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(back-end): Add MailTemplate tests
See also: #119
- Loading branch information
1 parent
a513b46
commit 7b233f1
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Infrastructure.Test/Services/MailTemplates/MailTemplateTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |