-
-
Save dcomartin/ca55b79eea0be0ccde07b5894094ba63 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Linq; | |
using Shouldly; | |
namespace EventSourcing.Demo | |
{ | |
public abstract class AggregateTests<TAggregate> where TAggregate : AggregateRoot | |
{ | |
private readonly TAggregate _aggregateRoot; | |
protected AggregateTests(TAggregate aggregateRoot) | |
{ | |
_aggregateRoot = aggregateRoot; | |
} | |
protected void Given(params IEvent[] events) | |
{ | |
if (events != null) | |
{ | |
_aggregateRoot.Load(events); | |
} | |
} | |
protected void When(Action<TAggregate> command) | |
{ | |
command(_aggregateRoot); | |
} | |
protected void Then<TEvent>(params Action<TEvent>[] conditions) | |
{ | |
var events = _aggregateRoot.GetUncommittedEvents(); | |
events.Count.ShouldBe(1); | |
var evnt = events.First(); | |
evnt.ShouldBeOfType<TEvent>(); | |
if (conditions != null) | |
{ | |
((TEvent)evnt).ShouldSatisfyAllConditions(conditions); | |
} | |
} | |
protected void Throws<TException>(Action<TAggregate> command, params Action<TException>[] conditions) where TException : Exception | |
{ | |
var ex = Should.Throw<TException>(() => command(_aggregateRoot)); | |
if (conditions != null) | |
{ | |
ex.ShouldSatisfyAllConditions(conditions); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment