public void CanApplyMishandledChangeToAggregateWithoutEffectOrException() { // arrange var aggregate = new ChangeableAggregate(); var @event = new SomethingElseHappened(); // act aggregate.ApplyEvent(@event); // assert aggregate.Change.Should().BeNull(); }
public void MissingEventRouteThrowsException() { // Setup the event router. var builder = new ApplyEventRouterBuilder <MyAggregateRoot, IEvent>(); builder.Add <SomethingHappened>((agg, e) => agg.ApplyEvent(e)); var router = builder.Build(); // Set up the initial state. var initialState = new MyAggregateRoot(); // Create some events to apply to the aggregate. var event1 = new SomethingHappened("Foo"); var event2 = new SomethingElseHappened("Bar"); // Route the events. var exception = Assert.Throws <InvalidOperationException>(() => router.Route(initialState, event1, event2)); const string expectedMessage = "No route or default route found when attempting to apply " + "SomethingElseHappened to MyAggregateRoot"; Assert.That(exception.Message, Is.EqualTo(expectedMessage)); }
public void EventIsRoutedAndApplied() { // Setup the event router. var builder = new ApplyEventRouterBuilder <MyAggregateRoot, IEvent>(); builder.Add <SomethingHappened>((agg, e) => agg.ApplyEvent(e)); builder.Add <SomethingElseHappened>((agg, e) => agg.ApplyEvent(e)); var router = builder.Build(); // Set up the initial state. var initialState = new MyAggregateRoot(); // Create some events to apply to the aggregate. var event1 = new SomethingHappened("Foo"); var event2 = new SomethingElseHappened("Bar"); // Route the events. var newState = router.Route(initialState, event1, event2); Assert.That(newState.State, Is.EqualTo("Foo")); Assert.That(newState.OtherState, Is.EqualTo("Bar")); }
public void DefaultEventRouteIsInvokedWhenSpecified() { // Setup the event router. var builder = new ApplyEventRouterBuilder <MyAggregateRoot, IEvent>(); builder.Add <SomethingHappened>((agg, e) => agg.ApplyEvent(e)); builder.Add <IEvent>((agg, e) => agg.DefaultApplyEvent(e)); // Default route var router = builder.Build(); // Set up the initial state. var initialState = new MyAggregateRoot(); // Create some events to apply to the aggregate. var event1 = new SomethingHappened("Foo"); var event2 = new SomethingElseHappened("Bar"); // Route the events. var newState = router.Route(initialState, event1, event2); Assert.That(newState.State, Is.EqualTo("Foo")); // We expect SomethingElseHappened to do nothing, since the default route just returns "this". Assert.That(newState.OtherState, Is.Null); }
private void Handle(SomethingElseHappened @event, int count) { this.Change = @event; }
public void Apply(SomethingElseHappened e) { }
protected void Apply(SomethingElseHappened evt) { ApplySomethingElseHappenedCalled = true; }
public MyAggregateRoot ApplyEvent(SomethingElseHappened @event) { return(new MyAggregateRoot(State, @event.OtherState)); }