Skip to content

Commit 0f0ea86

Browse files
committed
Xml comments added to ContentResultAssertions, and assertion overload removed (in line with FluentAssertions)
1 parent 67f0e29 commit 0f0ea86

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

src/FluentAssertions.Mvc3/ContentResultAssertions.cs

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@
88

99
namespace FluentAssertions.Mvc
1010
{
11+
/// <summary>
12+
/// Contains a number of methods to assert that a <see cref="ContentResult"/> is in the expected state.
13+
/// </summary>
1114
public class ContentResultAssertions : ObjectAssertions
1215
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="T:ContentResultAssertions" /> class.
18+
/// </summary>
1319
public ContentResultAssertions(ContentResult subject) : base(subject)
1420
{
1521
}
1622

17-
public ContentResultAssertions WithContent(string expectedContent)
18-
{
19-
WithContent(expectedContent, string.Empty, null);
20-
return this;
21-
}
22-
23-
public ContentResultAssertions WithContent(string expectedContent, string reason, params object[] reasonArgs)
23+
/// <summary>
24+
/// Asserts that the content is exactly the same as the expected content, ignoring the casing.
25+
/// </summary>
26+
/// <param name="expectedContent">The expected content string.</param>
27+
/// <param name="reason">
28+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
29+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
30+
/// </param>
31+
/// <param name="reasonArgs">
32+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
33+
/// </param>
34+
public ContentResultAssertions WithContent(string expectedContent, string reason = "", params object[] reasonArgs)
2435
{
2536
string actualContent = (Subject as ContentResult).Content;
2637

@@ -32,38 +43,48 @@ public ContentResultAssertions WithContent(string expectedContent, string reason
3243
return this;
3344
}
3445

35-
public ContentResultAssertions WithContentType(string expectedContent)
36-
{
37-
WithContentType(expectedContent, string.Empty, null);
38-
return this;
39-
}
40-
41-
public ContentResultAssertions WithContentType(string expectedContent, string reason, params object[] reasonArgs)
46+
/// <summary>
47+
/// Asserts that the content type is the expected content type.
48+
/// </summary>
49+
/// <param name="expectedContentType">The expected content type.</param>
50+
/// <param name="reason">
51+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
52+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
53+
/// </param>
54+
/// <param name="reasonArgs">
55+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
56+
/// </param>
57+
public ContentResultAssertions WithContentType(string expectedContentType, string reason = "", params object[] reasonArgs)
4258
{
4359
string actualContentType = (Subject as ContentResult).ContentType;
4460

4561
Execute.Verification
46-
.ForCondition(string.Equals(expectedContent, actualContentType, StringComparison.InvariantCultureIgnoreCase))
62+
.ForCondition(string.Equals(expectedContentType, actualContentType, StringComparison.InvariantCultureIgnoreCase))
4763
.BecauseOf(reason, reasonArgs)
48-
.FailWith(string.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentType", expectedContent, actualContentType));
49-
50-
return this;
51-
}
64+
.FailWith(string.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentType", expectedContentType, actualContentType));
5265

53-
public ContentResultAssertions WithContentEncoding(Encoding expectedEncoding)
54-
{
55-
WithContentEncoding(expectedEncoding, string.Empty, null);
5666
return this;
5767
}
5868

59-
public ContentResultAssertions WithContentEncoding(Encoding expectedEncoding, string reason, params object[] reasonArgs)
69+
/// <summary>
70+
/// Asserts that the content encoding is the expected content encoding type.
71+
/// </summary>
72+
/// <param name="expectedEncoding">The expected content encoding type.</param>
73+
/// <param name="reason">
74+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
75+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
76+
/// </param>
77+
/// <param name="reasonArgs">
78+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
79+
/// </param>
80+
public ContentResultAssertions WithContentEncoding(Encoding expectedEncoding, string reason = "", params object[] reasonArgs)
6081
{
6182
Encoding actualContentEncoding = (Subject as ContentResult).ContentEncoding;
6283

6384
Execute.Verification
6485
.ForCondition(expectedEncoding == actualContentEncoding)
6586
.BecauseOf(reason, reasonArgs)
66-
.FailWith(string.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentType", expectedEncoding.ToString(), actualContentEncoding.ToString()));
87+
.FailWith(string.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentEncoding", expectedEncoding.ToString(), actualContentEncoding.ToString()));
6788

6889
return this;
6990
}

tests/FluentAssertions.Mvc3.Tests/ContentResultAssertions_Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void WithContentEncoding_GivenUnexpected_ShouldFail()
6565
var actualEncoding = Encoding.ASCII;
6666
var expectedEncoding = Encoding.Unicode;
6767
ActionResult result = new ContentResult { ContentEncoding = actualEncoding };
68-
var failureMessage = String.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentType", expectedEncoding, actualEncoding);
68+
var failureMessage = String.Format(FailureMessages.CommonFailMessage, "ContentResult.ContentEncoding", expectedEncoding, actualEncoding);
6969

7070
Action a = () => result.Should().BeContentResult().WithContentEncoding(expectedEncoding);
7171

0 commit comments

Comments
 (0)