コード例 #1
0
        public async void TestLargeNumberOfDocuments()
        {
            var configManager    = new ServiceDbConfigManager("TestService");
            var dbAccess         = CreateDbAccess(configManager);
            var dbAccessProvider = new TestDocumentDbAccessProvider(dbAccess);

            var fruitStore = new FruitStore(dbAccessProvider);

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

            var apples = new List <Apple>();

            for (int i = 0; i < 800; 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 r1 = await fruitStore.GetAppleByQuery("[x].Type = 'Gala'");

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

            var r2 = await fruitStore.GetAllApples();

            Assert.Equal(1600, 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(1600, r4.Length);
        }
コード例 #2
0
        public async void TestMultipleStoreDocumentTypes()
        {
            var configManager    = new ServiceDbConfigManager("TestService");
            var dbAccess         = CreateDbAccess(configManager);
            var dbAccessProvider = new TestDocumentDbAccessProvider(dbAccess);

            var fruitStore = new FruitStore(dbAccessProvider);

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

            var apples = new List <Apple>();
            var pears  = new List <Pear>();

            for (int i = 0; i < 50; 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 bartlett = new Pear
                {
                    Id     = Guid.NewGuid(),
                    Colour = "Red"
                };

                var comice = new Pear
                {
                    Id     = Guid.NewGuid(),
                    Colour = "Green"
                };

                await fruitStore.UpsertPear(bartlett);

                await fruitStore.UpsertPear(comice);

                pears.AddRange(new[] { bartlett, comice });
            }

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

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

            var r2 = await fruitStore.GetAllApples();

            Assert.Equal(100, 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(100, r4.Length);

            var r5 = await fruitStore.GetPearByQuery("[x].Colour = @colour", new[] { new DbParameter("colour", "Red") });

            Assert.Equal(50, r5.Length);
            Assert.True(r5.All(x => x.Colour == "Red"));

            var r6 = await fruitStore.GetAllPears();

            Assert.Equal(100, r6.Length);

            var lastPear = pears.Last();
            var r7       = await fruitStore.GetPearById(lastPear.Id);

            Assert.Equal(lastPear.Id, r7.Id);
            Assert.Equal(lastPear.Colour, r7.Colour);
        }
コード例 #3
0
        public async void TestMultipleServicesDocumentPurge()
        {
            var configManager1    = new ServiceDbConfigManager("TestService1");
            var dbAccess1         = CreateDbAccess(configManager1);
            var dbAccessProvider1 = new TestDocumentDbAccessProvider(dbAccess1);

            var configManager2    = new ServiceDbConfigManager("TestService2");
            var dbAccess2         = CreateDbAccess(configManager2);
            var dbAccessProvider2 = new TestDocumentDbAccessProvider(dbAccess2);

            var fruitStore1 = new FruitStore(dbAccessProvider1);
            var fruitStore2 = new FruitStore(dbAccessProvider2);

            await dbAccess1.Open(new[] { fruitStore1 });

            await dbAccess2.Open(new[] { fruitStore2 });

            var apples = new List <Apple>();

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

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

                await fruitStore1.UpsertApple(gala);

                await fruitStore1.UpsertApple(fuji);

                await fruitStore2.UpsertApple(gala);

                await fruitStore2.UpsertApple(fuji);

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

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

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

            var r2 = await fruitStore1.GetAllApples();

            Assert.Equal(40, r2.Length);

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

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

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

            Assert.Equal(40, r4.Length);

            ServiceManager serviceManager1 = new ServiceManager(dbAccess1);
            ServiceManager serviceManager2 = new ServiceManager(dbAccess2);

            // Purge a service's docs.
            await serviceManager1.PurgeDocumentsAsync();

            Assert.Empty(await fruitStore1.GetAllApples());
            Assert.NotEmpty(await fruitStore2.GetAllApples());

            // Purge other service's docs.
            await serviceManager2.PurgeDocumentsAsync();

            Assert.Empty(await fruitStore1.GetAllApples());
            Assert.Empty(await fruitStore2.GetAllApples());
        }
コード例 #4
0
        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);
        }