コード例 #1
0
        private async Task SeedCounterAsync(Guid id, FruitStore fruitStore, bool shouldSleep = false)
        {
            var versionedApple = await fruitStore.GetVersionedAppleById(id);

            var apple = versionedApple.Document;

            apple.SeedCount += 1;

            if (shouldSleep)
            {
                // Sleep here to give the first thread enough time to store the document.
                // A sleep time less than 10 milli-seconds doesnt give cosmos db enough time
                // to store the first update.
                Thread.Sleep(10);
            }

            await fruitStore.UpsertApple(apple, (int)versionedApple.Metadata.Version);
        }
コード例 #2
0
        public async void TestDocumentPurge()
        {
            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 gala = new Apple {
                Id = Guid.NewGuid(), Type = "Gala"
            };
            var opal = new Apple {
                Id = Guid.NewGuid(), Type = "Opal"
            };

            var redBartlett = new Pear {
                Id = Guid.NewGuid(), Colour = "Red"
            };
            var darkRedBartlett = new Pear {
                Id = Guid.NewGuid(), Colour = "DarkRed"
            };

            await fruitStore.UpsertApple(gala);

            await fruitStore.UpsertApple(gala);

            await fruitStore.UpsertApple(gala);

            await fruitStore.UpsertApple(opal);

            await fruitStore.UpsertPear(redBartlett);

            await fruitStore.UpsertPear(darkRedBartlett);

            await fruitStore.UpsertPear(darkRedBartlett);

            await fruitStore.DeletePearById(darkRedBartlett.Id);

            var galaResult = await fruitStore.GetAppleVersions(gala.Id);

            var opalResult = await fruitStore.GetAppleVersions(opal.Id);

            var redBartlettResult = await fruitStore.GetPearVersions(redBartlett.Id);

            var darkRedBartlettResult = await fruitStore.GetPearVersions(redBartlett.Id);

            Assert.NotNull(galaResult);
            Assert.NotNull(opalResult);
            Assert.NotNull(redBartlettResult);
            Assert.NotNull(darkRedBartlettResult);

            await fruitStore.PurgeAllPears();

            galaResult = await fruitStore.GetAppleVersions(gala.Id);

            opalResult = await fruitStore.GetAppleVersions(opal.Id);

            redBartlettResult = await fruitStore.GetPearVersions(redBartlett.Id);

            darkRedBartlettResult = await fruitStore.GetPearVersions(redBartlett.Id);

            Assert.NotNull(galaResult);
            Assert.NotNull(opalResult);
            Assert.Null(redBartlettResult);
            Assert.Null(darkRedBartlettResult);

            await fruitStore.PurgeApple(gala.Id);

            galaResult = await fruitStore.GetAppleVersions(gala.Id);

            opalResult = await fruitStore.GetAppleVersions(opal.Id);

            Assert.Null(galaResult);
            Assert.NotNull(opalResult);

            await fruitStore.UpsertApple(gala);

            var versionedGalaResult = await fruitStore.GetVersionedAppleById(gala.Id);

            Assert.NotNull(versionedGalaResult);
            Assert.Equal(1, versionedGalaResult.Metadata.Version);
        }