Skip to content

Instantly share code, notes, and snippets.

View Finglas's full-sized avatar

Shaun Finglas Finglas

  • UK
View GitHub Profile
@Finglas
Finglas / quiz.feature
Created October 25, 2012 22:17 — forked from icodeecono/quiz.feature
Minisculus Challenge REST API
Feature: a quiz
Background:
Given the quiz is configured with the questions:
"""
[
{"key": "foo", "question": "1+1", "answer": "2", "reference-url": "questions/foo.html"},
{"key": "bar", "question": "1x3", "answer": "3", "reference-url": "questions/bar.html"}
]
"""
@Finglas
Finglas / DDD-Validation.py
Created September 22, 2014 23:38
Example of DDD validation using services
# Only validation that should happen per load.
def person_loading_validator(person):
if len(person.name) < 1:
raise Exception("One or more characters required.")
# Only validation that should happen on every save.
def person_saving_validator(person):
if len(person.name) < 1:
raise Exception("One or more characters required.")
@Finglas
Finglas / IOC-newing-example.cs
Created November 2, 2014 20:53
Example of IOC without a container
new House(
new Kitchen(
new Fridge(
new Beer(),
new Pizza()
)
),
new Lounge(
new Sofa()
),
@Finglas
Finglas / IOC-newing-example-modules.cs
Last active August 29, 2015 14:08
Example of IOC without a container using modules
new House(
KitchenModule().Resolve(),
new Lounge(
new Sofa()
),
new Hallway(),
new Bedroom()
new Garden()
);
@Finglas
Finglas / customeraggregatev1.cs
Last active August 29, 2015 14:09
CustomerAggregrate with hand rolled validation
public class Customer
{
public void PlaceOrder(Order order)
{
if (order.Cancelled || order.IsReplacement)
{
// Do stuff...
}
// Snip
@Finglas
Finglas / customeraggregatev2.cs
Last active August 29, 2015 14:10
CustomerAggregate with Validator
public class Customer
{
private class OrderStatusFlag
{
// Snip
}
public void PlaceOrder(Order order)
{
var validator = new Validator();
@Finglas
Finglas / executewithoutfactory.cs
Created December 9, 2014 13:31
Example of a value type being saved without a factory
public void Execute(string input)
{
// Snip...
messageRepository.Save(new Message(input));
}
@Finglas
Finglas / executewithafactory.cs
Created December 9, 2014 13:33
Example of a value type being saved with a factory
public void Execute(string input)
{
// Snip...
messageRepository.Save(messageFactory.Create(input));
}
@Finglas
Finglas / testsusingfactory.cs
Last active August 29, 2015 14:11
Example of the test fixture for the code with a factory
[TestFixture]
public class ConsumerTests
{
[Test]
public void Test()
{
// Arrange
var messageFactory = new Mock<IMessageFactory>();
var message = new Message("Hello, World");
messageFactory.Setup(x => x.Create()).Returns(message);
@Finglas
Finglas / testingwithoutfactory.cs
Created December 13, 2014 17:55
Test without the need for a factory
[TestFixture]
public class ConsumerWithoutFactoryTests
{
[Test]
public void Test()
{
// Arrange
var messageRepository = new Mock<IMessageRepository>();
var subject = new ConsumerWithoutFactory(messageRepository.Object);