예제 #1
0
        public async Task When_FilterCalledWithoutCached_Then_SetObjectCached_Test(string method, string path, string queryString)
        {
            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 CachedAttribute.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);
        }