Esempio n. 1
0
        public void HandleSignal_RefreshSingleUsersGroups_CorrectlyHandlesSignal()
        {
            var userId = 6;
            var siteId = 3;
            var signalType = "recache-groups";

            var groupName = "editor";
            var siteIds = new Queue<int>();
            siteIds.Enqueue(1);
            siteIds.Enqueue(2);
            siteIds.Enqueue(siteId);
            var userIds = new Queue<int>();
            userIds.Enqueue(6);
            userIds.Enqueue(6);
            userIds.Enqueue(userId);

            var siteId2s = new Queue<int>();
            siteId2s.Enqueue(1);
            siteId2s.Enqueue(2);
            siteId2s.Enqueue(3);
            var userId2s = new Queue<int>();
            userId2s.Enqueue(userId);
            userId2s.Enqueue(userId);
            userId2s.Enqueue(userId);

            var cache = GetGroupsCache(_mocks);

            var readerMembers = _mocks.DynamicMock<IDnaDataReader>();
            readerMembers.Stub(x => x.Read()).Return(true).Repeat.Times(3);
            readerMembers.Stub(x => x.GetString("name")).Return(groupName);
            readerMembers.Stub(x => x.GetInt32("siteid")).Return(1).WhenCalled(x => x.ReturnValue = siteIds.Dequeue());
            readerMembers.Stub(x => x.GetInt32("userid")).Return(1).WhenCalled(x => x.ReturnValue = userIds.Dequeue());

            var readerGetAllGroups = _mocks.DynamicMock<IDnaDataReader>();
            readerGetAllGroups.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerGetAllGroups.Stub(x => x.GetString("groupname")).Return(groupName);

            

            var readerGetUserGroups = _mocks.DynamicMock<IDnaDataReader>();
            readerGetUserGroups.Stub(x => x.Read()).Return(true).Repeat.Times(3);
            readerGetUserGroups.Stub(x => x.GetString("name")).Return(groupName);
            readerGetUserGroups.Stub(x => x.GetInt32("siteid")).Return(1).WhenCalled(x => x.ReturnValue = siteId2s.Dequeue());
            readerGetUserGroups.Stub(x => x.GetInt32("userid")).Return(1).WhenCalled(x => x.ReturnValue = userId2s.Dequeue());


            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("fetchgroupsandmembersbysite")).Return(readerMembers);
            creator.Stub(x => x.CreateDnaDataReader("GetAllGroups")).Return(readerGetAllGroups);
            creator.Stub(x => x.CreateDnaDataReader("fetchgroupsforuser")).Return(readerGetUserGroups);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var obj = new UserGroups(creator, diag, cache, null, null);

            Assert.AreEqual(2, obj.InternalObjects.Count);

            NameValueCollection args = new NameValueCollection();
            args.Add("userid", userId.ToString());
            Assert.IsTrue(obj.HandleSignal(signalType, args));
            //none returned as refresh removed all existing groups
            Assert.AreEqual(8, obj.InternalObjects.Count);
            var cacheKey = UserGroups.CreateCacheKey(siteId);
            Assert.AreEqual(1, ((UserSiteGroups)obj.InternalObjects[cacheKey]).UserGroupIds[userId].Count);
        }
Esempio n. 2
0
        public void HandleSignal_RefreshAllUsersAndGroups_CorrectlyHandlesSignal()
        {
            var userId = 7;
            var siteId = 2;
            var signalType = "recache-groups";

            var groupName = "editor";
            var siteIds = new Queue<int>();
            siteIds.Enqueue(1);
            siteIds.Enqueue(2);
            siteIds.Enqueue(2);
            var userIds = new Queue<int>();
            userIds.Enqueue(6);
            userIds.Enqueue(6);
            userIds.Enqueue(7);

            var cache = GetGroupsCache(_mocks);

            var readerMembers = _mocks.DynamicMock<IDnaDataReader>();
            readerMembers.Stub(x => x.Read()).Return(true).Repeat.Times(3);
            readerMembers.Stub(x => x.GetString("name")).Return(groupName);
            readerMembers.Stub(x => x.GetInt32("siteid")).Return(1).WhenCalled(x => x.ReturnValue = siteIds.Dequeue());
            readerMembers.Stub(x => x.GetInt32("userid")).Return(1).WhenCalled(x => x.ReturnValue = userIds.Dequeue());

            var readerGetAllGroups = _mocks.DynamicMock<IDnaDataReader>();
            readerGetAllGroups.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerGetAllGroups.Stub(x => x.GetString("groupname")).Return(groupName);

            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("fetchgroupsandmembersbysite")).Return(readerMembers);
            creator.Stub(x => x.CreateDnaDataReader("GetAllGroups")).Return(readerGetAllGroups);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var obj = new UserGroups(creator, diag, cache, null, null);

            Assert.IsTrue(obj.HandleSignal(signalType, null));
            var cacheKey = UserGroups.CreateCacheKey(siteId);
            Assert.AreEqual(1, ((UserSiteGroups)obj.InternalObjects[cacheKey]).UserGroupIds[userId].Count);
        }