-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bumped version to 5.6.1 - see changes in release comments
- Loading branch information
Showing
12 changed files
with
317 additions
and
43 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
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
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
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
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
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,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MailMergeLib; | ||
using NUnit.Framework; | ||
|
||
namespace UnitTests | ||
{ | ||
[TestFixture] | ||
public class HtmlBodyBuilderTest | ||
{ | ||
[TestCase("Temp")] | ||
[TestCase("..\\..\\temp")] | ||
public void SetHtmlBuilderDocBaseUri_UriFormatException(string baseUri) | ||
{ | ||
var mmm = new MailMergeMessage("subject", "plain text", "<html><head><base href=\"\" /></head><body></body></html>"); | ||
var hbb = new HtmlBodyBuilder(mmm, (object)null); | ||
Assert.Throws<UriFormatException>(() => hbb.DocBaseUri = baseUri); | ||
} | ||
|
||
[TestCase(null)] | ||
[TestCase("")] | ||
[TestCase("C:\\Temp")] | ||
[TestCase("\\\\some\\unc\\path")] | ||
public void SetHtmlBuilderDocBaseUri_NoException(string baseUri) | ||
{ | ||
var mmm = new MailMergeMessage("subject", "plain text", "<html><head><base href=\"\" /></head><body></body></html>"); | ||
var hbb = new HtmlBodyBuilder(mmm, (object)null); | ||
Assert.DoesNotThrow(() => hbb.DocBaseUri = baseUri); | ||
} | ||
|
||
[Test] | ||
public void ScriptTagRemoved() | ||
{ | ||
var mmm = new MailMergeMessage("subject_to_set", "plain text", "<html><head><script>var x='x';</script><script>var y='y';</script></head><body>some body</body></html>"); | ||
var hbb = new HtmlBodyBuilder(mmm, (object)null); | ||
var html = hbb.GetBodyPart(); | ||
Assert.IsTrue(html.ToString().Contains("some body")); | ||
Assert.IsTrue(!html.ToString().Contains("script")); | ||
} | ||
|
||
[Test] | ||
public void ExistingTitleTagSetWithSubject() | ||
{ | ||
var subjectToSet = "subject_to_set"; | ||
var mmm = new MailMergeMessage(subjectToSet, "plain text", "<html><head><title>abc</title></head><body></body></html>"); | ||
var hbb = new HtmlBodyBuilder(mmm, (object)null); | ||
var html = hbb.GetBodyPart(); | ||
Assert.IsTrue(html.ToString().Contains(subjectToSet)); | ||
} | ||
|
||
[Test] | ||
public void NonExistingTitleTagSetWithSubject() | ||
{ | ||
var subjectToSet = "subject_to_set"; | ||
var mmm = new MailMergeMessage(subjectToSet, "plain text", "<html><head></head><body></body></html>"); | ||
var hbb = new HtmlBodyBuilder(mmm, (object)null); | ||
var html = hbb.GetBodyPart(); | ||
Assert.IsTrue(!html.ToString().Contains(subjectToSet)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,25 +9,109 @@ namespace UnitTests | |
public class Message_Config | ||
{ | ||
private MessageConfig _msgConfig = new MessageConfig(); | ||
private string _tempPath = Path.GetTempPath(); | ||
|
||
[TestCase(" \t", "?")] | ||
[TestCase(" ", "?")] | ||
[TestCase("", "?")] | ||
[TestCase(null, "?")] | ||
[TestCase("\\noFullPath", null)] | ||
[TestCase(" \t", "")] | ||
[TestCase(" ", "")] | ||
[TestCase("", "")] | ||
[TestCase(null, "")] | ||
[TestCase("noFullPath", "noFullPath")] | ||
[TestCase("C:\\some\\path\\to\\folder", "C:\\some\\path\\to\\folder")] | ||
public void SetFileBaseDirectory(string path, string expected) | ||
{ | ||
if (expected == "?") expected = Path.GetTempPath(); | ||
_msgConfig.FileBaseDirectory = path; | ||
Assert.AreEqual(expected, _msgConfig.FileBaseDirectory); | ||
} | ||
|
||
[TestCase(" \t", false)] | ||
[TestCase(" ", false)] | ||
[TestCase("", false)] | ||
[TestCase(null, false)] | ||
[TestCase("C:\\some\\path\\to\\folder", false)] | ||
[TestCase("\\\\some\\unc\\path", false)] | ||
[TestCase("noFullPath", true)] | ||
[TestCase("..\\..\\relativePath", true)] | ||
public void FileBaseDirectory_must_be_full_path_when_processing_the_message(string path, bool shouldThrow) | ||
{ | ||
var mmm = new MailMergeMessage("subject", "plain text", "<html><body></body></html>"); | ||
mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, "[email protected]")); | ||
mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, "[email protected]")); | ||
mmm.Config.FileBaseDirectory = path; | ||
|
||
if (shouldThrow) | ||
{ | ||
try | ||
{ | ||
mmm.GetMimeMessage(null); | ||
} | ||
catch (Exception e) | ||
{ | ||
Assert.IsTrue(e is MailMergeMessage.MailMergeMessageException); | ||
Assert.IsTrue(e.InnerException != null); | ||
} | ||
} | ||
else | ||
{ | ||
Assert.DoesNotThrow(() => mmm.GetMimeMessage(null)); | ||
} | ||
} | ||
|
||
[TestCase(" \t", "file:///")] | ||
[TestCase(" ", "file:///")] | ||
[TestCase("", "file:///")] | ||
[TestCase("C:\\some\\path\\to\\folder", "file:///C:/some/path/to/folder")] | ||
[TestCase("\\\\some\\unc\\path", "file://some/unc/path")] | ||
[TestCase("noFullPath", null)] | ||
[TestCase("..\\..\\relativePath", null)] | ||
public void HtmlBodyBuilderDocBaseUri_vs_MessageConfig_FileBaseDirectory(string path, string expected) | ||
{ | ||
var mmm = new MailMergeMessage("subject", "plain text", "<html><body></body></html>"); | ||
mmm.Config.FileBaseDirectory = path; | ||
|
||
HtmlBodyBuilder hbb; | ||
if (expected == null) | ||
{ | ||
Assert.Throws<ArgumentException>(() => _msgConfig.FileBaseDirectory = path); | ||
return; | ||
Assert.Throws<UriFormatException>(() => { hbb = new HtmlBodyBuilder(mmm, (object) null); }); | ||
} | ||
else | ||
{ | ||
hbb = new HtmlBodyBuilder(mmm, (object) null); | ||
Assert.AreEqual(expected, hbb.DocBaseUri); | ||
} | ||
} | ||
|
||
_msgConfig.FileBaseDirectory = path; | ||
Assert.AreEqual(expected, _msgConfig.FileBaseDirectory); | ||
[Test] | ||
public void MessageConfig_FileBaseDirectory_cannot_be_changed_by_Html_Base_Tag() | ||
{ | ||
var mmm = new MailMergeMessage("subject", "plain text", | ||
"<html><head><base href=\"\" /></head><body></body></html>"); | ||
mmm.Config.FileBaseDirectory = Path.GetTempPath(); | ||
|
||
var hbb = new HtmlBodyBuilder(mmm, (object) null); | ||
Assert.AreEqual(new Uri(mmm.Config.FileBaseDirectory), hbb.DocBaseUri); | ||
} | ||
|
||
[Test] | ||
public void Empty_MessageConfig_FileBaseDirectory_is_changed_by_Html_Base_Tag() | ||
{ | ||
var baseTagHref = "file:///C:/Temp/"; | ||
var mmm = new MailMergeMessage("subject", "plain text", | ||
$"<html><head><base href=\"{baseTagHref}\" /></head><body></body></html>"); | ||
mmm.Config.FileBaseDirectory = string.Empty; | ||
|
||
var hbb = new HtmlBodyBuilder(mmm, (object) null); | ||
hbb.GetBodyPart(); | ||
Assert.AreEqual(baseTagHref, hbb.DocBaseUri); | ||
} | ||
|
||
[Test] | ||
public void HashCode() | ||
{ | ||
var mc1 = new MessageConfig(); | ||
var mc2 = new MessageConfig(); | ||
|
||
Assert.AreEqual(mc1.GetHashCode(), mc2.GetHashCode()); | ||
Assert.AreEqual(mc1.GetHashCode(), mc1.GetHashCode()); | ||
Assert.AreEqual(mc2.GetHashCode(), mc2.GetHashCode()); | ||
} | ||
} | ||
} |
Oops, something went wrong.