示例#1
0
        public void GetAsync_GivenNullCacheKey_ShouldThrowArgumentNullException()
        {
            //---------------Set up test pack-------------------
            var thuriaCache = new ThuriaCache <string>();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.ThrowsAsync <ArgumentNullException>(() => thuriaCache.GetAsync(null));

            //---------------Test Result -----------------------
            exception.ParamName.Should().Be("cacheKey");
        }
示例#2
0
        public async Task GetAsync_GivenDataDoesNotExist_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            var cacheKey    = RandomValueGenerator.CreateRandomString(5, 10);
            var thuriaCache = new ThuriaCache <string>();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var cacheDataReturned = await thuriaCache.GetAsync(cacheKey);

            //---------------Test Result -----------------------
            cacheDataReturned.Should().BeNull();
        }
示例#3
0
        public async Task GetAsync_GivenDataExists_ShouldReturnData()
        {
            //---------------Set up test pack-------------------
            var cacheKey    = RandomValueGenerator.CreateRandomString(5, 10);
            var cacheData   = RandomValueGenerator.CreateRandomString(20, 50);
            var thuriaCache = new ThuriaCache <string>();

            await thuriaCache.UpsertAsync(cacheKey, new ThuriaCacheData <string>(cacheData));

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var cacheDataReturned = await thuriaCache.GetAsync(cacheKey);

            //---------------Test Result -----------------------
            cacheDataReturned.Should().NotBeNullOrWhiteSpace();
            cacheDataReturned.Should().Be(cacheData);
        }
示例#4
0
        public async Task Upsert_GivenValidData_And_CacheDataDoesNotExist_ShouldAddCacheDataToCache_And_ReturnTrue()
        {
            //---------------Set up test pack-------------------
            var cacheKey        = RandomValueGenerator.CreateRandomString(5, 10);
            var cacheData       = RandomValueGenerator.CreateRandomString(20, 50);
            var thuriaCacheData = new ThuriaCacheData <string>(cacheData);
            var thuriaCache     = new ThuriaCache <string>();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var upsertResult = await thuriaCache.UpsertAsync(cacheKey, thuriaCacheData);

            //---------------Test Result -----------------------
            upsertResult.Should().BeTrue();

            var returnedData = await thuriaCache.GetAsync(cacheKey);

            returnedData.Should().Be(cacheData);
        }
示例#5
0
        public async Task Upsert_GivenValidData_And_CacheDataExists_ShouldUpdateCacheDataInCache_And_ReturnTrue()
        {
            //---------------Set up test pack-------------------
            var cacheKey         = RandomValueGenerator.CreateRandomString(5, 10);
            var cacheData1       = RandomValueGenerator.CreateRandomString(20, 50);
            var cacheData2       = RandomValueGenerator.CreateRandomString(20, 50);
            var thuriaCacheData1 = new ThuriaCacheData <string>(cacheData1);
            var thuriaCacheData2 = new ThuriaCacheData <string>(cacheData2);
            var thuriaCache      = new ThuriaCache <string>();
            var upsertResult1    = await thuriaCache.UpsertAsync(cacheKey, thuriaCacheData1);

            //---------------Assert Precondition----------------
            upsertResult1.Should().BeTrue();
            //---------------Execute Test ----------------------
            var upsertResult2 = await thuriaCache.UpsertAsync(cacheKey, thuriaCacheData2);

            //---------------Test Result -----------------------
            upsertResult2.Should().BeTrue();

            var returnedData = await thuriaCache.GetAsync(cacheKey);

            returnedData.Should().Be(cacheData2);
        }