Created
July 4, 2011 21:33
-
-
Save gregoryyoung/1063971 to your computer and use it in GitHub Desktop.
query specification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A query specification is intended to be used on a method with a return value. The | |
* general idea is that the Given() will build the SUT. The when() will call the method | |
* returning the methods return value. The expectations are then on the returned value. | |
* | |
* You may wonder how you can assert on the sut after the call. You can't using this | |
* template. This is by design, see CQS by Bertrand Meyer, you should not mutate state | |
* of the object when querying. If you want to break this rule use a more open template | |
* and specialize it. | |
*/ | |
public class QuerySepcification | |
{ | |
public ISpecification it_returns_something_interesting = new QuerySpecification<QueryExample, Product>() | |
{ | |
On = () => new QueryExample(), | |
When = obj => obj.GetProduct(14), | |
Expect = | |
{ | |
product => product.Id == 14, | |
product => product.Code == "TEST", | |
product => product.Description == "test description" | |
}, | |
}; | |
} | |
public class QueryExample | |
{ | |
public Product GetProduct(int id) | |
{ | |
return new Product(id, "TEST", "test description"); | |
} | |
} | |
public class Product | |
{ | |
public readonly int Id; | |
public readonly string Code; | |
public readonly string Description; | |
public Product(int id, string code, string description) | |
{ | |
Id = id; | |
Description = description; | |
Code = code; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment