Skip to content

Instantly share code, notes, and snippets.

View SzymonPobiega's full-sized avatar
🏠
Working from home

Szymon Pobiega SzymonPobiega

🏠
Working from home
View GitHub Profile
@SzymonPobiega
SzymonPobiega / gist:1027094
Created June 15, 2011 13:31
Small internal DSL in unit tests
[TestMethod]
public void It_uses_more_specific_rule_if_rule_and_information_is_present()
{
Given(new ProductType("air", null, ProductCategory.AirOnly),
new ProductType("air", "someSpecialWeirdProduct", ProductCategory.LandOnly))
.ItMaps(new ProductReference("air", "someSpecialWeirdProduct"))
.To(ProductCategory.LandOnly);
}
@SzymonPobiega
SzymonPobiega / gist:953302
Created May 3, 2011 13:10
Monads in action
protected override ValidationResults OnValidate(PurchaseTransaction purchaseTransaction)
{
return purchaseTransaction
.With(ValidationCheck)
.Unless(IsValidateServiceDown)
.Try(SendMessageToTransecure)
.InCaseOfException(MarkServiceAsDown)
.Return(TheResult, OrFailureCodeInCaseOfFailure);
}
[Test]
public void NHibernate_allows_crud_operations()
{
Create();
Read();
Update();
Delete();
}
private void Create()
//Customer is an aggregate root
public class Customer : AggregateRootMappedByConvention
{
//Customer contains orders, each of which is uniquely identified hence is an entity
private readonly List<Order> _orders = new List<Order>();
public void CreateOrder(int id)
{
//Does not create an entity, only publishes event.
//The entity has localy unique id. Its uniqueness is ensured here.