예제 #1
0
        public async Task LoadWithNull(PersistenceLayerProvider layerProvider)
        {
            var versionRepository = layerProvider.VersionRepository;
            var count             = await versionRepository.GetVersionAsync(null);

            Assert.AreEqual(0, count);
        }
예제 #2
0
        public async Task SnapshotExactlyOnSnapShotTime_DoesNotReturnNotFoundBug(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <Event1>();
            BsonMapRegistrationHelpers.AddBsonMapFor <Event2>();

            var eventStore = new EventStore(layerProvider.EventRepository, layerProvider.SnapShotRepository, new
                                            SnapShotConfig(new List <ISnapShot> {
                new SnapShot <User>(1)
            }));

            var entityId = Guid.NewGuid();
            await eventStore.AppendAsync(new List <IDomainEvent>
            {
                new Event1(entityId),
                new Event2(entityId, "Peter"),
                new Event2(entityId, "Peterneu")
            }, 0);

            await eventStore.LoadAsync <User>(entityId.ToString());

            var result = await eventStore.LoadAsync <User>(entityId.ToString());

            Assert.AreEqual("Peterneu", result.Value.Name);
            Assert.AreEqual(3, result.Version);
        }
예제 #3
0
        public async Task AddAndLoadEventsConcurrent(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid = Guid.NewGuid();
            var events  = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid)
            };
            var events2 = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid)
            };

            var t1 = eventRepository.AppendAsync(events, 0);
            var t2 = eventRepository.AppendAsync(events2, 0);

            var allResults = await Task.WhenAll(t1, t2);

            var concurrencyException        = Assert.ThrowsException <ConcurrencyViolatedException>(() => CheckAllResults(allResults));
            var concurrencyExceptionMessage = concurrencyException.Message;

            Assert.AreEqual("Concurrency violation detected, could not update database. ExpectedVersion: 0, ActualVersion: 2", concurrencyExceptionMessage);

            var loadEvents = await eventRepository.LoadEvents();

            Assert.AreEqual(2, loadEvents.Value.Count());
        }
        public async Task StatusLoadAndSafe_HappyPath(PersistenceLayerProvider layerProvider)
        {
            var statusRepository = layerProvider.StatusRepository;

            List <EventsPublishedByService> services = new List <EventsPublishedByService> {
                EventsPublishedByService.Reachable(new ServiceEndPoint(new Uri("http://service1.de"), "Name1"), new []
                {
                    new EventSchema("Event1"),
                    new EventSchema("Event2"),
                    new EventSchema("Event3")
                })
            };
            var subscribedEventCollection = new EventsSubscribedByService(
                new []
            {
                new EventSchema("Event1"),
                new EventSchema("Event2")
            },
                new [] { new ReadModelSubscription("Rm1", new EventSchema("Event3")) });
            var eventLocation = new EventLocation(services, subscribedEventCollection);

            await statusRepository.SaveEventLocation(eventLocation);

            var location = await statusRepository.GetEventLocation();

            var microwaveServiceNodes = location.Services.ToList();

            Assert.IsNotNull(microwaveServiceNodes);
            Assert.AreEqual(1, microwaveServiceNodes.Count);
            Assert.AreEqual(2, microwaveServiceNodes[0].SubscribedEvents.Count());
            Assert.AreEqual(1, microwaveServiceNodes[0].ReadModels.Count());
            Assert.IsTrue(!location.UnresolvedEventSubscriptions.Any());
            Assert.IsTrue(!location.UnresolvedReadModeSubscriptions.Any());
        }
예제 #5
0
        public async Task AddAndLoadEventsConcurrent_MultipleEntitiies_GlobalWorks(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid  = Guid.NewGuid();
            var newGuid2 = Guid.NewGuid();
            var events   = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid)
            };
            var events2 = new List <IDomainEvent> {
                new TestEvent1(newGuid2), new TestEvent2(newGuid2)
            };

            await eventRepository.AppendAsync(events, 0);

            await eventRepository.AppendAsync(events2, 0);

            var res = await eventRepository.LoadEvents();

            Assert.IsTrue(res.Is <Ok>());
            var domainEventWrappers = res.Value.ToList();

            Assert.AreEqual(1, domainEventWrappers[0].OverallVersion);
            Assert.AreEqual(2, domainEventWrappers[1].OverallVersion);
            Assert.AreEqual(3, domainEventWrappers[2].OverallVersion);
            Assert.AreEqual(4, domainEventWrappers[3].OverallVersion);
        }
