コード例 #1
0
        public void Should_Overwrite_Item_in_Cache()
        {
            var user = TestDataHelper.CreateNewUser();

            //Save data to the cache
            var result = _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(result);

            //Verify that the user is actually in the database
            var itemInCache = _cacheService.Get(user.UserName);

            Assert.IsInstanceOf <UserAccount>(itemInCache);
            Assert.AreEqual(user.EmailAddress, ((UserAccount)itemInCache).EmailAddress);

            var originalName = user.UserName;
            var newName      = "Bears";

            user.UserName = newName;

            Assert.AreNotEqual(originalName, user.UserName);
            Assert.IsTrue(_cacheService.Save(originalName, user));

            itemInCache = _cacheService.Get(originalName);
            Assert.IsInstanceOf <UserAccount>(itemInCache);
            Assert.AreEqual(user.EmailAddress, ((UserAccount)itemInCache).EmailAddress);
            Assert.AreNotEqual(originalName, ((UserAccount)itemInCache).UserName);
            Assert.AreEqual(newName, ((UserAccount)itemInCache).UserName);
        }
コード例 #2
0
        public void Should_Save_Item_To_Cache()
        {
            //Create a new test user to save to the cache
            var user = TestDataHelper.CreateNewUser();

            //Save the user to the cache
            var result = _cacheService.Save(user.UserName, user);


            //Verify that the user is in the cache
            Assert.IsTrue(result);
        }
コード例 #3
0
        public void CanSaveItemToCacheAndVerify()
        {
            //Create a new test user to save to the cache
            var user = TestDataHelper.CreateNewUser();

            //Add the cached object to our clean-up list
            _cachedObjects.Add(user.UserName);

            //Save the user to the cache
            _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(_cacheService.Exists(user.UserName));
        }
コード例 #4
0
        public void Should_Get_Poco_Item_From_Cache()
        {
            var user = TestDataHelper.CreateNewUser();

            //Save data to the cache
            var result = _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(result);

            var itemInCache = _cacheService.Get(user.UserName);

            Assert.IsInstanceOf <UserAccount>(itemInCache);
            Assert.AreEqual(user.EmailAddress, ((UserAccount)itemInCache).EmailAddress);
        }
コード例 #5
0
        public void CanDeleteItemFromCache()
        {
            //Create a new test user to save to the cache
            var user = TestDataHelper.CreateNewUser();

            //Add the cached object to our clean-up list
            _cachedObjects.Add(user.UserName);

            //Save the user to the cache
            _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(_cacheService.Exists(user.UserName));

            //Attempt to delete the object from the cache...
            var removeResult = _cacheService.Remove(user.UserName);

            //Assert that the item was indeed removed from the cache..
            Assert.IsTrue(removeResult);

            //Verify that the item was removed
            Assert.IsFalse(_cacheService.Exists(user.UserName));
        }
コード例 #6
0
        public void CanSaveAndRetrieveItemFromCache()
        {
            //Create a new test user to save to the cache
            var user = TestDataHelper.CreateNewUser();

            //Add the cached object to our clean-up list
            _cachedObjects.Add(user.UserName);

            //Save the user to the cache
            _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(_cacheService.Exists(user.UserName));

            //Retrieve the object from the cache
            var userInCache = _cacheService.Get(user.UserName) as UserAccount;

            //Assert that the object isn't null
            Assert.IsNotNull(userInCache);

            //Assert that the object in the cache is the same instance as our existing object
            Assert.AreSame(user, userInCache);
        }
コード例 #7
0
        public void CanUpdateItemInCache()
        {
            //Create a new test user to save to the cache
            var user = TestDataHelper.CreateNewUser();

            //Add the cached object to our clean-up list
            _cachedObjects.Add(user.UserName);

            //Save the user to the cache
            _cacheService.Save(user.UserName, user);

            //Verify that the user is in the cache
            Assert.IsTrue(_cacheService.Exists(user.UserName));

            //Clone the user's email address and save a copy for future comparison
            var oldUserEmail = user.EmailAddress.Clone() as string;

            //Create a new email address
            var newUserEmail = System.Guid.NewGuid().ToString();

            user.EmailAddress = newUserEmail;

            //Assert that the two emails aren't equal (reference checking, not Guid collisions)
            Assert.AreNotEqual(oldUserEmail, newUserEmail);

            //Update the user in the cache
            _cacheService.Save(user.UserName, user);

            //Retrieve the object from the cache
            var userInCache = _cacheService.Get(user.UserName) as UserAccount;

            //Assert that the object isn't null
            Assert.IsNotNull(userInCache);

            //Assert that the object in the cache is the same instance as our existing object
            Assert.AreNotEqual(oldUserEmail, userInCache.EmailAddress);
        }