public void ApplyHistory_NullCollection_ShouldThrowException()
        {
            // Arrange
            EventAggregate eventAggregate = new FakeEventAggregate();

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => eventAggregate.ApplyHistory(null));
        }
        public void ApplyHistory_WithNullObject_ShouldThrowException()
        {
            // Arrange
            IEnumerable <EventWithGuidKey> historyEvents = new EventWithGuidKey[] { null };
            EventAggregate eventAggregate = new FakeEventAggregate();

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => eventAggregate.ApplyHistory(historyEvents));
        }
        public void ApplyHistory_WithNotSupportedEventType_ShouldThrowException()
        {
            // Arrange
            EventWithGuidKey deletedEvent = new FakeDeletedEvent(Guid.NewGuid(), 1);
            IEnumerable <EventWithGuidKey> historyEvents = new[] { deletedEvent };
            EventAggregate eventAggregate = new FakeEventAggregate();

            // Act, Assert
            Assert.Throws <NotSupportedException>(() => eventAggregate.ApplyHistory(historyEvents));
        }
        public void MarkAsCommitted_OnCreatedAggregate_ShouldNotContainUncommitted()
        {
            // Arrange
            EventAggregate eventAggregate = new FakeEventAggregate(Guid.NewGuid());

            // Act
            eventAggregate.MarkAsCommitted();
            IEnumerable <Event <Guid> > uncommitted = eventAggregate.GetUncommitted();

            // Assert
            Assert.Empty(uncommitted);
        }
        public void GetUncommitted_OnCreatedAggregate_ShouldReturnCollection()
        {
            // Arrange
            EventAggregate eventAggregate = new FakeEventAggregate(Guid.NewGuid());

            // Act
            IEnumerable <Event <Guid> > result = eventAggregate.GetUncommitted();

            // Assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
Esempio n. 6
0
        public async void GetById_OnEmptyRepository_ShouldReturnNull()
        {
            // Arrange
            Mock <IEventStore <Guid, Event <Guid> > >          eventStoreMock = CreateEventStoreMock();
            IEventStore <Guid, Event <Guid> >                  eventStore     = eventStoreMock.Object;
            IEventSourcedRepository <FakeEventAggregate, Guid> repository     =
                new MemoryEventAggregateRepository <FakeEventAggregate>(eventStore);

            // Act
            FakeEventAggregate result = await repository.FindByIdAsync(Guid.NewGuid());

            // Assert
            Assert.Null(result);
        }
Esempio n. 7
0
        public async void GetById_WithExistingid_ShouldReturnNotNull()
        {
            // Arrange
            Guid eventAggregateId = Guid.NewGuid();
            Mock <IEventStore <Guid, Event <Guid> > >          eventStoreMock = CreateEventStoreMock(eventAggregateId);
            IEventStore <Guid, Event <Guid> >                  eventStore     = eventStoreMock.Object;
            IEventSourcedRepository <FakeEventAggregate, Guid> repository     =
                new MemoryEventAggregateRepository <FakeEventAggregate>(eventStore);

            // Act
            FakeEventAggregate result = await repository.FindByIdAsync(eventAggregateId);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(eventAggregateId, result.EntityId);
        }
Esempio n. 8
0
        public async void Add_FakeObject_ShouldBeSaved()
        {
            // Arrange
            Mock <IEventStore <Guid, Event <Guid> > > eventStoreMock = CreateEventStoreMock();
            IEventStore <Guid, Event <Guid> >         eventStore     = eventStoreMock.Object;
            FakeEventAggregate fakeEventAggregate = CreateDirtyFake(Guid.NewGuid());
            IEventSourcedRepository <FakeEventAggregate, Guid> repository =
                new MemoryEventAggregateRepository <FakeEventAggregate>(eventStore);

            // Act
            bool result = await repository.SaveAsync(fakeEventAggregate);

            // Assert
            Assert.True(result);
            eventStoreMock.Verify(m => m.SaveEvents(It.IsAny <Guid>(), It.IsAny <IReadOnlyCollection <Event <Guid> > >()), Times.Once);
        }
        public void ApplyHistory_WithNotEmptyEventHistory_ShouldApplyChanges()
        {
            // Arrange
            Guid             eventAggregateId            = Guid.NewGuid();
            EventWithGuidKey createdEvent                = new FakeCreatedEvent(eventAggregateId, 1);
            IEnumerable <EventWithGuidKey> historyEvents = new [] { createdEvent };
            EventAggregate eventAggregate                = new FakeEventAggregate();

            // Act
            Guid beforeChangesId = eventAggregate.EntityId;

            eventAggregate.ApplyHistory(historyEvents);

            // Assert
            Assert.NotEqual(eventAggregateId, beforeChangesId);
            Assert.Equal(eventAggregateId, eventAggregate.EntityId);
        }