public async Task Then_The_Item_Is_Saved_To_The_Cache_Using_Key_And_First_ConfigName_And_Expiry_Passed( string keyName, int expiryInHours, string appName, string appName2, TestObject test, [Frozen] Mock <IDistributedCache> distributedCache, [Frozen] Mock <IConfiguration> configuration, CacheStorageService service) { //Arrange configuration.SetupGet(x => x[It.Is <string>(s => s.Equals("ConfigNames"))]).Returns($"{appName},{appName2}"); //Act await service.SaveToCache(keyName, test, expiryInHours); //Assert distributedCache.Verify(x => x.SetAsync( $"{appName}_{keyName}", It.Is <byte[]>(c => Encoding.UTF8.GetString(c).Equals(JsonConvert.SerializeObject(test))), It.Is <DistributedCacheEntryOptions>(c => c.AbsoluteExpirationRelativeToNow.Value.Hours == TimeSpan.FromHours(expiryInHours).Hours), It.IsAny <CancellationToken>()), Times.Once); }
public void SavesToDistributedCache() { memoryCache = new MemoryCache(new MemoryCacheOptions()); _sut = new CacheStorageService(_mockDistributedCache.Object, memoryCache, new FatSharedComponentsConfiguration { CacheMemoryAbsoluteExpirySeconds = 5 }); var response = _sut.SaveToCache <TrainingProviderDetailsViewModel>("testkey", GetTestTrainingProviderDetails(), cacheAbsoluteExipration, cacheSlidingExpiration); _mockDistributedCache.Verify(s => s.SetAsync(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>(), It.IsAny <CancellationToken>()), Times.Once()); }
public async Task Then_The_Item_Is_Saved_To_The_Cache_Using_Key_And_Expiry_Passed( string keyName, int expiryInHours, TestObject test, [Frozen] Mock <IDistributedCache> distributedCache, CacheStorageService service) { //Act await service.SaveToCache(keyName, test, expiryInHours); //Assert distributedCache.Verify(x => x.SetAsync( keyName, It.Is <byte[]>(c => Encoding.UTF8.GetString(c).Equals(JsonConvert.SerializeObject(test))), It.Is <DistributedCacheEntryOptions>(c => c.AbsoluteExpirationRelativeToNow.Value.Hours == TimeSpan.FromHours(expiryInHours).Hours), It.IsAny <CancellationToken>()), Times.Once); }