예제 #6
0
        public async Task AddAndLoadEventsConcurrent_AfterNormalAdd(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid = Guid.NewGuid();
            var events  = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid)
            };
            var events2 = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid)
            };

            await eventRepository.AppendAsync(events, 0);

            var t1 = eventRepository.AppendAsync(events, 2);
            var t2 = eventRepository.AppendAsync(events2, 2);

            var allResults = await Task.WhenAll(t1, t2);

            Assert.ThrowsException <ConcurrencyViolatedException>(() => CheckAllResults(allResults));

            var loadEvents = await eventRepository.LoadEvents();

            Assert.AreEqual(4, loadEvents.Value.Count());
        }
예제 #7
0
        public async Task AddAndLoadEvents_OrderIsCorrect(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent1>();
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent2>();
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent3>();

            var eventRepository = layerProvider.EventRepository;

            var newGuid = Guid.NewGuid();
            var events  = new List <IDomainEvent> {
                new TestEvent1(newGuid)
            };
            var events2 = new List <IDomainEvent> {
                new TestEvent2(newGuid), new TestEvent3(newGuid, "TestName")
            };
            var res = await eventRepository.AppendAsync(events, 0);

            var res2 = await eventRepository.AppendAsync(events2, 1);

            res.Check();
            res2.Check();

            var loadEventsByEntity = await eventRepository.LoadEventsByEntity(newGuid.ToString());

            Assert.AreEqual(3, loadEventsByEntity.Value.Count());
            Assert.AreEqual(1, loadEventsByEntity.Value.ToList()[0].EntityStreamVersion);
            Assert.AreEqual(2, loadEventsByEntity.Value.ToList()[1].EntityStreamVersion);
            Assert.AreEqual(3, loadEventsByEntity.Value.ToList()[2].EntityStreamVersion);
        }
예제 #8
0
        public async Task AddMultipleEvents_GlobalVersionIsUpdatedCorrectly(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid       = Guid.NewGuid();
            var domainEvents  = new List <IDomainEvent>();
            var domainEvents2 = new List <IDomainEvent>();

            for (int i = 0; i < 100; i++)
            {
                domainEvents.Add(new TestEvent1(newGuid));
                domainEvents2.Add(new TestEvent2(newGuid));
            }


            await eventRepository.AppendAsync(domainEvents, 0);

            await eventRepository.AppendAsync(domainEvents, 100);

            var result = await eventRepository.LoadEvents();

            var dateTimeOffset = result.Value.Skip(78).First().OverallVersion;

            Assert.AreEqual(200, result.Value.Count());

            for (int i = 0; i < 10; i++)
            {
                var result2 = await eventRepository.LoadEvents(dateTimeOffset);

                Assert.AreEqual(121, result2.Value.Count());
            }
        }
