Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarnold committed Mar 25, 2012
1 parent 0c450c5 commit c78a239
Show file tree
Hide file tree
Showing 30 changed files with 1,415 additions and 0 deletions.
1 change: 1 addition & 0 deletions TESTS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EmbeddedMail.Tests
98 changes: 98 additions & 0 deletions src/EmbeddedMail.Tests/EmbeddedMail.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AA9B50AA-275C-4108-9B53-0A5947C553DC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EmbeddedMail.Tests</RootNamespace>
<AssemblyName>EmbeddedMail.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FubuCore">
<HintPath>..\packages\FubuCore.0.9.4.117\lib\FubuCore.dll</HintPath>
</Reference>
<Reference Include="FubuTestingSupport">
<HintPath>..\packages\FubuTestingSupport.0.9.4.117\lib\FubuTestingSupport.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.mocks">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll</HintPath>
</Reference>
<Reference Include="pnunit.framework">
<HintPath>..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks">
<HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="StructureMap">
<HintPath>..\packages\structuremap.2.6.3\lib\StructureMap.dll</HintPath>
</Reference>
<Reference Include="StructureMap.AutoMocking">
<HintPath>..\packages\structuremap.automocking.2.6.3\lib\StructureMap.AutoMocking.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Handlers\DataHandlerTester.cs" />
<Compile Include="Handlers\HeloHandlerTester.cs" />
<Compile Include="Handlers\MessageParsingHandlerTester.cs" />
<Compile Include="Handlers\QuitHandlerTester.cs" />
<Compile Include="Handlers\RegisterAddressesHandlerTester.cs" />
<Compile Include="EmbeddedSmtpServerIntegratedTester.cs" />
<Compile Include="PortFinder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SmtpTokenTester.cs" />
<Compile Include="StubSmtpSession.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EmbeddedMail\EmbeddedMail.csproj">
<Project>{63FEC2DC-0739-42EF-B73C-EC9F8FF19573}</Project>
<Name>EmbeddedMail</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
52 changes: 52 additions & 0 deletions src/EmbeddedMail.Tests/EmbeddedSmtpServerIntegratedTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Linq;
using System.Net.Mail;
using FubuTestingSupport;
using NUnit.Framework;

namespace EmbeddedMail.Tests
{
[TestFixture]
public class EmbeddedSmtpServerIntegratedTester
{
private EmbeddedSmtpServer theServer;
private MailMessage theMessage;

[TestFixtureSetUp]
public void BeforeAll()
{
var port = PortFinder.FindPort(8181);
theServer = new EmbeddedSmtpServer(port);
theMessage = new MailMessage("x@domain.com", "y@domain.com", "Hello there", "O hai");
theMessage.CC.Add("copy@domain.com");
theMessage.Bcc.Add("blind@domain.com");
theServer.Start();

using (var client = new SmtpClient("localhost", 8181))
{
client.Send(theMessage);
client.Send(theMessage);
}

theServer.Stop();
}

[Test]
public void receives_the_message()
{
var message = theServer.ReceivedMessages().First();
message.From.ShouldEqual(theMessage.From);
message.To.First().ShouldEqual(theMessage.To.First());
message.Subject.ShouldEqual(theMessage.Subject);
message.Body.ShouldEqual(theMessage.Body);

message.CC.Single().ShouldEqual(theMessage.CC.Single());
message.Bcc.Single().ShouldEqual(theMessage.Bcc.Single());
}

[Test]
public void receives_multiple_messages()
{
theServer.ReceivedMessages().ShouldHaveCount(2);
}
}
}
68 changes: 68 additions & 0 deletions src/EmbeddedMail.Tests/Handlers/DataHandlerTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using EmbeddedMail.Handlers;
using FubuTestingSupport;
using NUnit.Framework;
using Rhino.Mocks;

namespace EmbeddedMail.Tests.Handlers
{
[TestFixture]
public class DataHandlerTester
{
private DataHandler theHandler;
private ISmtpSession theSession;
private SmtpToken theToken;

[SetUp]
public void SetUp()
{
theSession = MockRepository.GenerateStub<ISmtpSession>();
theHandler = new DataHandler();
theToken = new SmtpToken();
}

[Test]
public void matches_data_command()
{
theToken.Command = "DATA";
theHandler.Matches(theToken).ShouldBeTrue();
}

[Test]
public void does_not_match_message_body()
{
theToken.Command = "DATA";
theToken.IsMessageBody = true;

theHandler.Matches(theToken).ShouldBeFalse();
}

[Test]
public void does_not_match_other_commands()
{
theToken.Command = "BLAH";
theToken.IsMessageBody = true;

theHandler.Matches(theToken).ShouldBeFalse();
}

[Test]
public void writes_end_character_response()
{
theHandler.Handle(theToken, theSession);
theSession.AssertWasCalled(x => x.WriteResponse("354 End data with ."));
}

[Test]
public void sets_the_message_body_flag()
{
theHandler.Handle(theToken, theSession);
theToken.IsMessageBody.ShouldBeTrue();
}

[Test]
public void should_continue()
{
theHandler.Handle(theToken, theSession).ShouldEqual(ContinueProcessing.Continue);
}
}
}
59 changes: 59 additions & 0 deletions src/EmbeddedMail.Tests/Handlers/HeloHandlerTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using EmbeddedMail.Handlers;
using FubuTestingSupport;
using NUnit.Framework;
using Rhino.Mocks;

namespace EmbeddedMail.Tests.Handlers
{
[TestFixture]
public class HeloHandlerTester
{
private HeloHandler theHandler;
private ISmtpSession theSession;
private SmtpToken theToken;

[SetUp]
public void SetUp()
{
theSession = MockRepository.GenerateStub<ISmtpSession>();
theHandler = new HeloHandler();
theToken = new SmtpToken();

theSession.Stub(x => x.RemoteAddress).Return("1234");
}

[Test]
public void matches_helo_command()
{
theToken.Command = "HELO";
theHandler.Matches(theToken).ShouldBeTrue();
}

[Test]
public void matches_ehlo_command()
{
theToken.Command = "EHLO";
theHandler.Matches(theToken).ShouldBeTrue();
}

[Test]
public void does_not_match_other_commands()
{
theToken.Command = "BLAH";
theHandler.Matches(theToken).ShouldBeFalse();
}

[Test]
public void writes_hello_response()
{
theHandler.Handle(theToken, theSession);
theSession.AssertWasCalled(x => x.WriteResponse("250 Hello 1234, I am glad to meet you"));
}

[Test]
public void should_continue()
{
theHandler.Handle(theToken, theSession).ShouldEqual(ContinueProcessing.Continue);
}
}
}
Loading

0 comments on commit c78a239

Please sign in to comment.