Пример #1
0
        public void CommonRW()
        {
            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);

            Assert.IsTrue(storageService.Has("infiniteKey"), "Invalid value");
            Assert.AreEqual(storageService.Get <StorageValueWrapper>("infiniteKey").value, 1);

            storageService.Remove("infiniteKey");

            Assert.IsFalse(storageService.Has("infiniteKey"));

            //storageService.Set("sampleKey", null);
            //Assert.IsNotNull(storageService.Has("sampleKey"));
        }
Пример #2
0
        public void ExpireTime()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("sessionKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.AfterSession);
            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);
            storageService.Create("nonExpiredKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Expire, DateTime.UtcNow + new TimeSpan(24, 0, 0));

            //make sure entry will be expired
            storageService.Create("expiredKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Expire, DateTime.UtcNow + new TimeSpan(0, 0, 0, 0, 5));
            Thread.Sleep(10);

            //test expierd entry
            Assert.ThrowsException <EntryExpiredException>(() =>
            {
                storageService.Get("expiredKey");
            }, "Expired entry have to throw exception during R/W operations");

            Assert.ThrowsException <EntryExpiredException>(() =>
            {
                storageService.Update("expiredKey", StorageValueWrapper.FromValue(2));
            }, "Expired entry have to throw exception during R/W operations");

            storageService.UpdateExpireDate("expiredKey", DateTime.UtcNow + new TimeSpan(24, 0, 0));
            storageService.Update("expiredKey", StorageValueWrapper.FromValue(5));

            //test if reseted entry will be changed as expected
            Assert.AreEqual(storageService.Get <StorageValueWrapper>("expiredKey").value, 5);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.IsFalse(storageService.Has("sessionKey"), "Session key shouldn't be saved and loaded");
            Assert.AreEqual(storageService.Get <StorageValueWrapper>("infiniteKey").value, 1, "Inifinite key should be aviable");
        }
Пример #3
0
        public void FlushLoad()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.AreEqual(storageService.Get <StorageValueWrapper>("infiniteKey").value, 1, "Inifinite key should be aviable");
        }
Пример #4
0
        public void TestDeserializedStorageEntityExpireRule()
        {
            //make sure all entries will be deleted
            TestingResourcesHelper.PreapareTestingDirectory(ServiceResolver.GetService <IAppConfigurationService>());

            var storageService = ServiceResolver.GetService <IStorageService>();

            storageService.Create("infiniteKey", StorageValueWrapper.FromValue(1), StorageEntryExpirePolicy.Never);

            //save data
            storageService.Flush();

            //reset service(es)
            Cleanup();
            Init();

            storageService = ServiceResolver.GetService <IStorageService>();
            storageService.Load();

            Assert.AreEqual(storageService.GetExpirePolicy("infiniteKey"), StorageEntryExpirePolicy.Never, "Created and loaded expire policies should be same");
        }