4

Looked for a method on the MvcContrib.TestHelper.RouteTestingExtensions class named ShouldNotMap. There is ShouldBeIgnored, but I don't want to test an IgnoreRoute invocation. I want to test that a specific incoming route should not be mapped to any resource.

Is there a way to do this using MvcContrib TestHelper?

Update

Just tried this, and it seems to work. Is this the correct way?

"~/do/not/map/this".Route().ShouldBeNull();
danludwig
  • 46,965
  • 25
  • 159
  • 237
  • I didn't find a ShouldBeNull() method. Instead I had to do "~/do/not/map/this".Route().ShouldEqual(null, ""); – JNappi Jul 26 '12 at 15:24

2 Answers2

1

I think you are looking for the following:

"~/do/not/map/this".ShouldBeIgnored();

Behind the scenes this asserts that the route is processed by StopRoutingHandler.

Ben Griswold
  • 17,793
  • 14
  • 58
  • 60
0

I was looking for the same thing. I ended up adding the following extension methods to implement ShouldBeNull and the even shorter ShouldNotMap:

In RouteTestingExtensions.cs:

    /// <summary>
    /// Verifies that no corresponding route is defined.
    /// </summary>
    /// <param name="relativeUrl"></param>
    public static void ShouldNotMap(this string relativeUrl)
    {
        RouteData routeData = relativeUrl.Route();
        routeData.ShouldBeNull(string.Format("URL '{0}' shouldn't map.", relativeUrl));
    }

    /// <summary>
    /// Verifies that the <see cref="RouteData">routeData</see> is null.
    /// </summary>
    public static void ShouldNotMap(this RouteData routeData)
    {
        routeData.ShouldBeNull("URL should not map.");
    }

In GeneralTestExtensions.cs :

    ///<summary>
    /// Asserts that the object should be null.
    ///</summary>
    ///<param name="actual"></param>
    ///<param name="message"></param>
    ///<exception cref="AssertFailedException"></exception>
    public static void ShouldBeNull(this object actual, string message)
    {
        if (actual != null)
        {
            throw new AssertFailedException(message);
        }
    }
marapet
  • 54,856
  • 12
  • 170
  • 184