Skip to content

Commit

Permalink
Merge pull request #5 from soygul/master
Browse files Browse the repository at this point in the history
Pull to Master
  • Loading branch information
rftd committed Nov 8, 2013
2 parents 9a019ad + 84e9ee2 commit b0ceca2
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 0 deletions.
1 change: 1 addition & 0 deletions NBug.Tests/NBug.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Integration\HandlerTests.cs" />
<Compile Include="Unit\BugReportTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Unit\Helpers\EmailDestinationBuilderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NBug\NBug.csproj">
Expand Down
288 changes: 288 additions & 0 deletions NBug.Tests/Unit/Helpers/EmailDestinationBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
namespace NBug.Tests.Unit.Helpers
{
using System.Net;
using System.Net.Mail;

using NBug.Helpers;

using Xunit;

public class EmailDestinationBuilderTests
{
private const string ServerName = "smtp.test.com";

[Fact]
public void BuildAttachmentsAndServerOptionsWithPort_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
var credential = new NetworkCredential("test", "foo");

string result = builder.SendAttachments().UseServer(true, 99, credential).Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};SmtpServer={4};UseSSL=yes;Port=99;UseAuthentication=yes;Username={5};Password={6};",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"true",
ServerName,
"test",
"foo");

Assert.Equal(expected, result);
}

[Fact]
public void BuildAttachmentsAndShortServerOptions_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
var credential = new NetworkCredential("test", "foo");

string result = builder.SendAttachments().UseServer(false, credential).Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};SmtpServer={4};UseSSL=no;Port=25;UseAuthentication=yes;Username={5};Password={6};",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"true",
ServerName,
"test",
"foo");

Assert.Equal(expected, result);
}

[Fact]
public void BuildCustomBody_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.Body("Bizz").Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};CustomBody={4};SmtpServer={5};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"false",
"Bizz",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void BuildCustomSubject_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.Subject("Buzz").Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};CustomSubject={4};SmtpServer={5};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"false",
"Buzz",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void BuildFromName_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.FromName("Homer").Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};FromName={1};To={2},{3};UseAttachment={4};SmtpServer={5};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
"Homer",
toAddress.Address,
anotherAddress.Address,
"false",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void BuildPriority_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.Priority(MailPriority.High).Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};SmtpServer={4};UseSSL=yes;Port=465;Priority={5};UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"false",
ServerName,
MailPriority.High);

Assert.Equal(expected, result);
}

[Fact]
public void BuildReplyTo_PreparesCorrectDestination()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.ReplyTo("B@rt").Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};ReplyTo={3};UseAttachment={4};SmtpServer={5};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"B@rt",
"false",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void BuildWithBcc_DefaultsToSecuredAnonymousConnectionNoAttachments()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

var bcc1 = new MailAddress("[email protected]");
var bcc2 = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);

string result = builder.Bcc(new[] { bcc1, bcc2 }).Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};Bcc={3},{4};UseAttachment={5};SmtpServer={6};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
bcc1.Address,
bcc2.Address,
"false",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void BuildWithCc_DefaultsToSecuredAnonymousConnectionNoAttachments()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");
var cc1 = new MailAddress("[email protected]");
var cc2 = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);

string result = builder.Cc(new[] { cc1, cc2 }).Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};Cc={3},{4};UseAttachment={5};SmtpServer={6};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
cc1.Address,
cc2.Address,
"false",
ServerName);

Assert.Equal(expected, result);
}

[Fact]
public void Build_DefaultsToSecuredAnonymousConnectionNoAttachments()
{
// Arrange
var fromAddress = new MailAddress("[email protected]");
var toAddress = new MailAddress("[email protected]");
var anotherAddress = new MailAddress("[email protected]");

// Act
var builder = new EmailDestinationBuilder(fromAddress, new[] { toAddress, anotherAddress }, ServerName);
string result = builder.Build();

// Assert
var expected =
string.Format(
"Type=Mail;From={0};To={1},{2};UseAttachment={3};SmtpServer={4};UseSSL=yes;Port=465;UseAuthentication=no;",
fromAddress.Address,
toAddress.Address,
anotherAddress.Address,
"false",
ServerName);

Assert.Equal(expected, result);
}
}
}
Loading

0 comments on commit b0ceca2

Please sign in to comment.