コード例 #1
0
        public void TestRemove()
        {
            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);

            testService.Remove(user);
            Assert.AreEqual(0, testService.GetCount());
            Assert.AreEqual(0, cacheDictionary.Count);
        }
コード例 #2
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());
        }
コード例 #3
0
        public void Should_return_null_key_when_user_is_null()
        {
            // Given
            User user             = null;
            var  userCacheService = new UserCacheService();

            // When
            var key = userCacheService.Add(user);

            // Then
            key.ShouldBe(null);
        }
コード例 #4
0
        public void Should_return_valid_key_when_user_is_added()
        {
            // Given
            var user = new User()
            {
                Id = MakeFake.Guid
            };
            var userCacheService = new UserCacheService();

            // When
            var key = userCacheService.Add(user);

            // Then
            key.ShouldNotBe(null);
            key.IsGuid().ShouldBe(true);
        }
コード例 #5
0
        public void Should_return_true_when_key_is_known()
        {
            // Given
            var user = new User()
            {
                Id = MakeFake.Guid
            };
            var userCacheService = new UserCacheService();
            var key = userCacheService.Add(user);

            // When
            var isValid = userCacheService.Validate(key);

            // Then
            isValid.ShouldBe(true);
        }
コード例 #6
0
        public void Should_return_success_is_true_when_removing_known_key()
        {
            // Given
            var user = new User()
            {
                Id = MakeFake.Guid
            };
            var userCacheService = new UserCacheService();
            var key = userCacheService.Add(user);

            // When
            var success = userCacheService.Remove(key);

            // Then
            success.ShouldBe(true);
        }
コード例 #7
0
        public void Should_return_user_when_key_is_known()
        {
            // Given
            var userId           = MakeFake.Guid;
            var userCacheService = new UserCacheService();
            var key = userCacheService.Add(new User()
            {
                Id = userId
            });

            // When
            var user = userCacheService.GetUser(key);

            // Then
            user.ShouldNotBe(null);
            user.Id.ShouldBe(userId);
        }
コード例 #8
0
        public void Should_return_success_is_false_when_key_is_unknown()
        {
            // Given
            var user = new User()
            {
                Id = MakeFake.Guid
            };
            var unknownKey       = MakeFake.Guid;
            var userCacheService = new UserCacheService();
            var key = userCacheService.Add(user);

            // When
            var success = userCacheService.Remove(unknownKey);

            // Then
            success.ShouldBe(false);
        }
コード例 #9
0
        public void Should_return_null_user_after_user_is_removed()
        {
            // Given
            var userId           = MakeFake.Guid;
            var userCacheService = new UserCacheService();
            var key = userCacheService.Add(new User()
            {
                Id = userId
            });

            // When
            userCacheService.Remove(key);
            var user = userCacheService.GetUser(key);

            // Then
            user.ShouldBe(null);
        }
コード例 #10
0
        public void Should_return_null_when_key_is_unknown()
        {
            // Given
            var userId           = MakeFake.Guid;
            var userCacheService = new UserCacheService();
            var unknownKey       = MakeFake.Guid;

            userCacheService.Add(new User()
            {
                Id = userId
            });

            // When
            var user = userCacheService.GetUser(unknownKey);

            // Then
            user.ShouldBe(null);
        }
コード例 #11
0
        public void Should_return_false_when_key_is_unknown()
        {
            // Given
            var user = new User()
            {
                Id = MakeFake.Guid
            };
            var unknownKey       = MakeFake.Guid;
            var userCacheService = new UserCacheService();

            userCacheService.Add(user);

            // When
            var isValid = userCacheService.Validate(unknownKey);

            // Then
            isValid.ShouldBe(false);
        }