mvccontrib-testhelper

Issue with MvcContrib TestHelper Fluent Route Testing and Specific HttpVerbs

ぐ巨炮叔叔 提交于 2020-01-11 10:48:42
问题 I'm attempting to use the MvcContrib TestHelper fluent route testing API, but I'm seeing odd behavior. The .WithMethod(HttpVerb) extension method does not seem to be executing as expected. Here's my controller showing (2) actions (identically named) that accept different HttpVerbs: [HttpGet] public ActionResult IdentifyUser() { return View(new IdentifyUserViewModel()); } [HttpPost] public ActionResult IdentifyUser(IdentifyUserInputModel model) { return null; } And here is the test that should

Trying to stub Server.MapPath with MvcContrib Test helpers and Rhino Mocks 3.5

和自甴很熟 提交于 2020-01-05 08:27:27
问题 I'm using MvcContrib's test helpers and Rhino Mocks 3.5 to test an ASP.NET MVC action method. I build my fake controller like so: var _builder = new TestControllerBuilder(); _builder.InitializeController(_controller); So I get a fake controller that contains fake HTTP Server etc. I'm then trying to stub the Server.MapPath method like so controller.Server.Stub(x => x.MapPath(Arg<string>.Is.Anything)).Return("/APP_DATA/Files/"); but in my method under test the call to Server.MapPath("/APP_DATA

Error using MVCContrib TestHelper

你说的曾经没有我的故事 提交于 2020-01-01 15:03:13
问题 While trying to implement the second answer to a previous question, I am receiving an error. I have implemented the methods just as the post shows, and the first three work properly. The fourth one (HomeController_Delete_Action_Handler_Should_Redirect_If_Model_Successfully_Delete) gives this error: Could not find a parameter named 'controller' in the result's Values collection. If I change the code to: actual .AssertActionRedirect() .ToAction("Index"); it works properly, but I don't like the

Using MVCContrib.TestHelpers with MsTest - is there any way to get nicer fail messages?

假装没事ソ 提交于 2019-12-13 16:13:24
问题 I'm just starting to use MVCContrib, and I'm really liking the syntactic sugar it adds to various test scenarious. For example, I just wrote this assertion: "~/".Route().ShouldMapTo<SpotController>(c => c.List()); It's brilliant! Well, almost... Instead of, as I'd like, seeing the actual reason why the test fails (I've changed nothing in my MVC application, so that should route to HomeController.Index() ) I get the generic message about an exception being thrown during test execution. This is

Newbie question on MvcContrib TestHelpers

两盒软妹~` 提交于 2019-12-12 10:09:12
问题 I'm just starting to use the TestHelpers in MvcContrib. I want to try and test an action method on my controller that itself tests if IsAjaxRequest() is true. I've used the same code that is shown in the TestHelper samples to set up the TestControllerBuilder _controller = new StarsController(); _builder = new TestControllerBuilder(); _builder.InitializeController(_controller); So that _controller has all the faked/mocked HttpContext inside it, which is really great. But what do I do now to

Mvcontrib.MVC3.Testhelper UpdateModel NullReferenceExceuption during Unit Test

自闭症网瘾萝莉.ら 提交于 2019-12-09 19:52:43
问题 I am trying to unit test an edit action on my controller in ASP.NET MVC 3. I have installed Mvcontrib.MVC3.TestHelper via nuget to mock out my controller Context but I am still getting a NullReferenceException my code looks like this: [TestMethod] public void it_should_redirect_to_index_after_editing_a_something_successfully() { var something= new SomeThing { ID = Guid.NewGuid(), CreatedAt = DateTime.Now, LastModified = DateTime.Now, Owner = "Me", Status = "new", Title = "my Title",

Attempted to read or write protected memory

浪子不回头ぞ 提交于 2019-12-08 06:16:55
问题 I have a sample ASP.NET MVC 3 web application that is following Jonathan McCracken's Test-Drive Asp.NET MVC (great book , by the way) and I have stumbled upon a problem. Note that I'm using MVCContrib, Rhino and NUnit. [Test] public void ShouldSetLoggedInUserToViewBag() { var todoController = new TodoController(); var builder = new TestControllerBuilder(); builder.InitializeController(todoController); builder.HttpContext.User = new GenericPrincipal(new GenericIdentity("John Doe"), null);

Newbie question on MvcContrib TestHelpers

匆匆过客 提交于 2019-12-06 08:04:23
I'm just starting to use the TestHelpers in MvcContrib. I want to try and test an action method on my controller that itself tests if IsAjaxRequest() is true. I've used the same code that is shown in the TestHelper samples to set up the TestControllerBuilder _controller = new StarsController(); _builder = new TestControllerBuilder(); _builder.InitializeController(_controller); So that _controller has all the faked/mocked HttpContext inside it, which is really great. But what do I do now to force IsAjaxRequest() on the internally faked Request object to return true? You need to stub out the

After using Automapper to map a ViewModel how and what should I test?

社会主义新天地 提交于 2019-12-03 03:56:24
问题 I am attempting to test the Index action of a controller. The action uses AutoMapper to map a domain Customer object to a view model TestCustomerForm . While this works I am concerned about the best way to test the results that I am receiving from the Index action. The controller's index action looks like this: public ActionResult Index() { TestCustomerForm cust = Mapper.Map<Customer, TestCustomerForm>(_repository.GetCustomerByLogin(CurrentUserLoginName)); return View(cust); } And its

After using Automapper to map a ViewModel how and what should I test?

时光毁灭记忆、已成空白 提交于 2019-12-02 17:19:51
I am attempting to test the Index action of a controller. The action uses AutoMapper to map a domain Customer object to a view model TestCustomerForm . While this works I am concerned about the best way to test the results that I am receiving from the Index action. The controller's index action looks like this: public ActionResult Index() { TestCustomerForm cust = Mapper.Map<Customer, TestCustomerForm>(_repository.GetCustomerByLogin(CurrentUserLoginName)); return View(cust); } And its TestMethod looks like this: [TestMethod] public void IndexShouldReturnCustomerWithMachines() { // arrange var