forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpPageSampleKeyTest.cs
More file actions
198 lines (169 loc) · 11.1 KB
/
Copy pathHelpPageSampleKeyTest.cs
File metadata and controls
198 lines (169 loc) · 11.1 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// 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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Http.Headers;
using Microsoft.TestCommon;
using ROOT_PROJECT_NAMESPACE.Areas.HelpPage;
namespace WebApiHelpPageWebHost.UnitTest
{
public class HelpPageSampleKeyTest
{
[Fact]
public void Constructor_TwoParameters()
{
HelpPageSampleKey key = new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), typeof(Tuple<int, string>));
Assert.Equal(new MediaTypeHeaderValue("application/xml"), key.MediaType);
Assert.Equal(typeof(Tuple<int, string>), key.ParameterType);
Assert.Null(key.SampleDirection);
Assert.Equal(String.Empty, key.ControllerName);
Assert.Equal(String.Empty, key.ActionName);
Assert.Empty(key.ParameterNames);
}
[Fact]
public void Constructor_FourParameters()
{
HelpPageSampleKey key = new HelpPageSampleKey(SampleDirection.Request, "myController", "myAction", new[] { "id", "name" });
Assert.Null(key.MediaType);
Assert.Null(key.ParameterType);
Assert.Equal(SampleDirection.Request, key.SampleDirection.Value);
Assert.Equal("myController", key.ControllerName);
Assert.Equal("myAction", key.ActionName);
Assert.NotEmpty(key.ParameterNames);
Assert.True(key.ParameterNames.SetEquals(new[] { "name", "id" }));
}
[Fact]
public void Constructor_FiveParameters()
{
HelpPageSampleKey key = new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, "myController", "myAction", new[] { "id", "name" });
Assert.Equal(new MediaTypeHeaderValue("application/xml"), key.MediaType);
Assert.Null(key.ParameterType);
Assert.Equal(SampleDirection.Request, key.SampleDirection.Value);
Assert.Equal("myController", key.ControllerName);
Assert.Equal("myAction", key.ActionName);
Assert.NotEmpty(key.ParameterNames);
Assert.True(key.ParameterNames.SetEquals(new[] { "name", "id" }));
}
public static IEnumerable<object[]> Constructor_ThrowsArgumentNullException_PropertyData
{
get
{
yield return new Func<object>[] { () => new HelpPageSampleKey(null, typeof(Tuple<int, string>)) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), null) };
yield return new Func<object>[] { () => new HelpPageSampleKey(SampleDirection.Request, "c", "a", null) };
yield return new Func<object>[] { () => new HelpPageSampleKey(SampleDirection.Request, null, "a", new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(SampleDirection.Request, "c", null, new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(null, SampleDirection.Request, "c", "a", new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, "c", "a", null) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, null, "a", new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, "c", null, new string[0]) };
}
}
[Theory]
[PropertyData("Constructor_ThrowsArgumentNullException_PropertyData")]
public void Constructor_ThrowsArgumentNullException(Func<object> constructorDelegate)
{
Assert.Throws(typeof(ArgumentNullException), constructorDelegate);
}
public static IEnumerable<object[]> Constructor_ThrowsArgumentException_PropertyData
{
get
{
yield return new Func<object>[] { () => new HelpPageSampleKey(SampleDirection.Request, null, "a", new string[0])};
yield return new Func<object>[] { () => new HelpPageSampleKey(SampleDirection.Request, "c", null, new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, null, "a", new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), SampleDirection.Request, "c", null, new string[0]) };
}
}
public static IEnumerable<object[]> Constructor_ThrowsInvalidEnumArgumentException_PropertyData
{
get
{
yield return new Func<object>[] { () => new HelpPageSampleKey((SampleDirection)10, "c", "a", new string[0]) };
yield return new Func<object>[] { () => new HelpPageSampleKey(new MediaTypeHeaderValue("application/xml"), (SampleDirection)9, "c", "a", new string[0]) };
}
}
[Theory]
[PropertyData("Constructor_ThrowsInvalidEnumArgumentException_PropertyData")]
public void Constructor_ThrowsInvalidEnumArgumentException(Func<object> constructorDelegate)
{
Assert.Throws(typeof(InvalidEnumArgumentException), constructorDelegate);
}
public static IEnumerable<object[]> Equals_ReturnsTrue_PropertyData
{
get
{
HelpPageSampleKey key1 = new HelpPageSampleKey(SampleDirection.Request, "myController", "myAction", new[] { "id", "name" });
HelpPageSampleKey key2 = new HelpPageSampleKey(SampleDirection.Request, "MyController", "myAction", new[] { "ID", "name" });
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(SampleDirection.Request, "myController", "myAction", new[] { "id", "name" });
key2 = new HelpPageSampleKey((SampleDirection)0, "MyController", "myAction", new[] { "ID", "name" });
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), typeof(Tuple<int, string>));
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("TEXT/custom"), typeof(Tuple<int, string>));
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "myAction", new string[0]);
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "CONTROLLER", "MYACTION", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Response, "controller", "myAction", new[] { "ID", "NAME" });
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Response, "CONTROLLER", "MYACTION", new[] { "id", "name" });
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[0]);
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Response, "controller", "action", new string[0]);
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), (SampleDirection)1, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
}
}
[Theory]
[PropertyData("Equals_ReturnsTrue_PropertyData")]
public void Equals_ReturnsTrue(HelpPageSampleKey key1, HelpPageSampleKey key2)
{
Assert.True(key1.Equals(key2));
}
public static IEnumerable<object[]> Equals_ReturnsFalse_PropertyData
{
get
{
HelpPageSampleKey key1 = new HelpPageSampleKey(SampleDirection.Request, "myController", "myAction", new[] { "id", "name" });
HelpPageSampleKey key2 = new HelpPageSampleKey(SampleDirection.Request, "MyController", "myAction", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), typeof(Tuple<int, int>));
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("TEXT/custom"), typeof(Tuple<int, string>));
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[0]);
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("TEXT/custom"), SampleDirection.Response, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), (SampleDirection)0, "controller", "action", new string[0]);
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("TEXT/custom"), (SampleDirection)1, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[] { "" });
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
key1 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), typeof(Tuple<int, int>));
key2 = new HelpPageSampleKey(new MediaTypeHeaderValue("text/custom"), SampleDirection.Request, "controller", "action", new string[0]);
yield return new object[] { key1, key2 };
}
}
[Theory]
[PropertyData("Equals_ReturnsFalse_PropertyData")]
public void Equals_ReturnsFalse(HelpPageSampleKey key1, HelpPageSampleKey key2)
{
Assert.False(key1.Equals(key2));
}
[Theory]
[PropertyData("Equals_ReturnsTrue_PropertyData")]
public void GetHashCode_ReturnsSame(HelpPageSampleKey key1, HelpPageSampleKey key2)
{
Assert.Equal(key1.GetHashCode(), key2.GetHashCode());
}
[Theory]
[PropertyData("Equals_ReturnsFalse_PropertyData")]
public void GetHashCode_ReturnsDifferent(HelpPageSampleKey key1, HelpPageSampleKey key2)
{
Assert.NotEqual(key1.GetHashCode(), key2.GetHashCode());
}
}
}