6

I have a unit test that worked fine in MVC2. The test simply defines the Action on the controller, the necessary stubs, and tests the name of the view. However, after upgrading to MVC3, when I invoke the method, I get the error above. The site MVC3 upgrade works just fine; I just have these unit tests failing due to the upgrade. Thanks.

Here's my action:

public partial class GadgetController
{
    [SetterProperty]
    public IATCGadgetProxy ATCGadgetService { get; set; }

    public ActionResult LoadForums(bool popularOnly, bool myThreads, int itemCount)
    {
        var model = ATCGadgetService.LoadForums(popularOnly, myThreads, itemCount);

        return View("AskTheCommunity-Forums", model);
    }
}

Here's the test. It is failing when it's returning the view from the Action.

[TestMethod]
public void Test_Forums_Action_Type()
{
    GadgetController controller = new GadgetController();
    controller.ATCGadgetService = new ATCGadgetServiceStub();
    ViewResult result = controller.LoadForums(false, false, 10) as ViewResult;

    Assert.IsNotNull(result);
    Assert.AreEqual("AskTheCommunity-Forums", result.ViewName);
}
1
  • 1
    Please show the code you are trying to test as well as your test. At its current state your question is difficult to answer. Commented Jul 14, 2011 at 19:02

2 Answers 2

4

I know this is an old thread but I just got the same error with MVC 5.2.3... but using Xunit. In the end, it does not really matter as the way to solve the issue would be the same.

First, you have to make sure MVC was added to your Tests project. I added it via NuGet:

Install-Package Microsoft.AspNet.Mvc -Version 5.2.3

Or you can alter the version to whatever MVC version you are using.

Then, I was still having the error. I just found out that the App.config page was missing information. Once I made sure I had these lines, everything worked:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

    <!-- Other config here -->

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

3

One of the things that drove me crazy upgrading a project to MVC 3 was these odd, unexplained errors. Until I figured that not all of the projects were upgraded to MVC 3 (in your case - that might be the test project) and remained in MVC 2, which caused some very weird behaviors like the one you describe. Please check the version of System.Web.Mvc (and possibly related assemblies) in your test project.

2 Comments

@Ryan did it help you? You haven't given any feedback.
This was the case when I was compiling a project with a reference to MVC 4 and then deploying to a website that had MVC 3. I changed the reference to MVC 3 and things started working. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.