public async void TestServiceRegistrationAndUpdateConcurrency()
        {
            // This test performs a concurrency check to ensure that multiple threads can successfully interact with
            // the same config manager. The config manager is thread safe so multiple stores registering and performing
            // actions on different threads should produce a consistent result.

            var configManager = new ServiceDbConfigManager("TestService");
            var dbAccess      = await CreateDbAccess(configManager);

            var dbAccessProvider = new TestDocumentDbAccessProvider(dbAccess);

            List <Task> tasks = new List <Task>
            {
                Task.Run(async() =>
                {
                    var fruitStore = new FruitStore(dbAccessProvider);

                    var gala = new Apple {
                        Id = Guid.NewGuid(), Type = "Gala"
                    };
                    await fruitStore.UpsertApple(gala);
                }),
                Task.Run(async() =>
                {
                    var flowerStore = new FlowerStore(dbAccessProvider);

                    var daisy = new Daisy {
                        Id = Guid.NewGuid(), Colour = "Red"
                    };
                    await flowerStore.Upsert(daisy);
                })
            };

            Task.WaitAll(tasks.ToArray());
        }
Example #2
0
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
            var daisy = new Daisy
            {
                Id     = Guid.NewGuid(),
                Colour = "Red"
            };

            await _flowerStore.Upsert(daisy);

            var result = await _flowerStore.GetById(daisy.Id);

            return(new[] { result.Colour });
        }
        public async void TestMultipleServiceStores()
        {
            var configManager    = new ServiceDbConfigManager("TestService");
            var dbAccess         = CreateDbAccess(configManager);
            var dbAccessProvider = new TestDocumentDbAccessProvider(dbAccess);

            var fruitStore  = new FruitStore(dbAccessProvider);
            var flowerStore = new FlowerStore(dbAccessProvider);

            await dbAccess.Open(new VersionedDocumentStore[] { fruitStore, flowerStore });

            var apples  = new List <Apple>();
            var daisies = new List <Daisy>();

            for (int i = 0; i < 10; i++)
            {
                var gala = new Apple
                {
                    Id   = Guid.NewGuid(),
                    Type = "Gala"
                };

                var fuji = new Apple
                {
                    Id   = Guid.NewGuid(),
                    Type = "Fuji"
                };

                await fruitStore.UpsertApple(gala);

                await fruitStore.UpsertApple(fuji);

                apples.AddRange(new[] { gala, fuji });

                var daisy = new Daisy
                {
                    Id     = Guid.NewGuid(),
                    Colour = "Red"
                };

                await flowerStore.Upsert(daisy);

                daisies.Add(daisy);
            }

            var r1 = await fruitStore.GetAppleByQuery("[x].Type = 'Gala'");

            Assert.Equal(10, r1.Length);
            Assert.True(r1.All(x => x.Type == "Gala"));

            var r2 = await fruitStore.GetAllApples();

            Assert.Equal(20, r2.Length);

            var lastApple = apples.Last();
            var r3        = await fruitStore.GetAppleById(lastApple.Id);

            Assert.Equal(lastApple.Id, r3.Id);
            Assert.Equal(lastApple.Type, r3.Type);

            var r4 = await fruitStore.GetAppleByIds(apples.Select(x => x.Id.ToString()));

            Assert.Equal(20, r4.Length);

            var lastDaisy = daisies.Last();
            var r5        = await flowerStore.GetById(lastDaisy.Id);

            Assert.Equal(lastDaisy.Id, r5.Id);
            Assert.Equal(lastDaisy.Colour, r5.Colour);
        }