public OnActionExecutingAsync ( System.Web.Http.Controllers.HttpActionContext actionContext, |
||
actionContext | System.Web.Http.Controllers.HttpActionContext | |
cancellationToken | ||
return | Task |
public async Task Should_create_phoenix_and_try_refresh_cache_when_cache_item_is_stale() { // Arrange var store = Substitute.For <IAsyncCacheStore>(); store.StoreId.Returns(1000); var objCacheItem = new WebApiCacheItem { MaxAge = 5, StaleWhileRevalidate = 5, StoreId = 1000, CreatedTime = DateTime.UtcNow.AddSeconds(-5).AddMilliseconds(-1), }; store.GetAsync(Arg.Any <string>()).Returns(c => { objCacheItem.Key = c.Arg <string>(); return(Task.FromResult((object)objCacheItem)); }); Global.CacheStoreProvider.RegisterAsyncStore(store); var att = new Flatwhite.WebApi.OutputCacheAttribute { MaxAge = 5, CacheStoreId = 1000, StaleWhileRevalidate = 5 }; // Action await att.OnActionExecutingAsync(_actionContext, CancellationToken.None); // Assert Assert.IsTrue(Global.Cache.PhoenixFireCage.ContainsKey(objCacheItem.Key)); }
public async Task Should_call_reborn_on_existing_phoenix_and_try_refresh_cache_when_cache_item_is_stale() { // Arrange var store = Substitute.For<IAsyncCacheStore>(); store.StoreId.Returns(1000); var objCacheItem = new WebApiCacheItem { MaxAge = 5, StaleWhileRevalidate = 5, StoreId = 1000, CreatedTime = DateTime.UtcNow.AddSeconds(-5).AddMilliseconds(-1), }; var existingPhoenix = Substitute.For<WebApiPhoenix>(_invocation, objCacheItem, _request); existingPhoenix.When(x => x.Reborn()).Do(c => { Global.Cache.PhoenixFireCage.Remove(objCacheItem.Key); }); store.GetAsync(Arg.Any<string>()).Returns(c => { objCacheItem.Key = c.Arg<string>(); Global.Cache.PhoenixFireCage[objCacheItem.Key] = existingPhoenix; return Task.FromResult((object)objCacheItem); }); Global.CacheStoreProvider.RegisterAsyncStore(store); var att = new Flatwhite.WebApi.OutputCacheAttribute { MaxAge = 5, CacheStoreId = 1000, StaleWhileRevalidate = 5 }; // Action await att.OnActionExecutingAsync(_actionContext, CancellationToken.None); // Assert existingPhoenix.Received(1).Reborn(); }
public async Task Should_call_reborn_on_existing_phoenix_and_try_refresh_cache_when_cache_item_is_stale() { // Arrange var store = Substitute.For <IAsyncCacheStore>(); store.StoreId.Returns(1000); var objCacheItem = new WebApiCacheItem { MaxAge = 5, StaleWhileRevalidate = 5, StoreId = 1000, CreatedTime = DateTime.UtcNow.AddSeconds(-5).AddMilliseconds(-1), }; var existingPhoenix = Substitute.For <WebApiPhoenix>(_invocation, objCacheItem, _request); existingPhoenix.When(x => x.Reborn()).Do(c => { Global.Cache.PhoenixFireCage.Remove(objCacheItem.Key); }); store.GetAsync(Arg.Any <string>()).Returns(c => { objCacheItem.Key = c.Arg <string>(); Global.Cache.PhoenixFireCage[objCacheItem.Key] = existingPhoenix; return(Task.FromResult((object)objCacheItem)); }); Global.CacheStoreProvider.RegisterAsyncStore(store); var att = new Flatwhite.WebApi.OutputCacheAttribute { MaxAge = 5, CacheStoreId = 1000, StaleWhileRevalidate = 5 }; // Action await att.OnActionExecutingAsync(_actionContext, CancellationToken.None); // Assert existingPhoenix.Received(1).Reborn(); }
public async Task Should_create_phoenix_and_try_refresh_cache_when_cache_item_is_stale() { // Arrange var store = Substitute.For<IAsyncCacheStore>(); store.StoreId.Returns(1000); var objCacheItem = new WebApiCacheItem { MaxAge = 5, StaleWhileRevalidate = 5, StoreId = 1000, CreatedTime = DateTime.UtcNow.AddSeconds(-5).AddMilliseconds(-1), }; store.GetAsync(Arg.Any<string>()).Returns(c => { objCacheItem.Key = c.Arg<string>(); return Task.FromResult((object)objCacheItem); }); Global.CacheStoreProvider.RegisterAsyncStore(store); var att = new Flatwhite.WebApi.OutputCacheAttribute { MaxAge = 5, CacheStoreId = 1000, StaleWhileRevalidate = 5 }; // Action await att.OnActionExecutingAsync(_actionContext, CancellationToken.None); // Assert Assert.IsTrue(Global.Cache.PhoenixFireCage.ContainsKey(objCacheItem.Key)); }