Howdy,
I just upgraded my little playground web app to Preview 2. I wrote alot of code using the first preview, so it's taken me an hour or two to completely upgrade.
However, my controller tests fail :( Reliably, it's the controller tests that are asserting that RedirectToAction was called.
Cos preview 2 supports controller mocking, I ditched the sub-class testing patterny thing and opted for the mocking.
Here's one of my controller actions that uses RedirectToAction:
1 public void Create(string Message) {
2
3 if (String.IsNullOrEmpty(Message)) {
4 throw new ArgumentException("Message cannot be null or empty");
5 }
6
7 var rm = new ReminderMessage();
8 rm.Message = Message;
9
10
11
12 db.ReminderMessages.InsertOnSubmit(rm);
13 db.SubmitChanges();
14
15 RedirectToAction("List" );
16 }
For the ReminderMessagesController
My error unit tests run fine, cos they're exception expecting.
But, my normal operation unit test fails,
[Test]
[RollBack]
public void CreateNormally()
{
var rmc = Controller();
using (mocks.Record()) {
mocks.SetFakeControllerContext(rmc);
}
using (mocks.Playback()) {
rmc.Create("Sample Message");
}
}
with the MbUnit test execution exception:
| ReminderMessagesControllerTests.SetUp.UpdateMessage |
|
|
|
| Type:System.NotImplementedException | | Message:The method or operation is not implemented. | | Source:System.Web.Abstractions | | TargetSite:Void Redirect(System.String) | | HelpLink:null | StackTrace:
at System.Web.HttpResponseBase.Redirect(String url) at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.Redirect_callback_20(String url) at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.InvocationRedirect_32.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at Rhino.Mocks.Impl.ReplayPartialMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at HttpResponseBaseProxy2ad1c711cecc4e6da524bc5c50bdce13.Redirect(String url) at System.Web.Mvc.Controller.RedirectToAction(RouteValueDictionary values) at System.Web.Mvc.Controller.RedirectToAction(String actionName) at CN.Web.Controllers.ReminderMessagesController.Update(Int32 id) in C:\Projects\CharlesNicholas\CN.Web\Controllers\ReminderMessagesController.cs:line 78 at CN.Web.Test.ReminderMessagesControllerTests.UpdateMessage() in C:\Projects\CharlesNicholas\CN.Web.Test\ReminderMessagesControllerTests.cs:line 141 |
|
|
Woh. that's a deep stack trace. I'm not exactly sure what's going on here, but I bet it has something to do with redirects trying to call a 301 on some part of System.Web that wasn't mocked.
Okay, so how do I mock RedirectToAction when it isn't public? I thought all of these actionable methods were going to be public to avoid the subclass testing patterny thingo - which involved alot of duplicated code.
Does someone know what I'm doing wrong?
Thanks,
-CV