public void AppendUpdatedOrNewItemsInList_NothingUpdated()
 {
     ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();
     sessionItems["key"] = "val";
     sessionItems.Remove("key");
     Assert.Equal(0, RedisUtility.AppendUpdatedOrNewItemsInList(sessionItems, null));
 }
        public void TryUpdateIfLockIdMatchPrepare_Valid_OneUpdateOneDelete()
        {
            string id             = "session_id";
            int    sessionTimeout = 900;
            object lockId         = DateTime.Now.Ticks;
            ChangeTrackingSessionStateItemCollection data = Utility.GetChangeTrackingSessionStateItemCollection();

            data["KeyDel"] = "valueDel";
            data["Key"]    = "value";
            data.Remove("KeyDel");

            RedisConnectionWrapper.redisUtility     = new RedisUtility(Utility.GetDefaultConfigUtility());
            RedisConnectionWrapper.sharedConnection = A.Fake <RedisSharedConnection>();
            RedisConnectionWrapper redisConn = new RedisConnectionWrapper(Utility.GetDefaultConfigUtility(), id);

            redisConn.redisConnection = A.Fake <IRedisClientConnection>();

            redisConn.TryUpdateAndReleaseLockIfLockIdMatch(lockId, data, sessionTimeout);

            A.CallTo(() => redisConn.redisConnection.Eval(A <string> .Ignored, A <string[]> .That.Matches(s => s.Length == 3), A <object[]> .That.Matches(
                                                              o => o.Length == 11 &&
                                                              o[2].Equals(1) &&
                                                              o[3].Equals(9) &&
                                                              o[4].Equals(9) &&
                                                              o[5].Equals(1) &&
                                                              o[6].Equals(10) &&
                                                              o[7].Equals(11)
                                                              ))).MustHaveHappened();
        }
Exemple #3
0
        public void AppendUpdatedOrNewItemsInList_NothingUpdated()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();

            sessionItems["key"] = "val";
            sessionItems.Remove("key");
            Assert.Equal(0, RedisUtility.AppendUpdatedOrNewItemsInList(sessionItems, null));
        }
 public void AppendRemoveItemsInList_SuccessfulDeleted()
 {
     ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();
     List<object> list = new List<object>();
     sessionItems["key"] = "val";
     sessionItems.Remove("key");
     Assert.Equal(1, RedisUtility.AppendRemoveItemsInList(sessionItems, list));
     Assert.Equal(1, list.Count);
 }
Exemple #5
0
        public void AppendRemoveItemsInList_SuccessfulDeleted()
        {
            ChangeTrackingSessionStateItemCollection sessionItems = new ChangeTrackingSessionStateItemCollection();
            List <object> list = new List <object>();

            sessionItems["key"] = "val";
            sessionItems.Remove("key");
            Assert.Equal(1, RedisUtility.AppendRemoveItemsInList(sessionItems, list));
            Assert.Equal(1, list.Count);
        }
 public void Remove_WrongKey()
 {
     ChangeTrackingSessionStateItemCollection items = new ChangeTrackingSessionStateItemCollection();
     items["key"] = "value";
     Assert.Equal(1, items.Count);
     Assert.Equal(0, items.GetDeletedKeys().Count);
     Assert.Equal(1, items.GetModifiedKeys().Count);
     items.Remove("key1");
     Assert.Equal(1, items.Count);
     Assert.Equal(0, items.GetDeletedKeys().Count);
     Assert.Equal(1, items.GetModifiedKeys().Count);
 }
Exemple #7
0
        public void Remove_WrongKey()
        {
            ChangeTrackingSessionStateItemCollection items = new ChangeTrackingSessionStateItemCollection();

            items["key"] = "value";
            Assert.Equal(1, items.Count);
            Assert.Equal(0, items.GetDeletedKeys().Count);
            Assert.Equal(1, items.GetModifiedKeys().Count);
            items.Remove("key1");
            Assert.Equal(1, items.Count);
            Assert.Equal(0, items.GetDeletedKeys().Count);
            Assert.Equal(1, items.GetModifiedKeys().Count);
        }
Exemple #8
0
        public void Remove_WrongKey()
        {
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items["key"] = "value";
            Assert.Single(items);
            Assert.Empty(items.GetDeletedKeys());
            Assert.Single(items.GetModifiedKeys());
            items.Remove("key1");
            Assert.Single(items);
            Assert.Empty(items.GetDeletedKeys());
            Assert.Single(items.GetModifiedKeys());
        }
Exemple #9
0
        public void Remove_Successful()
        {
            ChangeTrackingSessionStateItemCollection items = Utility.GetChangeTrackingSessionStateItemCollection();

            items["key"] = "value";
            Assert.Equal(1, items.Count);
            Assert.Equal(0, items.GetDeletedKeys().Count);
            Assert.Equal(1, items.GetModifiedKeys().Count);
            items.Remove("key");
            Assert.Equal(0, items.Count);
            Assert.Equal(1, items.GetDeletedKeys().Count);
            Assert.Equal(0, items.GetModifiedKeys().Count);
        }
