private static Task AfterScheduledEventOccures(TestFutureEventsAggregate aggregate, FutureEventScheduledEvent futureEventEnvelop, ScheduleEventInFutureCommand testCommand) { var producedEvent = aggregate.GetEvent <ValueChangedSuccessfullyEvent>(); aggregate.ApplyEvent(producedEvent); var futureEventOccuredEvent = aggregate.GetEvent <FutureEventOccuredEvent>(); aggregate.ApplyEvent(futureEventOccuredEvent); //Future_event_occurance_has_same_id_as_future_event() Assert.Equal(futureEventEnvelop.Id, futureEventOccuredEvent.FutureEventId); //Future_event_applies_to_aggregate() Assert.Equal(producedEvent.Value, aggregate.Value); //Future_event_envelop_has_id_different_from_aggregate() Assert.NotEqual(futureEventEnvelop.Id, aggregate.Id); //Future_event_sourceId_is_aggregate_id() Assert.Equal(futureEventEnvelop.SourceId, aggregate.Id); //Future_event_payload_is_aggregate_original_event() Assert.Equal(((ValueChangedSuccessfullyEvent)futureEventEnvelop.Event).Id, producedEvent.Id); //Future_event_contains_data_from_command() Assert.Equal(testCommand.Value, producedEvent.Value); return(Task.CompletedTask); }
public void Then_it_occures_and_applies_to_aggregate() { var aggregate = new TestFutureEventsAggregate(Guid.NewGuid().ToString()); var testValue = "value D"; aggregate.ScheduleInFuture(DateTime.Now.AddSeconds(400), testValue); var futureEventA = aggregate.GetEvent <FutureEventScheduledEvent>(); aggregate.ScheduleInFuture(DateTime.Now.AddSeconds(400), "test value E"); var futureEventOutOfCriteria = aggregate.GetEvents <FutureEventScheduledEvent>().Skip(1).First(); aggregate.CancelFutureEvents(testValue); // Cancelation_event_is_produced() var cancelEvent = aggregate.GetEvent <FutureEventCanceledEvent>(); Assert.Equal(futureEventA.Id, cancelEvent.FutureEventId); //Only_predicate_satisfying_events_are_canceled()` var cancelEvents = aggregate.GetEvents <FutureEventCanceledEvent>(); Assert.True(cancelEvents.All(e => e.FutureEventId != futureEventOutOfCriteria.Id)); // Canceled_event_cannot_be_raised() Assert.Throws <ScheduledEventNotFoundException>(() => aggregate.RaiseScheduledEvent(futureEventA.Id, Guid.NewGuid().ToString())); }
public void When_raising_future_event() { var testCommand = new ScheduleEventInFutureCommand(DateTime.Now, Guid.NewGuid().ToString(), "test value"); var aggregate = new TestFutureEventsAggregate(testCommand.AggregateId); aggregate.ScheduleInFuture(testCommand.RaiseTime, testCommand.Value); var futureEventEnvelop = aggregate.GetEvent <FutureEventScheduledEvent>(); aggregate.ApplyEvent(futureEventEnvelop); //quite ugly, but it only safe way to run some logic after scheduled event persistence aggregate.RaiseScheduledEvent(futureEventEnvelop.Id, Guid.NewGuid().ToString()); }