Exemple #1
0
        protected async Task _handleCrazyKeys(IStorage storage)
        {
            var    storeItems = new StoreItems();
            string key        = "!@#$%^&*()~/\\><,.?';\"`~";

            storeItems[key] = new PocoStoreItem()
            {
                Id = "1"
            };

            await storage.Write(storeItems);

            dynamic result = await storage.Read(key);

            Assert.IsNotNull(result[key], $"result['{key}'] should not be null");
            Assert.AreEqual(result[key].Id, "1", "strong .id should be 1");
        }
        protected async Task _handleCrazyKeys(IStorage storage)
        {
            var key       = "!@#$%^&*()~/\\><,.?';\"`~";
            var storeItem = new PocoStoreItem()
            {
                Id = "1"
            };

            await storage.Write(new[] { new KeyValuePair <string, object>(key, storeItem) });

            var storeItems = await storage.Read(key);

            storeItem = storeItems.FirstOrDefault(si => si.Key == key).Value as PocoStoreItem;

            Assert.IsNotNull(storeItem);
            Assert.AreEqual("1", storeItem.Id);
        }
Exemple #3
0
        protected async Task _handleCrazyKeys(IStorage storage)
        {
            var key       = "!@#$%^&*()~/\\><,.?';\"`~";
            var storeItem = new PocoStoreItem()
            {
                Id = "1"
            };

            var dict = new Dictionary <string, object>()
            {
                { key, storeItem }
            };

            await storage.WriteAsync(dict);

            var storeItems = await storage.ReadAsync(new[] { key });

            storeItem = storeItems.FirstOrDefault(si => si.Key == key).Value as PocoStoreItem;

            Assert.IsNotNull(storeItem);
            Assert.AreEqual("1", storeItem.Id);
        }
Exemple #4
0
        protected async Task _updateObjectTest(IStorage storage)
        {
            var originalPocoItem = new PocoItem()
            {
                Id = "1", Count = 1
            };
            var originalPocoStoreItem = new PocoStoreItem()
            {
                Id = "1", Count = 1
            };

            // first write should work
            var dict = new Dictionary <string, object>()
            {
                { "pocoItem", originalPocoItem },
                { "pocoStoreItem", originalPocoStoreItem }
            };

            await storage.WriteAsync(dict);

            var loadedStoreItems = new Dictionary <string, object>(await storage.ReadAsync(new[] { "pocoItem", "pocoStoreItem" }));

            var updatePocoItem      = loadedStoreItems["pocoItem"] as PocoItem;
            var updatePocoStoreItem = loadedStoreItems["pocoStoreItem"] as PocoStoreItem;

            Assert.IsNotNull(updatePocoStoreItem.ETag, "updatePocoItem.eTag  should not be null");

            // 2nd write should work, because we have new etag, or no etag
            updatePocoItem.Count++;
            updatePocoStoreItem.Count++;

            await storage.WriteAsync(loadedStoreItems);

            var reloadedStoreItems = new Dictionary <string, object>(await storage.ReadAsync(new[] { "pocoItem", "pocoStoreItem" }));

            var reloeadedUpdatePocoItem     = reloadedStoreItems["pocoItem"] as PocoItem;
            var reloadedUpdatePocoStoreItem = reloadedStoreItems["pocoStoreItem"] as PocoStoreItem;

            Assert.IsNotNull(reloadedUpdatePocoStoreItem.ETag, "updatePocoItem.eTag  should not be null");
            Assert.AreNotEqual(updatePocoStoreItem.ETag, reloadedUpdatePocoStoreItem.ETag, "updatePocoItem.eTag  should not be different");
            Assert.AreEqual(2, reloeadedUpdatePocoItem.Count, "updatePocoItem.Count should be 2");
            Assert.AreEqual(2, reloadedUpdatePocoStoreItem.Count, "updatePocoStoreItem.Count should be 2");

            // write with old etag should succeed for non-storeitem
            try
            {
                updatePocoItem.Count = 123;

                await storage.WriteAsync(
                    new Dictionary <string, object>() { { "pocoItem", updatePocoItem } }
                    );
            }
            catch
            {
                Assert.Fail("Should not throw exception on write with pocoItem");
            }

            // write with old etag should FAIL for storeitem
            try
            {
                updatePocoStoreItem.Count = 123;

                await storage.WriteAsync(
                    new Dictionary <string, object>() { { "pocoStoreItem", updatePocoStoreItem } }
                    );

                Assert.Fail("Should have thrown exception on write with store item because of old etag");
            }
            catch
            {
            }

            var reloadedStoreItems2 = new Dictionary <string, object>(await storage.ReadAsync(new[] { "pocoItem", "pocoStoreItem" }));

            var reloadedPocoItem2      = reloadedStoreItems2["pocoItem"] as PocoItem;
            var reloadedPocoStoreItem2 = reloadedStoreItems2["pocoStoreItem"] as PocoStoreItem;

            Assert.AreEqual(123, reloadedPocoItem2.Count);
            Assert.AreEqual(2, reloadedPocoStoreItem2.Count);

            // write with wildcard etag should work
            reloadedPocoItem2.Count      = 100;
            reloadedPocoStoreItem2.Count = 100;
            reloadedPocoStoreItem2.ETag  = "*";

            var wildcardEtagedict = new Dictionary <string, object>()
            {
                { "pocoItem", reloadedPocoItem2 },
                { "pocoStoreItem", reloadedPocoStoreItem2 }
            };

            await storage.WriteAsync(wildcardEtagedict);

            var reloadedStoreItems3 = new Dictionary <string, object>(await storage.ReadAsync(new [] { "pocoItem", "pocoStoreItem" }));

            Assert.AreEqual(100, (reloadedStoreItems3["pocoItem"] as PocoItem).Count);
            Assert.AreEqual(100, (reloadedStoreItems3["pocoStoreItem"] as PocoStoreItem).Count);

            // write with empty etag should not work
            try
            {
                var reloadedStoreItem4 = (await storage.ReadAsync(new [] { "pocoStoreItem" })).OfType <PocoStoreItem>().First();

                reloadedStoreItem4.ETag = "";
                var dict2 = new Dictionary <string, object>()
                {
                    { "pocoStoreItem", reloadedStoreItem4 }
                };


                await storage.WriteAsync(dict2);

                Assert.Fail("Should have thrown exception on write with storeitem because of empty etag");
            }
            catch
            {
            }


            var finalStoreItems = new Dictionary <string, object>(await storage.ReadAsync(new[] { "pocoItem", "pocoStoreItem" }));

            Assert.AreEqual(100, (finalStoreItems["pocoItem"] as PocoItem).Count);
            Assert.AreEqual(100, (finalStoreItems["pocoStoreItem"] as PocoStoreItem).Count);
        }