예제 #9
0
        public async Task LoadDomainEvents_IdAndStuffIsSetCorreclty(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent1>();
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent2>();

            var eventRepository = layerProvider.EventRepository;

            var newGuid    = Guid.NewGuid();
            var testEvent1 = new TestEvent1(newGuid);
            var testEvent2 = new TestEvent2(newGuid);
            var events     = new List <IDomainEvent> {
                testEvent1, testEvent2
            };

            var res = await eventRepository.AppendAsync(events, 0);

            res.Check();

            var loadEventsByEntity = await eventRepository.LoadEventsByEntity(newGuid.ToString());

            Assert.AreEqual(2, loadEventsByEntity.Value.Count());
            Assert.AreEqual(1, loadEventsByEntity.Value.ToList()[0].OverallVersion);
            Assert.AreEqual(2, loadEventsByEntity.Value.ToList()[1].OverallVersion);
            Assert.AreEqual(1, loadEventsByEntity.Value.ToList()[0].EntityStreamVersion);
            Assert.AreEqual(2, loadEventsByEntity.Value.ToList()[1].EntityStreamVersion);
            Assert.IsTrue(newGuid.ToString() == loadEventsByEntity.Value.ToList()[0].DomainEvent.EntityId);
        }
        public async Task StatusLoadAndSafe_OneUnresolvedReadModel(PersistenceLayerProvider layerProvider)
        {
            var statusRepository = layerProvider.StatusRepository;

            List <EventsPublishedByService> services = new List <EventsPublishedByService> {
                EventsPublishedByService.Reachable(new ServiceEndPoint(new Uri("http://service1.de"), "Name1"), new []
                {
                    new EventSchema("Event1"),
                    new EventSchema("Event2")
                })
            };
            var subscribedEventCollection = new EventsSubscribedByService(
                new []
            {
                new EventSchema("Event1"),
                new EventSchema("Event2")
            },
                new [] { new ReadModelSubscription("Rm1", new EventSchema("Event3")) });
            var eventLocation = new EventLocation(services, subscribedEventCollection);

            await statusRepository.SaveEventLocation(eventLocation);

            await statusRepository.SaveEventLocation(eventLocation);

            var location = await statusRepository.GetEventLocation();

            Assert.AreEqual("Rm1", location.UnresolvedReadModeSubscriptions.Single().ReadModelName);
            Assert.AreEqual("Event3", location.UnresolvedReadModeSubscriptions.Single().GetsCreatedOn.Name);
            Assert.IsTrue(!location.UnresolvedEventSubscriptions.Any());
        }
예제 #11
0
        public async Task AddEmptyEventList(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var appendAsync = await eventRepository.AppendAsync(new List <IDomainEvent>(), 0);

            appendAsync.Check();
        }
예제 #12
0
        public async Task LoadWithNull(PersistenceLayerProvider layerProvider)
        {
            var repo           = layerProvider.SnapShotRepository;
            var snapShotResult = await repo.LoadSnapShot <UserSnapshotWithoutPrivateSetters>(null);

            Assert.IsTrue(snapShotResult.Is <NotFound>());
            Assert.ThrowsException <NotFoundException>(() => snapShotResult.Value);
        }
예제 #13
0
        public async Task LoadType_EmptyListWhenNoEventsPresentButAreBeingPublished(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var result = await eventRepository.LoadEventsByTypeAsync("TypeNotInsertedButSubscribed");

            Assert.AreEqual(0, result.Value.Count());
        }
        public async Task StatusLoadAndSafe_NoSaveBeforeGet(PersistenceLayerProvider layerProvider)
        {
            var statusRepository = layerProvider.StatusRepository;

            var location = await statusRepository.GetEventLocation();

            Assert.IsNotNull(location);
        }
예제 #15
0
        public async Task LoadWithNullId(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;
            var querry1         = await queryRepository.LoadAsync <TestReadModel>(null);

            Assert.IsTrue(querry1.Is <NotFound>());
            Assert.ThrowsException <NotFoundException>(() => querry1.Value);
        }
예제 #16
0
        public async Task LoadWithNulls(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var loadEventsByEntity = await eventRepository.LoadEventsByEntity(null);

            Assert.IsTrue(loadEventsByEntity.Is <NotFound>());
            Assert.ThrowsException <NotFoundException>(() => loadEventsByEntity.Value);
        }
예제 #17
0
        public async Task ReadModelNotFoundEceptionHasCorrectT(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;
            var guid2           = Guid.NewGuid();
            var result          = await queryRepository.LoadAsync <TestReadModel>(guid2.ToString());

            var notFoundException = Assert.ThrowsException <NotFoundException>(() => result.Value);

            Assert.IsTrue(notFoundException.Message.StartsWith("Could not find TestReadModel"));
        }
예제 #18
0
        public async Task LoadEntityId_NotFoundTIsCorrect(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var entityId = Guid.NewGuid();
            var result   = await eventRepository.LoadEventsByEntity(entityId.ToString());

            var notFoundException = Assert.ThrowsException <NotFoundException>(() => result.Value);

            Assert.AreEqual($"Could not find DomainEvents with ID {entityId}", notFoundException.Message);
        }
