Example #1
0
 public ExtendedCosmosDbQueryModelRepository(CosmosDbQueryModelRepository repo)
 {
     if (repo == null)
     {
         throw new ArgumentNullException(nameof(repo));
     }
     _repo = repo;
 }
        public void SetUp()
        {
            // ARRANGE
            var repository = new CosmosDbQueryModelRepository(_database, _collection, _offerThroughput, _noOfPartitions, _endpoint, _authKey);

            // ACT
            repository.Initialize();

            // ASSERT
        }
        public void ShouldBeStableInParallelUpdateDataQueryModel()
        {
            var repository = new CosmosDbQueryModelRepository(_database, _collection, _offerThroughput, _noOfPartitions, _endpoint, _authKey);

            Parallel.For(0, 50, (index) =>
            {
                RunDataQueryModel(repository, index).Wait();
            });
            // ASSERT
            Assert.IsTrue(true);
        }
Example #4
0
        public void Initialize()
        {
            // Configuration Parameters
            var eventDatabaseConnectionString = "Data Source=localhost;Initial Catalog=eventway;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            var projectionMetadataDatabaseConnectionString = eventDatabaseConnectionString;

            var cosmosDbEndpoint     = "https://localhost:8081"; // This is the default endpoint for local emulator-instances of the Cosmos DB
            var cosmosDbAuthKey      = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
            var cosmosDbDatabaseId   = "eventway";
            var cosmosDbCollectionId = "projections";
            var offerThroughput      = 10000;
            var noOfPartitions       = 1000;

            // Event Repository
            var eventRepository = new SqlServerEventRepository(eventDatabaseConnectionString);

            // Projection Metadata Repository
            var projectionMetadataRepository = new SqlServerProjectionMetadataRepository(projectionMetadataDatabaseConnectionString);

            // Query Model Repository
            var queryModelRepository = new CosmosDbQueryModelRepository(cosmosDbDatabaseId, cosmosDbCollectionId,
                                                                        offerThroughput, noOfPartitions, cosmosDbEndpoint, cosmosDbAuthKey);

            queryModelRepository.Initialize();

            // Event Listener
            var eventListener = new BasicEventListener();

            // Aggregate services
            var aggregateFactory    = new DefaultAggregateFactory();
            var aggregateRepository = new AggregateRepository(eventRepository, aggregateFactory);
            var aggregateStore      = new AggregateStore(aggregateRepository, eventListener);

            // PROJECTIONS
            UserProjection = new UserProjection(
                eventRepository,
                eventListener,
                queryModelRepository,
                projectionMetadataRepository);

            // APPLICATION SERVICES
            UserApplicationService = new UserApplicationService(
                aggregateStore,
                queryModelRepository);

            // Start listening for events
            UserProjection.Listen();
        }
        private async Task RunDataQueryModel(CosmosDbQueryModelRepository repository, int index)
        {
            try
            {
                //var queryModelId = Guid.NewGuid();
                //var testQueryModel = new TestQueryModel(queryModelId, "Hello Integration Test!" + index);
                var testQueryModel = _fixture.Create <TestQueryModel>();
                var queryModelId   = testQueryModel.id;

                await repository.Save(testQueryModel);

                var hydratedQueryModel = await repository.GetById <TestQueryModel>(queryModelId);

                var existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

                if (!existing)
                {
                    throw new Exception("DoesItemExist");
                }
                var hydratedQueryModel1 = await repository.QueryItem <TestQueryModel>(x => x.id == queryModelId);

                Assert.IsTrue(existing);
                Assert.IsNotNull(hydratedQueryModel);
                Assert.AreEqual(queryModelId, hydratedQueryModel.id);
                Assert.AreEqual(queryModelId, hydratedQueryModel1.id);

                hydratedQueryModel.DummyPayload = "DummyPayload" + queryModelId;

                await repository.Save(hydratedQueryModel);

                await repository.DeleteById <TestQueryModel>(queryModelId);

                existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

                if (existing)
                {
                    throw new Exception("DoesItemExist");
                }
            }
            catch (TaskCanceledException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        public async Task ShouldSuccesfullyCreateAndHydrateQueryModel()
        {
            // ARRANGE
            var repository = new CosmosDbQueryModelRepository(_database, _collection, _offerThroughput, _noOfPartitions, _endpoint, _authKey);

            var queryModelId   = Guid.NewGuid();
            var testQueryModel = new TestQueryModel(queryModelId, "Hello Integration Test!");

            // ACT
            await repository.Save(testQueryModel);

            var hydratedQueryModel = await repository.GetById <TestQueryModel>(queryModelId);

            var existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

            // ASSERT
            Assert.IsTrue(existing);
            Assert.IsNotNull(hydratedQueryModel);
            Assert.AreEqual(queryModelId, hydratedQueryModel.id);
            Assert.AreEqual("Hello Integration Test!", testQueryModel.DummyPayload);
            Assert.AreEqual(testQueryModel.DummyPayload, hydratedQueryModel.DummyPayload);
        }