-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathShouldReturnContent.cs
More file actions
40 lines (35 loc) · 1.49 KB
/
ShouldReturnContent.cs
File metadata and controls
40 lines (35 loc) · 1.49 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
using System.Text;
using System.Web.Mvc;
namespace TestStack.FluentMVCTesting
{
public partial class ControllerResultTest<T>
{
public ContentResult ShouldReturnContent(string content = null, string contentType = null, Encoding encoding = null)
{
ValidateActionReturnType<ContentResult>();
var contentResult = (ContentResult)ActionResult;
if (contentType != null && contentType != contentResult.ContentType)
{
throw new ActionResultAssertionException(string.Format(
"Expected content type to be '{0}', but instead was '{1}'.",
contentType,
contentResult.ContentType));
}
if (content != null && content != contentResult.Content)
{
throw new ActionResultAssertionException(string.Format(
"Expected content to be '{0}', but instead was '{1}'.",
content,
contentResult.Content));
}
if (encoding != null && encoding != contentResult.ContentEncoding)
{
throw new ActionResultAssertionException(string.Format(
"Expected encoding to be equal to {0}, but instead was {1}.",
encoding.EncodingName,
contentResult.ContentEncoding != null ? contentResult.ContentEncoding.EncodingName : "null"));
}
return contentResult;
}
}
}