forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaRegistrationContextTest.cs
More file actions
140 lines (117 loc) · 5.13 KB
/
Copy pathAreaRegistrationContextTest.cs
File metadata and controls
140 lines (117 loc) · 5.13 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// 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.
using System.Collections.Generic;
using System.Web.Routing;
using Microsoft.TestCommon;
namespace System.Web.Mvc.Test
{
public class AreaRegistrationContextTest
{
[Fact]
public void ConstructorSetsProperties()
{
// Arrange
string areaName = "the_area";
RouteCollection routes = new RouteCollection();
// Act
AreaRegistrationContext context = new AreaRegistrationContext(areaName, routes);
// Assert
Assert.Equal(areaName, context.AreaName);
Assert.Same(routes, context.Routes);
}
[Fact]
public void ConstructorThrowsIfAreaNameIsEmpty()
{
// Act & assert
Assert.ThrowsArgumentNullOrEmpty(
delegate { new AreaRegistrationContext("", new RouteCollection()); }, "areaName");
}
[Fact]
public void ConstructorThrowsIfAreaNameIsNull()
{
// Act & assert
Assert.ThrowsArgumentNullOrEmpty(
delegate { new AreaRegistrationContext(null, new RouteCollection()); }, "areaName");
}
[Fact]
public void ConstructorThrowsIfRoutesIsNull()
{
// Act & assert
Assert.ThrowsArgumentNull(
delegate { new AreaRegistrationContext("the_area", null); }, "routes");
}
[Fact]
public void MapRouteWithEmptyStringNamespaces()
{
// Arrange
string[] implicitNamespaces = new string[] { "implicit_1", "implicit_2" };
string[] explicitNamespaces = new string[0];
RouteCollection routes = new RouteCollection();
AreaRegistrationContext context = new AreaRegistrationContext("the_area", routes);
ReplaceCollectionContents(context.Namespaces, implicitNamespaces);
// Act
Route route = context.MapRoute("the_name", "the_url", explicitNamespaces);
// Assert
Assert.Equal(route, routes["the_name"]);
Assert.Equal("the_area", route.DataTokens["area"]);
Assert.Equal((object)true, route.DataTokens["UseNamespaceFallback"]);
Assert.Null(route.DataTokens["namespaces"]);
}
[Fact]
public void MapRouteWithExplicitNamespaces()
{
// Arrange
string[] implicitNamespaces = new string[] { "implicit_1", "implicit_2" };
string[] explicitNamespaces = new string[] { "explicit_1", "explicit_2" };
RouteCollection routes = new RouteCollection();
AreaRegistrationContext context = new AreaRegistrationContext("the_area", routes);
ReplaceCollectionContents(context.Namespaces, implicitNamespaces);
// Act
Route route = context.MapRoute("the_name", "the_url", explicitNamespaces);
// Assert
Assert.Equal(route, routes["the_name"]);
Assert.Equal("the_area", route.DataTokens["area"]);
Assert.Equal((object)false, route.DataTokens["UseNamespaceFallback"]);
Assert.Equal(explicitNamespaces, (string[])route.DataTokens["namespaces"]);
}
[Fact]
public void MapRouteWithImplicitNamespaces()
{
// Arrange
string[] implicitNamespaces = new string[] { "implicit_1", "implicit_2" };
string[] explicitNamespaces = new string[] { "explicit_1", "explicit_2" };
RouteCollection routes = new RouteCollection();
AreaRegistrationContext context = new AreaRegistrationContext("the_area", routes);
ReplaceCollectionContents(context.Namespaces, implicitNamespaces);
// Act
Route route = context.MapRoute("the_name", "the_url");
// Assert
Assert.Equal(route, routes["the_name"]);
Assert.Equal("the_area", route.DataTokens["area"]);
Assert.Equal((object)false, route.DataTokens["UseNamespaceFallback"]);
Assert.Equal(implicitNamespaces, (string[])route.DataTokens["namespaces"]);
}
[Fact]
public void MapRouteWithoutNamespaces()
{
// Arrange
RouteCollection routes = new RouteCollection();
AreaRegistrationContext context = new AreaRegistrationContext("the_area", routes);
// Act
Route route = context.MapRoute("the_name", "the_url");
// Assert
Assert.Equal(route, routes["the_name"]);
Assert.Equal("the_area", route.DataTokens["area"]);
Assert.Null(route.DataTokens["namespaces"]);
Assert.Equal((object)true, route.DataTokens["UseNamespaceFallback"]);
}
private static void ReplaceCollectionContents(ICollection<string> collectionToReplace, IEnumerable<string> newContents)
{
collectionToReplace.Clear();
foreach (string item in newContents)
{
collectionToReplace.Add(item);
}
}
}
}