Esempio n. 1
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);
        }