Exemple #10
0
        public void SetAndReleaseItemExclusive_OldItemRemovedItems()
        {
            Utility.SetConfigUtilityToDefault();
            string id = "session-id";
            ChangeTrackingSessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection();

            sessionStateItemCollection["session-key"] = "session-val";
            sessionStateItemCollection.Remove("session-key");
            SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15);

            var mockCache = A.Fake <ICacheConnection>();
            RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();

            sessionStateStore.cache = mockCache;
            sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false);
            A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A <object> .Ignored,
                                                                          A <ChangeTrackingSessionStateItemCollection> .That.Matches(o => o.Count == 0 && o.GetModifiedKeys().Count == 0 && o.GetDeletedKeys().Count == 1), 900)).MustHaveHappened();
        }
        public async Task SetAndReleaseItemExclusive_OldItemRemovedItems()
        {
            Utility.SetConfigUtilityToDefault();
            string id = "session-id";
            ChangeTrackingSessionStateItemCollection sessionStateItemCollection = Utility.GetChangeTrackingSessionStateItemCollection();

            sessionStateItemCollection["session-key"] = "session-val";
            sessionStateItemCollection.Remove("session-key");
            SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15);

            var mockCache = A.Fake <ICacheConnection>();
            RedisSessionStateProvider sessionStateStore = new Oriflame.Web.Redis.RedisSessionStateProvider();

            sessionStateStore.cache = mockCache;
            await sessionStateStore.SetAndReleaseItemExclusiveAsync(FakeHttpContext, id, sssd, 7, false, CancellationToken.None);

            A.CallTo(() => mockCache.TryUpdateAndReleaseLock(A <object> .Ignored,
                                                             A <ChangeTrackingSessionStateItemCollection> .That.Matches(o => o.Count == 0 && o.GetModifiedKeys().Count == 0 && o.GetDeletedKeys().Count == 1), 900)).MustHaveHappened();
        }
Exemple #12
0
        public void InsertRemoveUpdate_Sequence()
        {
            // Initial insert to set up value
            ChangeTrackingSessionStateItemCollection items = new ChangeTrackingSessionStateItemCollection();

            items["key1"] = "value1";
            Assert.Equal("value1", items[0]);
            Assert.Equal(true, items.Dirty);
            items.Dirty = false;

            // remove key
            items.Remove("key1");
            Assert.Equal(0, items.Count);
            Assert.Equal(1, items.GetDeletedKeys().Count);
            Assert.Equal(0, items.GetModifiedKeys().Count);

            // in same transaction insert same key than it should be update
            items["key1"] = "value1";
            Assert.Equal(1, items.Count);
            Assert.Equal(0, items.GetDeletedKeys().Count);
            Assert.Equal(1, items.GetModifiedKeys().Count);
        }
        public void TryUpdateIfLockIdMatchPrepare_Valid_OneUpdateOneDelete()
        {
            string id = "session_id";
            int sessionTimeout = 900;
            object lockId = DateTime.Now.Ticks;
            ChangeTrackingSessionStateItemCollection data = new ChangeTrackingSessionStateItemCollection();
            data["KeyDel"] = "valueDel";
            data["Key"] = "value";
            data.Remove("KeyDel");

            
            var mockRedisClient = A.Fake<IRedisClientConnection>();
            RedisConnectionWrapper.sharedConnection = new RedisSharedConnection(null, null);
            RedisConnectionWrapper.sharedConnection.connection = mockRedisClient;
            RedisConnectionWrapper redisConn = new RedisConnectionWrapper(Utility.GetDefaultConfigUtility(), id);
            redisConn.TryUpdateAndReleaseLockIfLockIdMatch(lockId, data, sessionTimeout);

            A.CallTo(() => mockRedisClient.Eval(A<string>.Ignored, A<string[]>.That.Matches(s => s.Length == 3), A<object[]>.That.Matches(
               o => o.Length == 11 &&
                    o[2].Equals(1) &&
                    o[3].Equals(9) &&
                    o[4].Equals(9) &&
                    o[5].Equals(1) &&
                    o[6].Equals(10) &&
                    o[7].Equals(11)
                ))).MustHaveHappened();
        }
        public void SetAndReleaseItemExclusive_OldItemRemovedItems()
        {
            Utility.SetConfigUtilityToDefault();
            string id = "session-id";
            ChangeTrackingSessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection();
            sessionStateItemCollection["session-key"] = "session-val";
            sessionStateItemCollection.Remove("session-key");
            SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15);

            var mockCache = A.Fake<ICacheConnection>();
            RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();
            sessionStateStore.cache = mockCache;
            sessionStateStore.SetAndReleaseItemExclusive(null, id, sssd, 7, false);
            A.CallTo(() => mockCache.TryUpdateAndReleaseLockIfLockIdMatch(A<object>.Ignored, 
                A<ChangeTrackingSessionStateItemCollection>.That.Matches(o => o.Count == 0 && o.GetModifiedKeys().Count == 0 && o.GetDeletedKeys().Count == 1), 900)).MustHaveHappened();
        }
        public void InsertRemoveUpdate_Sequence()
        {
            // Initial insert to set up value
            ChangeTrackingSessionStateItemCollection items = new ChangeTrackingSessionStateItemCollection();
            items["key1"] = "value1";
            Assert.Equal("value1", items[0]);
            Assert.Equal(true, items.Dirty);
            items.Dirty = false;

            // remove key
            items.Remove("key1");
            Assert.Equal(0, items.Count);
            Assert.Equal(1, items.GetDeletedKeys().Count);
            Assert.Equal(0, items.GetModifiedKeys().Count);
            
            // in same transaction insert same key than it should be update
            items["key1"] = "value1";
            Assert.Equal(1, items.Count);
            Assert.Equal(0, items.GetDeletedKeys().Count);
            Assert.Equal(1, items.GetModifiedKeys().Count);
        }