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"); }
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(); }
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); }
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); }
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); }