70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
|
|||
|
|
|||
|
using System.Web.Routing;
|
|||
|
using Microsoft.TestCommon;
|
|||
|
using Xunit;
|
|||
|
using Assert = Microsoft.TestCommon.AssertEx;
|
|||
|
|
|||
|
namespace System.Web.Http
|
|||
|
{
|
|||
|
public class RouteCollectionExtensionsTest
|
|||
|
{
|
|||
|
[Fact]
|
|||
|
public void IsCorrectType()
|
|||
|
{
|
|||
|
Assert.Type.HasProperties(typeof(RouteCollectionExtensions), TypeAssert.TypeProperties.IsStatic | TypeAssert.TypeProperties.IsPublicVisibleClass);
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
public void MapHttpRoute1ThrowsOnNullRouteCollection()
|
|||
|
{
|
|||
|
Assert.ThrowsArgumentNull(() => RouteCollectionExtensions.MapHttpRoute(null, "", "", null), "routes");
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
public void MapHttpRoute1CreatesRoute()
|
|||
|
{
|
|||
|
// Arrange
|
|||
|
RouteCollection routes = new RouteCollection();
|
|||
|
object defaults = new { d1 = "D1" };
|
|||
|
|
|||
|
// Act
|
|||
|
Route route = routes.MapHttpRoute("name", "template", defaults);
|
|||
|
|
|||
|
// Assert
|
|||
|
Assert.NotNull(route);
|
|||
|
Assert.Equal("template", route.Url);
|
|||
|
Assert.Equal(1, route.Defaults.Count);
|
|||
|
Assert.Equal("D1", route.Defaults["d1"]);
|
|||
|
Assert.Same(route, routes["name"]);
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
public void MapHttpRoute2ThrowsOnNullRouteCollection()
|
|||
|
{
|
|||
|
Assert.ThrowsArgumentNull(() => RouteCollectionExtensions.MapHttpRoute(null, "", "", null, null), "routes");
|
|||
|
}
|
|||
|
|
|||
|
[Fact]
|
|||
|
public void MapHttpRoute2CreatesRoute()
|
|||
|
{
|
|||
|
// Arrange
|
|||
|
RouteCollection routes = new RouteCollection();
|
|||
|
object defaults = new { d1 = "D1" };
|
|||
|
object constraints = new { c1 = "C1" };
|
|||
|
|
|||
|
// Act
|
|||
|
Route route = routes.MapHttpRoute("name", "template", defaults, constraints);
|
|||
|
|
|||
|
// Assert
|
|||
|
Assert.NotNull(route);
|
|||
|
Assert.Equal("template", route.Url);
|
|||
|
Assert.Equal(1, route.Defaults.Count);
|
|||
|
Assert.Equal("D1", route.Defaults["d1"]);
|
|||
|
Assert.Equal(1, route.Defaults.Count);
|
|||
|
Assert.Equal("C1", route.Constraints["c1"]);
|
|||
|
Assert.Same(route, routes["name"]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|