I'm working on a unit test in a project using the MOQ-framework, C# 4.0, MVC2.0
The test is similar to the one below. But as soon as i run this test i'm getting a strange error. I've checked all the referenced System.Web.mvc assemblies and there all at version 2.0.0, so it seems to me that those can't cause the issue.
[TestMethod]
public void PaymentStepOne_Should_Return_RedirectUrl_Because_CustomerId_In_Session_Is_Null()
{
var _mockFrontendWebshopController2 = new Mock<FrontendWebshopController>
(
_mockCartItemService.Object, _mockCartService.Object,
_mockOrderService.Object, _mockCustomerService.Object,
_mockVariantService.Object, _mockShippingCostService.Object,
_mockNodeService.Object, _mockPageSettingService.Object,
_mockUserProfileService.Object) { CallBase = true };
var config = ConfigurationManagerHelper.GetConfigurationManager(new DefaultSettings());
_mockFrontendWebshopController2.Setup(x => x.GetConfigurationManager()).Returns(config);
var webshopController = _mockFrontendWebshopController2.Object;
webshopController.SetFakeControllerContext();
webshopController.Response.Redirect("http://www.google.nl");
var idToUse = Guid.NewGuid();
var collection = new FormCollection { { "Id", idToUse.ToString() }, { "Amount_" + idToUse, "99" } };
var actual = (RedirectResult)webshopController.PaymentStepOne(collection);
Assert.AreEqual("http://www.google.nl", actual.Url);
}
I'm expecting the method to return an URL in this scenario which is supposed to be stored in the variable called 'actual'. But whenever i run the test i'm getting the following error message;
Test method Plugin.Webshop.Tests.FrontendWebshopControllerTest.PaymentStepOne_Should_Return_RedirectUrl_Because_CustomerId_In_Session_Is_Null threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Het systeem kan het opgegeven bestand niet vinden.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\QTAgent32.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = rob
LOG: DisplayName = System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Projects/Website_v1\SITE/TestResults/WSRob 2010-08-20 14_00_26/Out
LOG: Initial PrivatePath = NULL
Calling assembly : Plugin.Webshop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\IWES5\IWES\TestResults\WSRob 2010-08-20 14_00_26\Out\Plugin.Webshop.Tests.DLL.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Projects/Website_v1\SITE/TestResults/WSRob 2010-08-20 14_00_26/Out/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Website_v1\SITE/TestResults/WSRob 2010-08-20 14_00_26/Out/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Website_v1\SITE/TestResults/WSRob 2010-08-20 14_00_26/Out/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/Projects/Website_v1\SITE/TestResults/WSRob 2010-08-20 14_00_26/Out/System.Web.Mvc/System.Web.Mvc.EXE.
This error occures when the function which i want to test is being called, so it happens as soon as the following rule is being hit by the test;
var actual = webshopController.PaymentStepOne(collection);
Together with the error message i'm getting the following Stack Trace
Plugin.Webshop.Controllers.FrontendWebshopController.PaymentStepOne(FormCollection collection)
FrontendWebshopControllerProxy3eebc7d7c86c40848deab621477897c6.InvocationPaymentStepOne_9.InvokeMethodOnTarget()
Castle.DynamicProxy.AbstractInvocation.Proceed()
Moq.Interceptor.Intercept(IInvocation invocation)
Castle.DynamicProxy.AbstractInvocation.Proceed()
FrontendWebshopControllerProxy3eebc7d7c86c40848deab621477897c6.PaymentStepOne(FormCollection collection)
Plugin.Webshop.Tests.FrontendWebshopControllerTest.PaymentStepOne_Should_Return_RedirectUrl_Because_CustomerId_In_Session_Is_Null() in C:\Projects\Website_v1\SITE\Plugin.Webshop.Tests\FrontendWebshopControllerTest.cs: line 197
Please help out by finding the cause of this error, and resolving it.