예제 #19
0
        public async Task UpdateQuery(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;
            await queryRepository.SaveQueryAsync(new TestQuerry { UserName = "******" });

            await queryRepository.SaveQueryAsync(new TestQuerry { UserName = "******" });

            var query = (await queryRepository.LoadAsync <TestQuerry>()).Value;

            Assert.AreEqual("NewName", query.UserName);
        }
예제 #20
0
        public async Task SnapshotGetSavedAfterThirdEvent(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <Event1>();
            BsonMapRegistrationHelpers.AddBsonMapFor <Event2>();
            BsonMapRegistrationHelpers.AddBsonMapFor <Event3>();

            var snapShotRepository = layerProvider.SnapShotRepository;
            var eventStore         = new EventStore(layerProvider.EventRepository, snapShotRepository
                                                    , new SnapShotConfig(new
                                                                         List <ISnapShot> {
                new SnapShot <User>(3)
            }));

            var entityId = Guid.NewGuid();
            await eventStore.AppendAsync(new List <IDomainEvent>
            {
                new Event1(entityId),
                new Event2(entityId, "Peter")
            }, 0);

            await eventStore.LoadAsync <User>(entityId.ToString());

            var snapShotDboOld = await snapShotRepository.LoadSnapShot <User>(entityId.ToString());

            Assert.IsNull(snapShotDboOld.Value.Id);
            Assert.IsNull(snapShotDboOld.Value.Name);

            await eventStore.AppendAsync(new List <IDomainEvent>
            {
                new Event3(entityId, 14),
                new Event2(entityId, "PeterNeu")
            }, 2);

            var eventstoreResult = await eventStore.LoadAsync <User>(entityId.ToString());

            var user = eventstoreResult;

            Assert.AreEqual(4, eventstoreResult.Version);
            Assert.AreEqual(14, user.Value.Age);
            Assert.AreEqual("PeterNeu", user.Value.Name);
            Assert.AreEqual(entityId.ToString(), user.Value.Id);

            var snapShotDbo = await snapShotRepository.LoadSnapShot <User>(entityId.ToString());

            Assert.AreEqual(4, snapShotDbo.Version);
            Assert.AreEqual(entityId.ToString(), snapShotDbo.Value.Id);
            var userSnapShot = snapShotDbo.Value;

            Assert.AreEqual(14, userSnapShot.Age);
            Assert.AreEqual("PeterNeu", userSnapShot.Name);
            Assert.AreEqual(entityId.ToString(), userSnapShot.Id);
        }
예제 #21
0
        public async Task AddEvents_VersionWayTooHigh(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid = Guid.NewGuid();
            var events  = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid), new TestEvent1(newGuid), new TestEvent2(newGuid)
            };

            var result = await eventRepository.AppendAsync(events, 5);

            Assert.IsTrue(result.Is <ConcurrencyError>());
        }
예제 #22
0
        public async Task VersionRepo_DuplicateUpdate(PersistenceLayerProvider layerProvider)
        {
            var versionRepository = layerProvider.VersionRepository;

            var dateTimeOffset = 0;
            await versionRepository.SaveVersion(new LastProcessedVersion("Type", dateTimeOffset));

            await versionRepository.SaveVersion(new LastProcessedVersion("Type", dateTimeOffset));

            var count = await versionRepository.GetVersionAsync("Type");

            Assert.AreEqual(dateTimeOffset, count);
        }
예제 #23
0
        public async Task TestDeserializationOfIdInInterface_GetAutoProperty(PersistenceLayerProvider layerProvider)
        {
            var entityStreamRepository = layerProvider.EventRepository;

            var domainEvent = new TestEv_AutoProperty(Guid.NewGuid());
            await entityStreamRepository.AppendAsync(new List <IDomainEvent> {
                domainEvent
            }, 0);

            var deserialize = (await entityStreamRepository.LoadEvents()).Value.Single().DomainEvent;

            Assert.AreEqual(deserialize.EntityId, new Guid("84e5447a-0a28-4fe1-af5a-11dd6a43d3dd").ToString());
            Assert.AreNotEqual(deserialize.EntityId, Guid.Empty);
        }
