1
votes

I have unit tests and inside them I call a method that eventually calls this line:

DataSourceResult response = lstshiftGroup.ToDataSourceResult(request);

Which throws this exception:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

In my test project I have reference of System.Web.Mvc, Version=4.0.0.0 and in my project I have the same assembly.

What is wrong with my test?

1
what unit testing framework are you using?Sam Holder
I literally just had this problem 2 seconds ago. I ran updates on my NuGet packages (after installing ASP.NET MVC from NuGet in my UnitTest project) on both my web project and my Unit test project and now it worksRobert Snyder
@SamHolder Vs.Net 2013 C#Shahram
are you using the default MSTest framework? your not using NUnit or XUnit? And are the dlls for System.Web.Mvc.dll in the output folder of the tests?Sam Holder
yes im using default framework and dll is on the references of test solutionShahram

1 Answers

3
votes

You need to add reference to Asp.Net MVC to your Unit Test project. You can do this with NuGet. Here is the link to NuGet for MVC. Follow the instructions there to install it into your Unit Test project: https://www.nuget.org/packages/aspnetmvc