Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Created August 5, 2012 02:32
Show Gist options
  • Save ferclaverino/3261191 to your computer and use it in GitHub Desktop.
Save ferclaverino/3261191 to your computer and use it in GitHub Desktop.
Liskov - step 0
[TestFixture]
class MailBuilderTest
{
[Test]
public void TestContactInformation()
{
// arrange
ContactInformation contactInformation = new ContactInformation()
{
FirstName = "Homero",
LastName = "Simpson"
};
IMailMessageBuilder<ContactInformation> mailBuilder = new ContactInformationMailMessageBuilder();
// act
MailMessage message = mailBuilder
.WithFrom("[email protected]")
.WithTo("[email protected]")
.WithSubject("Hola")
.WithEntity(contactInformation).BuildMessage();
// assert
Assert.That(message.From.Address, Is.EqualTo("[email protected]"));
Assert.That(message.To, Has.All.Matches<MailAddress>(x => x.Address == "[email protected]"));
Assert.That(message.Subject, Is.EqualTo("Hola"));
Assert.That(message.Body, Is.StringContaining("Nombre: Homero"));
Assert.That(message.Body, Is.StringContaining("Apellido: Simpson"));
}
[Test]
public void TestContactInformationSubsidiary()
{
// arrange
ContactInformationSubsidiary contactInformation = new ContactInformationSubsidiary()
{
FirstName = "Homero",
LastName = "Simpson",
Subsidiary = "Retiro"
};
IMailMessageBuilder<ContactInformation> mailBuilder = new ContactInformationMailMessageBuilder();
// act
MailMessage message = mailBuilder
.WithFrom("[email protected]")
.WithTo("[email protected]")
.WithSubject("Hola")
.WithEntity(contactInformation).BuildMessage();
// assert
Assert.That(message.From.Address, Is.EqualTo("[email protected]"));
Assert.That(message.To, Has.All.Matches<MailAddress>(x => x.Address == "[email protected]"));
Assert.That(message.Subject, Is.EqualTo("Hola"));
Assert.That(message.Body, Is.StringContaining("Nombre: Homero"));
Assert.That(message.Body, Is.StringContaining("Apellido: Simpson"));
Assert.That(message.Body, Is.StringContaining("Sucursal: Retiro"));
}
[Test]
public void TestContactInformationAuctionSaleArtWork()
{
// arrange
ContactInformation contactInformation = new ContactInformationAuction()
{
FirstName = "Homero",
LastName = "Simpson",
Author = "Picasso",
Dimensions = "3x3"
};
IMailMessageBuilder<ContactInformation> mailBuilder = new ContactInformationMailMessageBuilder();
// act
MailMessage message = mailBuilder
.WithFrom("[email protected]")
.WithTo("[email protected]")
.WithSubject("Hola")
.WithEntity(contactInformation).BuildMessage();
// assert
Assert.That(message.From.Address, Is.EqualTo("[email protected]"));
Assert.That(message.To, Has.All.Matches<MailAddress>(x => x.Address == "[email protected]"));
Assert.That(message.Subject, Is.EqualTo("Hola"));
Assert.That(message.Body, Is.StringContaining("Nombre: Homero"));
Assert.That(message.Body, Is.StringContaining("Apellido: Simpson"));
Assert.That(message.Body, Is.StringContaining("Autor: Picasso"));
Assert.That(message.Body, Is.StringContaining("Dimensiones: 3x3"));
}
}
public IMailMessageBuilder<ContactInformation> WithEntity(ContactInformation contactInformation)
{
ParseContactInformation(contactInformation);
if (contactInformation is ContactInformationSubsidiary)
{
ContactInformationSubsidiary contact = contactInformation as ContactInformationSubsidiary;
ParseContactInformationSubsidiary(contact);
}
else if (contactInformation is ContactInformationAuction)
{
ContactInformationAuction contact = contactInformation as ContactInformationAuction;
ParseContactInformationAuction(contact);
}
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment