TestHelper problem

21 views
Skip to first unread message

kwilder

unread,
Sep 16, 2009, 12:16:21 PM9/16/09
to mvccontrib-discuss
I'm attempting to use the TestHelper classes to test the routes and
they don't work.

I've even tried the sample test helper application that came with
MvcContrib and they also don't work.

I have Rhino Mocks 3.5 and NUnit 2.4.6. What am I missing?

When I run this test:

"~/".Route().ShouldMapTo<HomeController>();

... I get this exception message:

Test_Route_To_KitController_And_Tags_Action_Method'
failed: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an
instance of an object.
at MvcContrib.TestHelper.RouteTestingExtensions.ShouldMapTo
[TController](RouteData routeData)
C:\WebProjects\MyCentral\MyCentral.UnitTests\KitTests\KitTests.cs
(402,0): at
MyCentral.UnitTests.KitTests.KitTests.Test_Route_To_KitController_And_Tags_Action_Method
()


0 passed, 1 failed, 0 skipped, took 0.63 seconds.

Any ideas?

Jeremy Skinner

unread,
Sep 16, 2009, 12:49:03 PM9/16/09
to mvccontri...@googlegroups.com
Could you post the rest of your test class?

Thanks

Jeremy

2009/9/16 kwilder <kaha...@gmail.com>

Ben Scheirman

unread,
Sep 16, 2009, 2:06:52 PM9/16/09
to mvccontri...@googlegroups.com
It might help to step through the code.

Are you running the latest? we've recently upgraded to RM 3.6, but I don't think that's your issue.

Jeremy Skinner

unread,
Sep 19, 2009, 1:51:47 PM9/19/09
to kwilder, mvccontri...@googlegroups.com
[Replied to the list]

I can't reproduce this. I used your TestFixtureSetUp code along with the test that you initially posted and the test passes. For reference, this is the complete test class I used:

[TestFixture]
    public class RouteTest
    {
         [TestFixtureSetUp]
       public void FixtureSetup()
       {
           RouteTable.Routes.Clear();

           RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           RouteTable.Routes.MapRoute("KitsByTag", "Kit/Tags/{tagname}",
               new { controller = "Kit", action = "Tags", tagname = "" });

           RouteTable.Routes.MapRoute("KitAuthorFilter", "Kit/ AuthorIndex/{authorid}",
               new { controller = "Kit", action = "AuthorIndex", authorid = "" });

           RouteTable.Routes.MapRoute("KitSEOFriendly", "Kit/Details/{title}",
               new { controller = "Kit", action = "Details", title = "" });

           RouteTable.Routes.MapRoute("Default", "{controller}/{action}/{id}",
               new { controller = "Home", action = "Index", id = "" });

       }

        [Test]
        public void Default_route()
        {
            "~/".Route().ShouldMapTo<HomeController>();
        }
    }

Jeremy

2009/9/19 kwilder <kaha...@gmail.com>
Sorry I'm late, I've been crushed on trying to finish this app.

Here's my FixtureSetup that contains the routes.

       [TestFixtureSetUp]
       public void FixtureSetup()
       {
           RouteTable.Routes.Clear();

           RouteTable.Routes.IgnoreRoute("{resource}.axd/
{*pathInfo}");

           RouteTable.Routes.MapRoute("KitsByTag", "Kit/Tags/
{tagname}", new { controller = "Kit", action = "Tags", tagname =
"" });
           RouteTable.Routes.MapRoute("KitAuthorFilter", "Kit/
AuthorIndex/{authorid}", new { controller = "Kit", action =
"AuthorIndex", authorid = "" });
           RouteTable.Routes.MapRoute("KitSEOFriendly", "Kit/Details/
{title}", new { controller = "Kit", action = "Details", title = "" });

           RouteTable.Routes.MapRoute("Default", "{controller}/
{action}/{id}", new { controller = "Home", action = "Index", id =
"" });

       }

Once I added this I wasn't getting the same error.  Now I'm getting
the error about the URL not matching any route.

TestCase
'M:MyCentral.UnitTests.KitTests.KitTests.Test_Route_To_KitController_And_Create_Action'
failed: The URL did not match any route
       MVCContrib.TestHelper.AssertionException: The URL did not match any
route
       at MVCContrib.TestHelper.RouteTestingExtensions.ShouldMapTo
[TController](RouteData routeData, Expression`1 action)

       C:\WebProjects\MyCentral\MyCentral.UnitTests\KitTests\KitTests.cs
(519,0):
               at
MyCentral.UnitTests.KitTests.KitTests.Test_Route_To_KitController_And_Create_Action
()

The weird thing about this is that it shows this error in the
TestDriven.Net VS 2008 addin but in the NUnit 2.5.1 GUI, it shows all
green.

Any thoughts?


On Sep 16, 9:49 am, Jeremy Skinner <jer...@jeremyskinner.co.uk> wrote:
> Could you post the rest of your test class?
>
> Thanks
>
> Jeremy
>
> 2009/9/16 kwilder <kahan...@gmail.com>

King Wilder

unread,
Sep 19, 2009, 7:11:53 PM9/19/09
to Jeremy Skinner, mvccontri...@googlegroups.com

Jeremy,

 

Just curious, does it pass in the NUnit GUI?  It passes for me there also, but not in the TestDriven.Net VS addin.  It returns the “Url doesn’t match any route” exception.  Do you think I should trust the NUnit GUI and not the TestDriven.Net addin?

 

Thanks.

 

King Wilder

kaha...@gmail.com

Jeremy Skinner

unread,
Sep 20, 2009, 4:10:29 AM9/20/09
to King Wilder, mvccontri...@googlegroups.com
This passes for me using the nunit runner, TestDriven and the R# runner.

Jeremy

2009/9/20 King Wilder <kaha...@gmail.com>

Eric Hexter

unread,
Sep 20, 2009, 7:39:42 AM9/20/09
to mvccontri...@googlegroups.com
If you are getting varying results through the test runners I would recomend making sure you have the latest version of the TestDriven.Net Addin. I have had this problem with the test runners before.  It get even worse when you start using build scripts that each implmenet their own version of the nunit test runner.

King Wilder

unread,
Sep 20, 2009, 12:19:33 PM9/20/09
to Jeremy Skinner, mvccontri...@googlegroups.com

Jeremy,

 

Ok, then there’s something wrong with one of those installations on my machine.  I’ll check it out.

 

Thanks,

 

King Wilder

Kaha...@gmail.com

King Wilder

unread,
Sep 20, 2009, 12:29:02 PM9/20/09
to Jeremy Skinner, mvccontri...@googlegroups.com

Jeremy,

 

One last thing and I’ll leave you alone.

 

I just tried moving the routes into my unit test method (and out of the FixtureSetup) and it passes using TestDriven.net.  Any ideas why this happens?

 

I’m using NUnit 2.5.1 and I have the using statement in the test class.

 

using NUnit.Framework

 

Could it be some conflict in my Windows Vista Ultimate SP1 installation?

 

Thanks,

 

King Wilder

Kaha...@gmail.com

 

 

From: jeremy....@gmail.com [mailto:jeremy....@gmail.com] On Behalf Of Jeremy Skinner


Sent: Sunday, September 20, 2009 1:10 AM

Jeremy Skinner

unread,
Sep 20, 2009, 12:32:18 PM9/20/09
to King Wilder, mvccontri...@googlegroups.com
Are you running the latest TestDriven.NET? I installed 2.23.2497

King Wilder

unread,
Sep 20, 2009, 12:39:04 PM9/20/09
to Jeremy Skinner, mvccontri...@googlegroups.com

No, I’m using an older Free Personal version (before he started charging for it), v2.9.2150.  That’s probably the reason.

Jeremy Skinner

unread,
Sep 20, 2009, 12:41:12 PM9/20/09
to King Wilder, mvccontri...@googlegroups.com
The personal version is still free - I'd recommend upgrading to the latest.

King Wilder

unread,
Sep 20, 2009, 1:44:14 PM9/20/09
to Jeremy Skinner, mvccontri...@googlegroups.com

I’ll do that.

Reply all
Reply to author
Forward
0 new messages