예제 #24
0
        public async Task LoadEventsByTypeAsync(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var newGuid = Guid.NewGuid();
            var events  = new List <IDomainEvent> {
                new TestEvent1(newGuid), new TestEvent2(newGuid), new TestEvent2(newGuid)
            };

            await eventRepository.AppendAsync(events, 0);

            var eventsLoaded = await eventRepository.LoadEventsByTypeAsync(typeof(TestEvent2).Name);

            Assert.AreEqual(2, eventsLoaded.Value.Count());
        }
예제 #25
0
        public async Task LoadType_VersionTooHIgh_NotFoundIsOk(PersistenceLayerProvider layerProvider)
        {
            var eventRepository = layerProvider.EventRepository;

            var entityId = new Guid();
            var events   = new List <IDomainEvent> {
                new TestEvent1(entityId), new TestEvent2(entityId)
            };
            await eventRepository.AppendAsync(events, 0);

            var result = await eventRepository.LoadEventsByTypeAsync(nameof(TestEvent1), 1000);

            Assert.IsTrue(result.Is <Ok>());
            Assert.AreEqual(0, result.Value.Count());
        }
예제 #26
0
        public async Task TestDeserializationOfIdInInterface(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEv2>();
            var entityStreamRepository = layerProvider.EventRepository;

            var domainEvent = new TestEv2(Guid.NewGuid());
            await entityStreamRepository.AppendAsync(new List <IDomainEvent> {
                domainEvent
            }, 0);

            var deserialize = (await entityStreamRepository.LoadEvents()).Value.Single().DomainEvent;

            Assert.AreEqual(deserialize.EntityId, domainEvent.EntityId);
            Assert.AreNotEqual(deserialize.EntityId, Guid.Empty.ToString());
        }
예제 #27
0
        public async Task AddEvents_IdSet(PersistenceLayerProvider layerProvider)
        {
            BsonMapRegistrationHelpers.AddBsonMapFor <TestEvent1>();

            var eventRepository = layerProvider.EventRepository;

            var testEvent1 = new TestEvent1(Guid.NewGuid());
            await eventRepository.AppendAsync(new[] { testEvent1 }, 0);

            var result = await eventRepository.LoadEventsByEntity(testEvent1.EntityId);

            var domainEvent = result.Value.Single().DomainEvent;

            Assert.IsTrue(domainEvent.EntityId.Equals(testEvent1.EntityId));
        }
예제 #28
0
        public async Task InsertQuery_ConcurrencyProblem(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;
            var testQuery       = new TestQuerry {
                UserName = "******"
            };
            var testQuery2 = new TestQuerry {
                UserName = "******"
            };
            var save  = queryRepository.SaveQueryAsync(testQuery);
            var save2 = queryRepository.SaveQueryAsync(testQuery2);

            await Task.WhenAll(new List <Task> {
                save, save2
            });
        }
예제 #29
0
        public async Task LoadTwoTypesOfReadModels_Bug(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;
            var guid2           = Guid.NewGuid();
            var testQuery2      = new TestReadModel2 {
                Identity = guid2.ToString()
            };

            testQuery2.SetVars("Test2", new [] { "Jeah", "jeah2" });

            await queryRepository.SaveReadModelAsync(testQuery2);

            var loadAll2 = await queryRepository.LoadAsync <TestReadModel>(guid2.ToString());

            Assert.IsTrue(loadAll2.Is <NotFound>());
        }
예제 #30
0
        public async Task IdentifiableQuerySaveAndLoad(PersistenceLayerProvider layerProvider)
        {
            var queryRepository = layerProvider.ReadModelRepository;

            var guid       = Guid.NewGuid();
            var testQuerry = new TestReadModel {
                Identity = guid.ToString()
            };

            testQuerry.SetVars("Test", new[] { "Jeah", "jeah2" });
            await queryRepository.SaveReadModelAsync(testQuerry);

            var querry1 = await queryRepository.LoadAsync <TestReadModel>(guid);

            Assert.AreEqual(guid.ToString(), querry1.Value.Identity);
            Assert.AreEqual("Test", querry1.Value.UserName);
            Assert.AreEqual("Jeah", querry1.Value.Strings.First());
        }