Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 来自控制器方法的FileContentResult null_C#_Asp.net Mvc - Fatal编程技术网

C# 来自控制器方法的FileContentResult null

C# 来自控制器方法的FileContentResult null,c#,asp.net-mvc,C#,Asp.net Mvc,我的控制器中有以下方法: [HttpGet] public ActionResult Process(int id) { var file = ServiceUtilities.FileManager.GetFile(id); if (file != null) { var fcr = new FileConte

我的控制器中有以下方法:

        [HttpGet]
        public ActionResult Process(int id)
        {
                var file = ServiceUtilities.FileManager.GetFile(id);

                if (file != null)
                {
                    var fcr = new FileContentResult(new byte[1], @"Image\Gif");
                    return fcr;
                }

                return RedirectToAction("Index", "Error");
        }
我在单元测试中调用此代码,如下所示:

var response =
            new Controllers.FileController().Process(1) as FileStreamResult;


Assert.IsNotNull(response);
然而,响应总是空的。如果在控制器代码中的
fcr
上设置断点,则该断点不为空


为了澄清,
file
是一个模拟对象,并且不是空的。

我可能遗漏了一些东西,但是
FileContentResult
(您从方法返回的内容)不是
FileStreamResult
(您在测试中强制转换它的内容)。它们都继承自
FileResult
,但为了让测试通过,
FileContentResult
需要继承自
FileStreamResult


或者这是一种错误的类型?

不,只是我在这么晚的时候变成了一个白痴!英雄联盟我们都去过那里@ChrisBint。约翰,希望你能得到更多的分数,并能通过评论tooDave做出贡献,是的!我终于可以发表评论了。说明。谢谢!:)