Skip to content

Commit

Permalink
Merge pull request smsohan#58 from tylermercier/master
Browse files Browse the repository at this point in the history
Version 1.2 ready
  • Loading branch information
smsohan committed Sep 26, 2012
2 parents c31b69f + fc9573a commit 3bd4d3a
Show file tree
Hide file tree
Showing 71 changed files with 15,842 additions and 947 deletions.
19 changes: 5 additions & 14 deletions Mvc.Mailer.Test/ExtensionMethods/HtmlHelperExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework;
using Moq;
using System.Web.Mvc;
using Mvc.Mailer;

namespace Mvc.Mailer.Test
{
namespace Mvc.Mailer.Test.ExtensionMethods {
[TestFixture]
public class HtmlHelperExtensionsTest
{
public class HtmlHelperExtensionsTest {
[Test]
public void InlineAttachment_should_produce_the_right_tag()
{
public void InlineAttachment_should_produce_the_right_tag() {
var htmlHelper = new HtmlHelper(new ViewContext(), new Mock<IViewDataContainer>().Object);
Assert.AreEqual("<img src=\"cid:logo\" alt=\"\"/>", htmlHelper.InlineImage("logo").ToString());
}

[Test]
public void InlineAttachment_should_produce_the_right_tag_with_alt()
{
public void InlineAttachment_should_produce_the_right_tag_with_alt() {
var htmlHelper = new HtmlHelper(new ViewContext(), new Mock<IViewDataContainer>().Object);
Assert.AreEqual("<img src=\"cid:logo\" alt=\"Company Logo\"/>", htmlHelper.InlineImage("logo", "Company Logo").ToString());
}
Expand Down
44 changes: 14 additions & 30 deletions Mvc.Mailer.Test/ExtensionMethods/MailMessageExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Mvc.Mailer;
using System.Net.Mail;
using System.IO;
using System.Threading;
using Moq;

namespace Mvc.Mailer.Test
{
namespace Mvc.Mailer.Test.ExtensionMethods {
[TestFixture]
public class MailMessageExtensionsTest
{
public class MailMessageExtensionsTest {

private SmtpClientWrapper _smtpClient;
private MailMessage _mailMessage;
private MailMessage _mailMessage;
private DirectoryInfo _mailDirectory;

[SetUp]
public void SetUp()
{
var smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
public void SetUp() {
var smtpClient = new SmtpClient {
DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
};

_mailDirectory = Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "Mails"));
smtpClient.PickupDirectoryLocation = _mailDirectory.FullName;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 597;
_smtpClient = new SmtpClientWrapper{InnerSmtpClient = smtpClient};
_smtpClient = new SmtpClientWrapper { InnerSmtpClient = smtpClient };
_mailMessage = new MailMessage { From = new MailAddress("gaga@gaga.com") };
_mailMessage.To.Add("gigi@gigi.com");
_mailMessage.Subject = "Hello!";
_mailMessage.Body = "Mail Body";
}

[Test]
public void TestSend()
{
public void TestSend() {
_mailMessage.Send(_smtpClient);
Assert.Pass("Mail Send working since no exception wast thrown");
}

[Test]
public void TestSendAsync()
{
public void TestSendAsync() {
_mailMessage.SendAsync(smtpClient: _smtpClient);
Assert.Pass("Mail Send Async working since no exception wast thrown");

}

[Test]
public void SendAsync_with_userState_should_pass_that()
{
public void SendAsync_with_userState_should_pass_that() {
var client = new Mock<ISmtpClient>();
client.Setup(c => c.SendAsync(_mailMessage, "something"));
_mailMessage.SendAsync(userState: "something", smtpClient: client.Object);
client.VerifyAll();
}

[Test]
public void In_Test_Mode_should_use_TestSmtpClient()
{
public void In_Test_Mode_should_use_TestSmtpClient() {
TestSmtpClient.SentMails.Clear();
MailerBase.IsTestModeEnabled = true;
_mailMessage.Send();
Expand All @@ -71,14 +59,10 @@ public void In_Test_Mode_should_use_TestSmtpClient()
}

[TearDown]
public void TearDown()
{
public void TearDown() {
MailerBase.IsTestModeEnabled = false;
TestSmtpClient.SentMails.Clear();
_mailDirectory.Delete(true);
}



}
}
}
45 changes: 14 additions & 31 deletions Mvc.Mailer.Test/ExtensionMethods/UrlHelperExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.IO;
using System.Configuration;

namespace Mvc.Mailer.Test
{
namespace Mvc.Mailer.Test.ExtensionMethods {
[TestFixture]
public class UrlHelperExtensionsTest
{
public class UrlHelperExtensionsTest {
UrlHelper _urlHelper;

[SetUp]
public void Init()
{
public void Init() {
var httpContext = HttpContext.Current;

if (httpContext == null)
{
if (httpContext == null) {
var request = new HttpRequest("/", "http://example.com:8080", "");
var response = new HttpResponse(new StringWriter());
httpContext = new HttpContext(request, response);
Expand All @@ -36,55 +28,46 @@ public void Init()
}

[Test]
public void Abs_with_abs_should_return_itself()
{
public void Abs_with_abs_should_return_itself() {
Assert.AreEqual("http://hello.com/any/thing", _urlHelper.Abs("http://hello.com/any/thing"));
}

[Test]
public void Abs_with_relative_should_absolutilze()
{
public void Abs_with_relative_should_absolutilze() {
Assert.AreEqual("http://example.com:8080/any/thing", _urlHelper.Abs("/any/thing"));
}

[Test]
public void Abs_with_root_should_absolutilze()
{
public void Abs_with_root_should_absolutilze() {
Assert.AreEqual("http://example.com:8080/", _urlHelper.Abs("/"));
}

[Test]
public void Abs_with_encoded_params_should_keep_encoding()
{
public void Abs_with_encoded_params_should_keep_encoding() {
Assert.AreEqual("http://example.com:8080/?param=encoded%20value", _urlHelper.Abs("/?param=encoded%20value"));
}

[Test]
public void Abs_with_config_should_use_the_base_url_from_the_config()
{
public void Abs_with_config_should_use_the_base_url_from_the_config() {
ConfigurationManager.AppSettings[UrlHelperExtensions.BASE_URL_KEY] = "http://my:666";
Assert.AreEqual("http://my:666/hello/there", _urlHelper.Abs("/hello/there"));
}

[Test]
public void Abs_with_config_should_not_double_slash_when_using_the_base_url_from_the_config()
{
public void Abs_with_config_should_not_double_slash_when_using_the_base_url_from_the_config() {
ConfigurationManager.AppSettings[UrlHelperExtensions.BASE_URL_KEY] = "http://my:666/";
Assert.AreEqual("http://my:666/hello/there", _urlHelper.Abs("/hello/there"));
}

[Test]
public void Abs_with_config_should_put_a_slash_when_using_the_base_url_from_the_config()
{
public void Abs_with_config_should_put_a_slash_when_using_the_base_url_from_the_config() {
ConfigurationManager.AppSettings[UrlHelperExtensions.BASE_URL_KEY] = "http://my:666";
Assert.AreEqual("http://my:666/hello/there", _urlHelper.Abs("hello/there"));
}

[TearDown]
public void TearDown()
{
public void TearDown() {
ConfigurationManager.AppSettings[UrlHelperExtensions.BASE_URL_KEY] = string.Empty;
}

}
}
}
31 changes: 9 additions & 22 deletions Mvc.Mailer.Test/LinkedResourceProviderTest.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;
using Mvc.Mailer;
using System.Net.Mail;
using System.IO;
using System.Net.Mime;

namespace Mvc.Mailer.Test
{
namespace Mvc.Mailer.Test {
[TestFixture]
public class LinkedResourceProviderTest
{
public class LinkedResourceProviderTest {
[Test]
public void Test_GetAll_should_call_get_and_add_to_list()
{
var linkedResourceProvider = new Mock<LinkedResourceProvider>();
linkedResourceProvider.CallBase = true;
public void Test_GetAll_should_call_get_and_add_to_list() {
var linkedResourceProvider = new Mock<LinkedResourceProvider> { CallBase = true };

var logo = new LinkedResource(new MemoryStream());
var banner = new LinkedResource(new MemoryStream());
Expand All @@ -38,20 +31,14 @@ public void Test_GetAll_should_call_get_and_add_to_list()
}

[Test]
public void Test_Get_should_return_a_linked_resource()
{
var linkedResourceProvider = new Mock<LinkedResourceProvider>();
linkedResourceProvider.CallBase = true;
public void Test_Get_should_return_a_linked_resource() {
var linkedResourceProvider = new Mock<LinkedResourceProvider> { CallBase = true };

var fileName = "Chrysanthemum.jpg";
const string fileName = "Chrysanthemum.jpg";
var linkedResource = linkedResourceProvider.Object.Get("flower", fileName);

Assert.AreEqual("flower", linkedResource.ContentId);
Assert.AreEqual(new ContentType("image/jpeg"), linkedResource.ContentType);

}



}
}
}
23 changes: 7 additions & 16 deletions Mvc.Mailer.Test/MailerBaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Mvc.Mailer;
using System.Net.Mail;
using System.Web.Mvc;
using Moq;
using System.IO;
using System.Web.Routing;
using System.Web;

namespace Mvc.Mailer.Test {
[TestFixture]
Expand All @@ -24,8 +21,7 @@ public void Setup() {
_mailerBase = new MailerBase();
_mailMessage = new MailMessage();

_mockMailer = new Mock<MailerBase>();
_mockMailer.CallBase = true;
_mockMailer = new Mock<MailerBase> { CallBase = true };
}

#region Properties Related tests
Expand All @@ -52,12 +48,12 @@ public void Test_IsTestModeEnabled() {
Assert.IsTrue(MailerBase.IsTestModeEnabled);
MailerBase.IsTestModeEnabled = false;
Assert.IsFalse(MailerBase.IsTestModeEnabled);

}

#endregion

#region Text related tests

[Test]
public void PopulateTextBody_should_unmark_as_is_body_html() {
_mockMailer.Setup(m => m.EmailBody("Welcome.text", "Layout.text")).Returns("Hello");
Expand Down Expand Up @@ -102,6 +98,7 @@ public void PopulateTextPart_should_use_right_view_name_and_mime() {
#endregion

#region Html related tests

[Test]
public void PopulateHtmltBody_should_mark_as_is_body_html() {
_mockMailer.Setup(m => m.EmailBody("Welcome", "Layout")).Returns("<h1>Hello</h1>");
Expand Down Expand Up @@ -136,8 +133,7 @@ public void PopulateHtmlPart_should_use_right_view_name_and_mime() {
#region Multi-part related tests

[Test]
public void Populate_should_create_a_mail_message_and_invoke_action()
{
public void Populate_should_create_a_mail_message_and_invoke_action() {
var linkedResources = new Dictionary<string, string>();
_mockMailer.Setup(x => x.PopulateBody(It.IsAny<MailMessage>(), "welcome", "master", linkedResources));
var mailMessage = _mockMailer.Object.Populate(x => {
Expand Down Expand Up @@ -187,7 +183,6 @@ public void PopulateBody_should_populate_body_with_html_when_only_html_present()
resourcesToTry.Add(null);
resourcesToTry.Add(new Dictionary<string, string>());


foreach (var resources in resourcesToTry) {
_mockMailer.Setup(m => m.TextViewExists("welcome", "Mail")).Returns(false);
_mockMailer.Setup(m => m.HtmlViewExists("welcome", "Mail")).Returns(true);
Expand All @@ -200,7 +195,6 @@ public void PopulateBody_should_populate_body_with_html_when_only_html_present()

[Test]
public void PopuateBody_should_populate_with_alternate_view_when_html_present_with_linked_resources() {

_mockMailer.Setup(m => m.TextViewExists("welcome", "Mail")).Returns(false);
_mockMailer.Setup(m => m.HtmlViewExists("welcome", "Mail")).Returns(true);

Expand Down Expand Up @@ -283,7 +277,6 @@ public void Test_PopulateLinkedResources_should_populate_each_resource() {
linkedResourceProviderMock.VerifyAll();
Assert.AreEqual(linkResources, htmlView.LinkedResources);
Assert.AreEqual(linkResources, actualResources);

}

[Test]
Expand All @@ -292,7 +285,7 @@ public void Test_PopulateLinkedResource_should_populate_the_resource() {

_mockMailer.Object.LinkedResourceProvider = linkedResourceProviderMock.Object;

LinkedResource linkResource = new LinkedResource(new MemoryStream());
var linkResource = new LinkedResource(new MemoryStream());

linkedResourceProviderMock.Setup(p => p.Get("logo", "logo.png")).Returns(linkResource);

Expand All @@ -303,15 +296,13 @@ public void Test_PopulateLinkedResource_should_populate_the_resource() {
Assert.AreEqual(1, htmlView.LinkedResources.Count);
Assert.AreEqual(linkResource, htmlView.LinkedResources.First());
Assert.AreEqual(linkResource, actualResource);

}
#endregion

private string GetContent(AlternateView alternateView) {
var dataStream = alternateView.ContentStream;
byte[] byteBuffer = new byte[dataStream.Length];
var byteBuffer = new byte[dataStream.Length];
return System.Text.Encoding.ASCII.GetString(byteBuffer, 0, dataStream.Read(byteBuffer, 0, byteBuffer.Length));
}

}
}
}
Loading

0 comments on commit 3bd4d3a

Please sign in to comment.