public void Constructor() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var cacheData = new ThuriaCacheData <string>("Test", DateTime.UtcNow.AddSeconds(5)); //---------------Test Result ----------------------- cacheData.Should().NotBeNull(); }
public void Upsert_GivenNullCacheKey_ShouldThrowArgumentNullException() { //---------------Set up test pack------------------- var thuriaCacheData = new ThuriaCacheData <string>("Test"); var thuriaCache = new ThuriaCache <string>(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var exception = Assert.ThrowsAsync <ArgumentNullException>(() => thuriaCache.UpsertAsync(null, thuriaCacheData)); //---------------Test Result ----------------------- exception.ParamName.Should().Be("cacheKey"); }
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(); }
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); }