Ejemplo n.º 1
0
        public void TestGetUserCache()
        {
            var camId       = 1;
            var isUserValid = true;
            var camUser     = new User
            {
                PrincipalId = camId,
            };
            var user = new SimpleUser
            {
                Id = Guid.NewGuid()
            };

            var testService = new UserCacheService(cache.Object, expectedTimeToLive);

            cacheDictionary.Add(testService.GetKey(user), new UserCache(user, camUser, isUserValid, null));

            Assert.AreEqual(1, testService.GetCount());
            Action <UserCache> tester = (c) =>
            {
                Assert.IsNotNull(c);
                Assert.AreEqual(user.Id, c.UserId);
            };

            var userCache = testService.GetUserCache(user);

            tester(userCache);

            Assert.AreEqual(1, testService.GetCount());
        }
Ejemplo n.º 2
0
        public void TestGetCacheKey_UserId()
        {
            var user = new SimpleUser
            {
                Id = Guid.NewGuid()
            };
            var testService = new UserCacheService(cache.Object, expectedTimeToLive);

            Assert.AreEqual(user.Id.ToString(), testService.GetKey(user.Id));
        }
Ejemplo n.º 3
0
        public void TestRemove_MultipleUsers()
        {
            var camId1          = 1;
            var camId2          = 2;
            var isCamUser1Valid = true;
            var isCamUser2Valid = true;
            var camUser1        = new User
            {
                PrincipalId = camId1,
            };
            var camUser2 = new User
            {
                PrincipalId = camId2,
            };
            var user1 = new SimpleUser
            {
                Id = Guid.NewGuid()
            };
            var user2 = new SimpleUser
            {
                Id = Guid.NewGuid()
            };
            var testService = new UserCacheService(cache.Object, expectedTimeToLive);

            Assert.AreEqual(0, testService.GetCount());
            Assert.AreEqual(0, cacheDictionary.Count);

            var userCache1 = new UserCache(user1, camUser1, isCamUser1Valid, new List <IPermission>());
            var userCache2 = new UserCache(user2, camUser2, isCamUser2Valid, new List <IPermission>());

            testService.Add(userCache1);
            testService.Add(userCache2);
            Assert.AreEqual(2, testService.GetCount());
            Assert.AreEqual(2, cacheDictionary.Count);

            testService.Remove(user1);
            Assert.AreEqual(1, testService.GetCount());
            Assert.AreEqual(1, cacheDictionary.Count);
            Assert.IsTrue(cacheDictionary.ContainsKey(testService.GetKey(user2)));
            Assert.AreEqual(1, testService.GetCount());
        }
Ejemplo n.º 4
0
        public void TestAdd()
        {
            var camId       = 1;
            var isUserValid = true;
            var camUser     = new User
            {
                PrincipalId = camId,
            };
            var user = new SimpleUser
            {
                Id = Guid.NewGuid()
            };
            var testService = new UserCacheService(cache.Object, expectedTimeToLive);

            Assert.AreEqual(0, testService.GetCount());
            Assert.AreEqual(0, cacheDictionary.Count);

            var userCache = new UserCache(user, camUser, isUserValid, new List <IPermission>());

            testService.Add(userCache);
            Assert.AreEqual(1, testService.GetCount());
            Assert.AreEqual(1, cacheDictionary.Count);
            Assert.IsInstanceOfType(cacheDictionary[testService.GetKey(user)], typeof(UserCache));
        }