Search Results

Search found 2 results on 1 pages for 'hellfire'.

Page 1/1 | 1 

  • How do I Unit Test Actions without Mocking that use UpdateModel?

    - by Hellfire
    I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC Beta 1. In it he shows the improvements made to the UpdateModel method and how they improve unit testing. I have recreated a similar project however anytime I run a UnitTest that contains a call to UpdateModel I receive an ArgumentNullException naming the controllerContext parameter. Here's the relevant bits, starting with my model: public class Country { public Int32 ID { get; set; } public String Name { get; set; } public String Iso3166 { get; set; } } The controller action: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Int32 id, FormCollection form) { using ( ModelBindingDataContext db = new ModelBindingDataContext() ) { Country country = db.Countries.Where(c => c.CountryID == id).SingleOrDefault(); try { UpdateModel(country, form); db.SubmitChanges(); return RedirectToAction("Index"); } catch { return View(country); } } } And finally my unit test that's failing: [TestMethod] public void Edit() { CountryController controller = new CountryController(); FormCollection form = new FormCollection(); form.Add("Name", "Canada"); form.Add("Iso3166", "CA"); var result = controller.Edit(2 /*Canada*/, form) as RedirectToRouteResult; Assert.IsNotNull(result, "Expected to be redirected on successful POST."); Assert.AreEqual("Show", result.RouteName, "Expected to redirect to the View action."); } ArgumentNullException is thrown by the call to UpdateModel with the message "Value cannot be null. Parameter name: controllerContext". I'm assuming that somewhere the UpdateModel requires the System.Web.Mvc.ControllerContext which isn't present during execution of the test. I'm also assuming that I'm doing something wrong somewhere and just need to pointed in the right direction. Help Please!

    Read the article

  • When debugging in VS 2008 why does the debugger land on a second return statement?

    - by Hellfire
    When debugging the following console program: class Program { static void Main(string[] args) { Console.WriteLine(DoIt(false)); Console.WriteLine(DoIt(true)); } private static Boolean DoIt(Boolean abort) { try { throw new InvalidOperationException(); } catch(Exception ex) { if (abort) { return true; } Console.WriteLine("Got here"); return false; } } } Why does the IDE land on the second return statement during the second call to DoIt()? The results of the execution is correct but the debugging experience is misleading. Is this a known issue? Is the behavior in VS 2010 the same?

    Read the article

1