コード例 #1
0
        public void SetResponse_ActionResultConverted_Succeeded()
        {
            FieldInfo fieldInfo = typeof(HttpBinding).GetField("isActionResultHandlingEnabled", BindingFlags.NonPublic | BindingFlags.Static);
            bool      oldValue  = (bool)fieldInfo.GetValue(null);

            fieldInfo.SetValue(null, true);

            try
            {
                var httpContext1 = new DefaultHttpContext();
                ActionResult <string> result1 = new ActionResult <string>("test");
                HttpBinding.SetResponse(httpContext1.Request, result1);
                Assert.Equal("test", ((ObjectResult)httpContext1.Request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey]).Value);

                var httpContext2 = new DefaultHttpContext();
                ActionResult <DummyClass> result2 = new ActionResult <DummyClass>(new DummyClass {
                    Value = "test"
                });
                HttpBinding.SetResponse(httpContext2.Request, result2);
                var resultObject = ((ObjectResult)httpContext2.Request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey]).Value;
                Assert.IsType <DummyClass>(resultObject);
                Assert.Equal("test", ((DummyClass)resultObject).Value);
            }
            finally
            {
                fieldInfo.SetValue(null, oldValue);
            }
        }
コード例 #2
0
        public void SetResponse_ActionResultGeneric_Succeeded()
        {
            var httpContext1 = new DefaultHttpContext();
            ActionResult <string> result1 = new ActionResult <string>("test");

            HttpBinding.SetResponse(httpContext1.Request, result1);
            var resultObject1 = ((ObjectResult)httpContext1.Request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey]).Value;

            Assert.IsType <ActionResult <string> >(resultObject1);
            Assert.Equal("test", (resultObject1 as ActionResult <string>).Value);

            var httpContext2 = new DefaultHttpContext();
            ActionResult <DummyClass> result = new ActionResult <DummyClass>(new DummyClass {
                Value = "test"
            });

            HttpBinding.SetResponse(httpContext2.Request, result);
            var resultObject2 = ((ObjectResult)httpContext2.Request.HttpContext.Items[ScriptConstants.AzureFunctionsHttpResponseKey]).Value;

            Assert.IsType <ActionResult <DummyClass> >(resultObject2);
            Assert.Equal("test", (resultObject2 as ActionResult <DummyClass>).Value.Value);
        }