public void Upsert_GivenNullCacheValue_ShouldThrowArgumentNullException() { //---------------Set up test pack------------------- var thuriaCache = new ThuriaCache <string>(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var exception = Assert.ThrowsAsync <ArgumentNullException>(() => thuriaCache.UpsertAsync("Test", null)); //---------------Test Result ----------------------- exception.ParamName.Should().Be("cacheValue"); }
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); }
public async Task ExistsAsync_GivenDataExists_And_NotExpired_ShouldReturnTrue() { //---------------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 dataExist = await thuriaCache.ExistsAsync(cacheKey); //---------------Test Result ----------------------- dataExist.Should().BeTrue(); }
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_SetCacheExpiryIsFalse_ShouldNotUpdateCacheExpiry() { //---------------Set up test pack------------------- DateTime?dataExpiry = null; var cacheKey = RandomValueGenerator.CreateRandomString(5, 10); var thuriaCacheData = Substitute.For <IThuriaCacheData <string> >(); thuriaCacheData.Expiry = Arg.Do <DateTime>(time => dataExpiry = time); var thuriaCache = new ThuriaCache <string>(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var upsertResult = await thuriaCache.UpsertAsync(cacheKey, thuriaCacheData, false); //---------------Test Result ----------------------- upsertResult.Should().BeTrue(); dataExpiry.Should().BeNull(); }
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 ExistsAsync_GivenDataExists_And_Expired_ShouldReturnFalse() { //---------------Set up test pack------------------- var cacheKey = RandomValueGenerator.CreateRandomString(5, 10); var cacheData = RandomValueGenerator.CreateRandomString(20, 50); var thuriaCache = new ThuriaCache <string>(); var thuriaCacheData = new ThuriaCacheData <string>(cacheData, DateTime.UtcNow.AddMilliseconds(10)); await thuriaCache.UpsertAsync(cacheKey, thuriaCacheData, false); Thread.Sleep(200); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var dataExist = await thuriaCache.ExistsAsync(cacheKey); //---------------Test Result ----------------------- dataExist.Should().BeFalse(); }