2012-01-25 54 views
4

在名爲ShouldNotMap的MvcContrib.TestHelper.RouteTestingExtensions類中查找方法。 ThereBeIgored,但我不想測試一個IgnoreRoute調用。我想測試一個特定的傳入路由不應該映射到任何資源。使用MvcContrib TestHelper聲明不應映射入站路由

有沒有辦法使用MvcContrib TestHelper來做到這一點?

更新

只是嘗試這樣做,它似乎工作。這是正確的方法嗎?

"~/do/not/map/this".Route().ShouldBeNull(); 
+0

我沒有找到一個ShouldBeNull()方法。相反,我必須做「〜/ do/not/map/this」.Route()。ShouldEqual(null,「」); – JNappi

回答

1

我認爲你正在尋找如下:

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

這個斷言,路線由Stop​​RoutingHandler處理幕後。

0

我在找同樣的東西。我最終加入以下擴展方法來實現ShouldBeNull和更短的ShouldNotMap

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."); 
    } 

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); 
     } 
    }