-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathControllerResultTestController.cs
More file actions
275 lines (232 loc) · 7.54 KB
/
ControllerResultTestController.cs
File metadata and controls
275 lines (232 loc) · 7.54 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
using System.IO;
using System.Text;
using System.Web.Mvc;
namespace TestStack.FluentMVCTesting.Tests.TestControllers
{
class ControllerResultTestController : Controller
{
#region Testing Constants
public const string RouteName = "RouteName";
public const string RedirectUrl = "http://url/";
public const string FileContentType = "application/contentType";
public const string ViewName = "NamedView";
public const string PartialName = "NamedPartial";
public const string RandomViewName = "Random";
public const int Code = 403;
public const string JsonValue = "json";
public const string FileName = "NamedFile";
public static byte[] BinaryFileContents = { 1 };
public static string TextualFileContent = "textual content";
public static byte[] EmptyFileBuffer = { };
public static readonly Stream EmptyStreamContents = new MemoryStream(EmptyFileBuffer);
public static readonly Stream BinaryStreamContents = new MemoryStream(BinaryFileContents);
public const string TextualContent = "textual content";
public static readonly Encoding TextualContentEncoding = Encoding.UTF8;
public const string ContentType = "application/contentType";
#endregion
#region Empty, Null and Random Results
public EmptyResult EmptyResult()
{
return new EmptyResult();
}
public ActionResult Null()
{
return null;
}
public ActionResult RandomResult()
{
return new RandomResult();
}
public ActionResult RedirectToRandomResult()
{
return RedirectToAction("RandomResult");
}
#endregion
#region Redirects
public ActionResult RedirectToUrl()
{
return Redirect(RedirectUrl);
}
public ActionResult RedirectToRouteName()
{
return RedirectToRoute(RouteName);
}
public ActionResult RedirectToActionWithNoParameters()
{
return RedirectToAction("ActionWithNoParameters");
}
public ActionResult RedirectToActionWithOneParameter()
{
return RedirectToAction("ActionWithOneParameter");
}
public ActionResult RedirectToActionWithTwoParameters()
{
return RedirectToAction("ActionWithTwoParameters");
}
public ActionResult RedirectToActionWithThreeParameters()
{
return RedirectToAction("ActionWithThreeParameters");
}
public ActionResult RedirectToActionWithMoreThanThreeParameters()
{
return RedirectToAction("ActionWithMoreThanThreeParameters");
}
public ActionResult RedirectToAnotherController()
{
return RedirectToAction("SomeAction", "SomeOther");
}
public ActionResult RedirectToAnotherActionNoController()
{
return RedirectToAction("SomeAction");
}
#region Redirect Actions
public ActionResult ActionWithNoParameters()
{
return new EmptyResult();
}
public ActionResult ActionWithOneParameter(int param1)
{
return new EmptyResult();
}
public ActionResult ActionWithTwoParameters(int param1, int param2)
{
return new EmptyResult();
}
public ActionResult ActionWithThreeParameters(int param1, int param2, int param3)
{
return new EmptyResult();
}
public ActionResult ActionWithMoreThanThreeParameters(int param1, int param2, int param3, int param4)
{
return new EmptyResult();
}
#endregion
#endregion
#region Views
public ActionResult DefaultView()
{
return View();
}
public ActionResult DefaultViewExplicit()
{
return View("DefaultViewExplicit");
}
public ActionResult DefaultPartial()
{
return PartialView();
}
public ActionResult DefaultPartialExplicit()
{
return PartialView("DefaultPartialExplicit");
}
public ActionResult NamedView()
{
return View(ViewName);
}
public ActionResult NamedPartial()
{
return PartialView(PartialName);
}
public ActionResult RandomView()
{
return View(RandomViewName);
}
public ActionResult RandomPartial()
{
return PartialView(RandomViewName);
}
#endregion
#region Files
public ActionResult EmptyFile()
{
var content = new byte[] { };
return File(content, FileContentType);
}
public ActionResult BinaryFile()
{
return File(BinaryFileContents, FileContentType);
}
public ActionResult TextualFile()
{
return TextualFile(Encoding.UTF8);
}
public ActionResult TextualFile(Encoding encoding)
{
var encodedContents = encoding.GetBytes(TextualFileContent);
return File(encodedContents, FileContentType);
}
public ActionResult EmptyStream()
{
return File(EmptyStreamContents, FileContentType);
}
public ActionResult BinaryStream()
{
return File(BinaryStreamContents, FileContentType);
}
public ActionResult TextualStream()
{
return TextualStream(Encoding.UTF8);
}
public ActionResult TextualStream(Encoding encoding)
{
var encondedContent = encoding.GetBytes(TextualFileContent);
var stream = new MemoryStream(encondedContent);
return File(stream, FileContentType);
}
public ActionResult EmptyFilePath()
{
return File(FileName, FileContentType);
}
#endregion
#region Http Status
public ActionResult NotFound()
{
return HttpNotFound();
}
public HttpStatusCodeResult StatusCode()
{
return new HttpStatusCodeResult(Code);
}
#endregion
#region JSON
public JsonResult Json()
{
return Json(JsonValue);
}
#endregion
#region Content
public ActionResult Content()
{
return Content(TextualContent, ContentType, TextualContentEncoding);
}
public ActionResult ContentWithoutEncodingSpecified()
{
return Content(TextualContent, ContentType);
}
#endregion
}
#region Test Classes
class SomeOtherController : Controller
{
public ActionResult SomeAction()
{
return new EmptyResult();
}
public ActionResult SomeOtherAction()
{
return new EmptyResult();
}
}
class YetAnotherController : Controller
{
public ActionResult SomeAction()
{
return new EmptyResult();
}
}
class RandomResult : ActionResult
{
public override void ExecuteResult(ControllerContext context) {}
}
#endregion
}