forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubRouteCollectionTest.cs
More file actions
60 lines (52 loc) · 2.04 KB
/
Copy pathSubRouteCollectionTest.cs
File metadata and controls
60 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if !ASPNETWEBAPI
using System.Web.Routing;
#endif
using Microsoft.TestCommon;
using Moq;
#if ASPNETWEBAPI
namespace System.Web.Http.Routing
#else
namespace System.Web.Mvc.Routing
#endif
{
public class SubRouteCollectionTest
{
#if ASPNETWEBAPI
[Fact]
public void SubRouteCollection_Throws_OnDuplicateNamedRoute_WebAPI()
{
// Arrange
var collection = new SubRouteCollection();
var route1 = new HttpRoute("api/Person");
var route2 = new HttpRoute("api/Car");
collection.Add(new RouteEntry("route", route1));
var expectedError =
"A route named 'route' is already in the route collection. Route names must be unique.\r\n\r\n" +
"Duplicates:" + Environment.NewLine +
"api/Car" + Environment.NewLine +
"api/Person";
// Act & Assert
Assert.Throws<InvalidOperationException>(() => collection.Add(new RouteEntry("route", route2)), expectedError);
}
#else
[Fact]
public void SubRouteCollection_Throws_OnDuplicateNamedRoute_MVC()
{
// Arrange
var collection = new SubRouteCollection();
var route1 = new Route("Home/Index", new Mock<IRouteHandler>().Object);
var route2 = new Route("Person/Index", new Mock<IRouteHandler>().Object);
collection.Add(new RouteEntry("route", route1));
var expectedError =
"A route named 'route' is already in the route collection. Route names must be unique.\r\n\r\n" +
"Duplicates:" + Environment.NewLine +
"Person/Index" + Environment.NewLine +
"Home/Index";
// Act & Assert
Assert.Throws<InvalidOperationException>(() => collection.Add(new RouteEntry("route", route2)), expectedError);
}
#endif
}
}