public void Should_invoke_event_specific_apply_methods_when_load_from_history() { //Arrange var domainEvent = new TestDomainEvent(); var sut = new TestEventSourcedAggregateRoot(); //Act sut.LoadFromHistory(new[] { domainEvent }); //Assert sut.ApplyWasCalled.Should().BeTrue(); }
public void Should_support_serialization() { //Arrange var sut = new TestEventSourcedAggregateRoot(Guid.NewGuid()); var domainEvent = new TestDomainEvent(); sut.LoadFromHistory(new[] { domainEvent }); //Act var serializedObject = JsonConvert.SerializeObject(sut); var deserializedObject = JsonConvert.DeserializeObject <TestEventSourcedAggregateRoot>(serializedObject); //Assert deserializedObject.Should().Be(sut); }
public async Task Should_save_events_in_event_store_when_aggregate_is_saved() { //Arrange //var eventStoreMock = new Mock<IEventStore>(); var eventStoreMock = new TestEventStore(); var sut = new EventSourcedRepository <TestEventSourcedAggregateRoot>(eventStoreMock, Mock.Of <ISnapshotStore>(), Mock.Of <IMediator>(), new EventSourcingOptions(), Mock.Of <ILogger <EventSourcedRepository <TestEventSourcedAggregateRoot> > >()); var domainEvent = Mock.Of <IDomainEvent>(); var domainEvents = new List <IDomainEvent> { domainEvent }; var testAggregate = new TestEventSourcedAggregateRoot(Guid.NewGuid(), 5, domainEvents); //Act await sut.SaveAsync(testAggregate, CancellationToken.None); //Assert //eventStoreMock.Verify(es => es.AppendEventsToStreamAsync(It.IsAny<string>(), It.Is<IEnumerable<IDomainEvent>>(de=> de.Single() == domainEvent), null, It.IsAny<CancellationToken>())); eventStoreMock.AppendEventsToStreamAsyncCallsCount.Should().Be(1); }