public async Task When_FilterCalledWithoutCached_Then_SetObjectCached_Test(string method, string path, string queryString) { Configuration .SetupGet(d => d.CurrentValue).Returns(GetConfiguration("Default".Split(","))); CachedByConfigurationAttribute = new CachedByConfigurationAttribute( ResponseCacheServiceMock.Object, Configuration.Object ); var expectedValue = new { prop1 = "teste" }; ActionExecutionDelegateMock .Setup(d => d.Invoke()) .ReturnsAsync( SetActionExecutedContext(expectedValue) ); HttpContext.Request.Method = method; HttpContext.Request.Path = path; HttpContext.Request.QueryString = new QueryString(queryString); //Act await CachedByConfigurationAttribute.OnActionExecutionAsync(Context, ActionExecutionDelegateMock.Object); ResponseCacheServiceMock.Verify_GetCachedResponseAsStringAsync(Times.Once()); ResponseCacheServiceMock.Verify_SetCacheResponseAsync(Times.Once()); var storedValue = await ResponseCacheServiceMock.Object.GetCachedResponseAsStringAsync($"{path}|{BuildValuesFromQueryString(HttpContext)}"); Assert.Equal(JsonSerializer.Serialize(expectedValue), storedValue); }
public async Task When_FilterCalledWithoutCached2_Then_SetObjectCached_Test(string method, string path, string queryString) { Configuration .SetupGet(d => d.CurrentValue).Returns(GetConfiguration("Default".Split(","))); CachedByConfigurationAttribute = new CachedByConfigurationAttribute( ResponseCacheServiceMock.Object, Configuration.Object ); object expectedValue = null; ActionExecutionDelegateMock .Setup(d => d.Invoke()) .ReturnsAsync( SetActionExecutedContext(expectedValue) ); HttpContext.Request.Method = method; HttpContext.Request.Path = path; HttpContext.Request.QueryString = new QueryString(queryString); //Act await CachedByConfigurationAttribute.OnActionExecutionAsync(Context, ActionExecutionDelegateMock.Object); ResponseCacheServiceMock.Verify_GetCachedResponseAsStringAsync(Times.Once()); ResponseCacheServiceMock.Verify_SetCacheResponseAsync(Times.Never()); }
public async Task When_FilterCalledAndNotGetMethod_Then_NotProcess_Test(string method, string path) { Configuration .SetupGet(d => d.CurrentValue).Returns(GetConfiguration("Default".Split(","))); CachedByConfigurationAttribute = new CachedByConfigurationAttribute( ResponseCacheServiceMock.Object, Configuration.Object ); var expectedValue = new { prop1 = "teste" }; ActionExecutionDelegateMock .Setup(d => d.Invoke()) .ReturnsAsync( SetActionExecutedContext(expectedValue) ); HttpContext.Request.Method = method; HttpContext.Request.Path = path; //Act await CachedByConfigurationAttribute.OnActionExecutionAsync(Context, ActionExecutionDelegateMock.Object); ResponseCacheServiceMock.Verify_GetCachedResponseAsStringAsync(Times.Never()); ResponseCacheServiceMock.Verify_SetCacheResponseAsync(Times.Never()); }
public async Task When_FilterCalled_Then_RemoveAllCachedPattern_Test(string method, string path, string patternRemove) { Configuration .SetupGet(d => d.CurrentValue) .Returns(GetConfiguration(new Dictionary <string, string>() { { path, patternRemove } })); CachedRemoveByConfigurationAttribute = new CachedRemoveByConfigurationAttribute( ResponseCacheServiceMock.Object, Configuration.Object ); var expectedValue = new { prop1 = "teste" }; ActionExecutionDelegateMock .Setup(d => d.Invoke()) .ReturnsAsync( SetActionExecutedContext(expectedValue) ); HttpContext.Request.Method = method; HttpContext.Request.Path = path; //Act await CachedRemoveByConfigurationAttribute.OnActionExecutionAsync(Context, ActionExecutionDelegateMock.Object); ResponseCacheServiceMock.Verify_GetKeysByPattern(Times.Once(), patternRemove); ResponseCacheServiceMock.Set_RemoveCachedResponseByNameAsync(Times.Once()); }