示例#1
0
        public void TypesOfStorage_ElementsAreProperlyObtainedFromCacheAndDataBase()
        {
            var dataBase = InitializeDataBase(amountOfElements: 5);
            var cache    = new CacheBuilder <string>().Build(capacity: 3, timeOfExpirationInTicks: 1000, slowDataBase: dataBase);
            var listOfId = dataBase.GetListOfId();

            for (var i = 0; i < 5; i++)
            {
                cache.GetElementById(listOfId[i]);
            }

            for (var i = 2; i >= 0; i--)
            {
                cache.GetElementById(listOfId[i]);
            }

            var listOfElementsInCache = cache.GetListOfElementsLocatedInCache();

            const int amountOfElementsInCache = 1;

            Assert.AreEqual(amountOfElementsInCache, listOfElementsInCache.Count);
            const string valueOfElementInCache = "two";

            Assert.AreEqual(valueOfElementInCache, listOfElementsInCache[0].Value);
        }
        public void TypesOfStorage_ElementsAreProperlyObtainedFromCacheAndDataBase()
        {
            var dataBase = InitializeDataBase(amountOfElements: 5);
            var cache = new CacheBuilder<string>().Build(capacity: 3, timeOfExpirationInTicks: 1000, slowDataBase: dataBase);
            var listOfId = dataBase.GetListOfId();

            for (var i = 0; i < 5; i++)
                cache.GetElementById(listOfId[i]);

            for (var i = 2; i >= 0; i--)
                cache.GetElementById(listOfId[i]);

            var listOfElementsInCache = cache.GetListOfElementsLocatedInCache();

            const int amountOfElementsInCache = 1;
            Assert.AreEqual(amountOfElementsInCache, listOfElementsInCache.Count);
            const string valueOfElementInCache = "two";
            Assert.AreEqual(valueOfElementInCache, listOfElementsInCache[0].Value);
        }