VS2015单元测试项目无法找到方法。

3
我将翻译如下内容:

我遇到了这个错误:

结果堆栈跟踪:在 UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch() Result Message: 测试方法 UnitTestProject.ControllerTest.TestMethodQuoteEndCustomerSearch 抛出异常:System.MissingMethodException: 找不到方法:'System.Web.Mvc.ActionResult QuoteCenter.Controllers.ECSearchController.QuoteEndCustomerSearch(System.String, System.String, System.String, System.String)'。

我的测试类看起来像这样:

namespace UnitTestProject
{
    [TestClass]
    public class ControllerTest
    {
        [TestMethod]
        public void TestMethodQuoteEndCustomerSearch()
        {
        //arrange
        ECSearchController myController = new ECSearchController();           

        //ISSUE WITH THE NEXT LINE
        ViewResult result = myController .QuoteEndCustomerSearch("", "", "", "") as ViewResult;
        }
    }
}

智能感知知道我的控制器有一个名为QuoteEndCustomerSearch的方法。但是当我调试时,我会收到上述错误。
控制器的方法如下所示:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult QuoteEndCustomerSearch(String quoteId, String CID, String URL, String UserID)
    { 
        //...
        return View("QuoteEndCustomerSearch", model);
    }

有什么其他建议吗?我已经在管理员模式下,并且重新启动了VS2015,但还是无法正常工作。


1
如果视图的名称与操作相同,则无需在“View()”中包含它。将“return View(“QuoteEndCustomerSearch”,model);”更改为返回View(model); - Nkosi
谢谢Nkosi提供的有用提示。 - Sniipe
1个回答

3
问题在于我的现有项目使用了MVC 5版本,但新的测试项目使用了更新的版本。现在一切都好了。 当我使用Nuget时,没有注意到版本不同。 我认为现在是一个很好的时机,将所有项目更新到最新的MVC版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接