Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Created July 17, 2012 01:41
Show Gist options
  • Save ferclaverino/3126395 to your computer and use it in GitHub Desktop.
Save ferclaverino/3126395 to your computer and use it in GitHub Desktop.
Open closed example, step 2
[TestFixture]
class FilterTest
{
[Test]
public void filterByBlue_return_2()
{
// arrange
ProductFilter filter = new ProductFilter();
IList<Product> products = BuildProducts();
// act
var result = filter.By(products, new FilterSpecificationColor(ProductColor.Blue));
// assert
Assert.That(result.Count(), Is.EqualTo(2));
Assert.That(result, Has.All.Matches<Product>(x => x.Color == ProductColor.Blue));
}
[Test]
public void filterBySmall_return_2()
{
// arrange
ProductFilter filter = new ProductFilter();
IList<Product> products = BuildProducts();
// act
var result = filter.By(products, new FilterSpecificationSize(ProductSize.Small));
// assert
Assert.That(result.Count(), Is.EqualTo(2));
Assert.That(result, Has.All.Matches<Product>(x => x.Size == ProductSize.Small));
}
[Test]
public void filterByBlueAndSmall_return_1()
{
// arrange
ProductFilter filter = new ProductFilter();
IList<Product> products = BuildProducts();
// act
var result = filter.By(products, new FilterSpecificationColorAndSize(ProductColor.Blue, ProductSize.Small));
// assert
Assert.That(result.Count(), Is.EqualTo(1));
Assert.That(result, Has.All.Matches<Product>(x => x.Size == ProductSize.Small));
}
private IList<Product> BuildProducts()
{
return new List<Product> {
new Product(ProductColor.Blue, ProductSize.Small),
new Product(ProductColor.Yellow, ProductSize.Small),
new Product(ProductColor.Yellow, ProductSize.Medium),
new Product(ProductColor.Red, ProductSize.Large),
new Product(ProductColor.Blue, ProductSize.ReallyBig)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment