Skip to content

Commit 8d59d9d

Browse files
author
Casey Burns
committed
Merge remote-tracking branch 'kevinkuszyk/master-kk'
2 parents a9f5ee0 + 0b25f82 commit 8d59d9d

14 files changed

+402
-153
lines changed

FluentAssertionsMvc.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuspecs", "nuspecs", "{48A7
3030
src\FluentAssertions.Mvc4\FluentAssertions.Mvc4.nuspec = src\FluentAssertions.Mvc4\FluentAssertions.Mvc4.nuspec
3131
EndProjectSection
3232
EndProject
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C48468D-7CDA-45C7-8B21-0669A567711B}"
34+
ProjectSection(SolutionItems) = preProject
35+
_todo_.txt = _todo_.txt
36+
EndProjectSection
37+
EndProject
3338
Global
3439
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3540
Debug|Any CPU = Debug|Any CPU

_todo_.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[ ] Change all dictionary asserts to us Subject.RouteValues.Should().Contain
66
[ ] FluentAssertions should *not* blow up if given null reasonArgs and a reason
77
[ ] Should because syntax in sample code
8-
[ ] XML comments every where
8+
[x] XML comments every where
99
[ ] Should assertions be more domain focused? i.e. routes.Should().MapTo()...
1010
[ ] Create RouteCollection.GenerateUrl(RouteValues)
1111
[ ] Need to test reason injection into fail messages

src/FluentAssertions.Mvc3/ActionResultAssertions.cs

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,43 @@
66

77
namespace FluentAssertions.Mvc
88
{
9+
/// <summary>
10+
/// Contains a number of methods to assert that an <see cref="ActionResult"/> is in the expected state.
11+
/// </summary>
912
[DebuggerNonUserCode]
1013
public class ActionResultAssertions : ObjectAssertions
1114
{
1215
public struct Constants
1316
{
1417
public const string CommonFailMessage = "Expected ActionResult to be {0}{reason}, but found {1}";
1518
}
16-
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="T:ActionResultAssertions" /> class.
22+
/// </summary>
1723
public ActionResultAssertions (ActionResult subject) : base(subject)
1824
{
1925
Subject = subject;
2026
}
2127

28+
/// <summary>
29+
/// Asserts that the subject is a <see cref="ContentResult"/>.
30+
/// </summary>
2231
public ContentResultAssertions BeContentResult()
2332
{
2433
return BeContentResult(string.Empty, null);
2534
}
2635

36+
/// <summary>
37+
/// Asserts that the subject is a <see cref="ContentResult"/>.
38+
/// </summary>
39+
/// <param name="reason">
40+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
41+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
42+
/// </param>
43+
/// <param name="reasonArgs">
44+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
45+
/// </param>
2746
public ContentResultAssertions BeContentResult(string reason, params object[] reasonArgs)
2847
{
2948
Execute.Assertion
@@ -34,11 +53,24 @@ public ContentResultAssertions BeContentResult(string reason, params object[] re
3453
return new ContentResultAssertions(Subject as ContentResult);
3554
}
3655

56+
/// <summary>
57+
/// Asserts that the subject is an <see cref="EmptyResult"/>.
58+
/// </summary>
3759
public EmptyResult BeEmptyResult()
3860
{
3961
return BeEmptyResult(string.Empty, null);
4062
}
4163

64+
/// <summary>
65+
/// Asserts that the subject is an <see cref="EmptyResult"/>.
66+
/// </summary>
67+
/// <param name="reason">
68+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
69+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
70+
/// </param>
71+
/// <param name="reasonArgs">
72+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
73+
/// </param>
4274
public EmptyResult BeEmptyResult(string reason, params object[] reasonArgs)
4375
{
4476
Execute.Assertion
@@ -49,11 +81,24 @@ public EmptyResult BeEmptyResult(string reason, params object[] reasonArgs)
4981
return Subject as EmptyResult;
5082
}
5183

84+
/// <summary>
85+
/// Asserts that the subject is a <see cref="RedirectToRouteResult"/>.
86+
/// </summary>
5287
public RedirectToRouteAssertions BeRedirectToRouteResult()
5388
{
5489
return BeRedirectToRouteResult(string.Empty, null);
5590
}
5691

92+
/// <summary>
93+
/// Asserts that the subject is a <see cref="RedirectToRouteResult"/>.
94+
/// </summary>
95+
/// <param name="reason">
96+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
97+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
98+
/// </param>
99+
/// <param name="reasonArgs">
100+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
101+
/// </param>
57102
public RedirectToRouteAssertions BeRedirectToRouteResult(string reason, params object[] reasonArgs)
58103
{
59104
Execute.Assertion
@@ -64,11 +109,24 @@ public RedirectToRouteAssertions BeRedirectToRouteResult(string reason, params o
64109
return new RedirectToRouteAssertions(Subject as RedirectToRouteResult);
65110
}
66111

112+
/// <summary>
113+
/// Asserts that the subject is a <see cref="PartialViewResult"/>.
114+
/// </summary>
67115
public PartialViewResultAssertions BePartialViewResult()
68116
{
69117
return BePartialViewResult(string.Empty, null);
70118
}
71119

120+
/// <summary>
121+
/// Asserts that the subject is a <see cref="PartialViewResult"/>.
122+
/// </summary>
123+
/// <param name="reason">
124+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
125+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
126+
/// </param>
127+
/// <param name="reasonArgs">
128+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
129+
/// </param>
72130
public PartialViewResultAssertions BePartialViewResult(string reason, params object[] reasonArgs)
73131
{
74132
Execute.Assertion
@@ -79,11 +137,24 @@ public PartialViewResultAssertions BePartialViewResult(string reason, params obj
79137
return new PartialViewResultAssertions(Subject as PartialViewResult);
80138
}
81139

140+
/// <summary>
141+
/// Asserts that the subject is a <see cref="RedirectResult"/>.
142+
/// </summary>
82143
public RedirectResultAssertions BeRedirectResult()
83144
{
84145
return BeRedirectResult(string.Empty, null);
85146
}
86147

148+
/// <summary>
149+
/// Asserts that the subject is a <see cref="RedirectResult"/>.
150+
/// </summary>
151+
/// <param name="reason">
152+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
153+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
154+
/// </param>
155+
/// <param name="reasonArgs">
156+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
157+
/// </param>
87158
public RedirectResultAssertions BeRedirectResult(string reason, params object[] reasonArgs)
88159
{
89160
Execute.Assertion
@@ -94,11 +165,24 @@ public RedirectResultAssertions BeRedirectResult(string reason, params object[]
94165
return new RedirectResultAssertions(Subject as RedirectResult);
95166
}
96167

168+
/// <summary>
169+
/// Asserts that the subject is a <see cref="ViewResult"/>.
170+
/// </summary>
97171
public ViewResultAssertions BeViewResult()
98172
{
99173
return BeViewResult(string.Empty, null);
100174
}
101175

176+
/// <summary>
177+
/// Asserts that the subject is a <see cref="ViewResult"/>.
178+
/// </summary>
179+
/// <param name="reason">
180+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
181+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
182+
/// </param>
183+
/// <param name="reasonArgs">
184+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
185+
/// </param>
102186
public ViewResultAssertions BeViewResult(string reason, params object[] reasonArgs)
103187
{
104188
Execute.Assertion

src/FluentAssertions.Mvc3/AssertionsExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@
77

88
namespace FluentAssertions.Mvc
99
{
10+
/// <summary>
11+
/// Contains extension methods for custom assertions in unit tests.
12+
/// </summary>
1013
[DebuggerNonUserCode]
1114
public static class AssertionsExtensions
1215
{
16+
/// <summary>
17+
/// Returns an <see cref="ActionResultAssertions"/> object that can be used to assert the
18+
/// current <see cref="ActionResult"/>.
19+
/// </summary>
1320
public static ActionResultAssertions Should (this ActionResult actual)
1421
{
1522
return new ActionResultAssertions (actual);
1623
}
1724

25+
/// <summary>
26+
/// Returns an <see cref="RouteDataAssertions"/> object that can be used to assert the
27+
/// current <see cref="RouteData"/>.
28+
/// </summary>
1829
public static RouteDataAssertions Should(this RouteData routeData)
1930
{
2031
return new RouteDataAssertions(routeData);

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.Assertion
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.Assertion
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
}

src/FluentAssertions.Mvc3/FluentAssertions.Mvc3.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<projectUrl>http://fluentassertionsmvc.codeplex.com</projectUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>FluentAssertions MVC is a set of MVC focused assertions and helper extensions to the excellent FluentAssertions library.</description>
13-
<releaseNotes>Initial release.</releaseNotes>
13+
<releaseNotes>Xml comments added and Fluent Assertions dependency upgraded to v2.1</releaseNotes>
1414
<copyright>Copyright 2013</copyright>
1515
<tags>TDD, TDD, Fluent, Mvc, AspNetMvc</tags>
1616
<dependencies>
17-
<dependency id="FluentAssertions" version="[2.0.0.1,2.1)" />
17+
<dependency id="FluentAssertions" version="2.1" />
1818
</dependencies>
1919
</metadata>
2020
</package>

src/FluentAssertions.Mvc3/RedirectResultAssertions.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@
88

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

15-
public RedirectResultAssertions WithUrl(string expectedUrl)
16-
{
17-
WithUrl(expectedUrl, string.Empty, null);
18-
return this;
19-
}
20-
21-
public RedirectResultAssertions WithUrl(string expectedUrl, string reason, string reasonArgs)
21+
/// <summary>
22+
/// Asserts that the url is the expected url.
23+
/// </summary>
24+
/// <param name="expectedUrl">The expected url.</param>
25+
/// <param name="reason">
26+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
27+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
28+
/// </param>
29+
/// <param name="reasonArgs">
30+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
31+
/// </param>
32+
public RedirectResultAssertions WithUrl(string expectedUrl, string reason = "", params object[] reasonArgs)
2233
{
2334
string actualUrl = (Subject as RedirectResult).Url;
2435

@@ -30,13 +41,18 @@ public RedirectResultAssertions WithUrl(string expectedUrl, string reason, strin
3041
return this;
3142
}
3243

33-
public RedirectResultAssertions WithPermanent(bool expectedPermanent)
34-
{
35-
WithPermanent(expectedPermanent, string.Empty, null);
36-
return this;
37-
}
38-
39-
public RedirectResultAssertions WithPermanent(bool expectedPermanent, string reason, string reasonArgs)
44+
/// <summary>
45+
/// Asserts that the redirect is permanent.
46+
/// </summary>
47+
/// <param name="expectedPermanent">Should the expected redirect be permanent.</param>
48+
/// <param name="reason">
49+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
50+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
51+
/// </param>
52+
/// <param name="reasonArgs">
53+
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
54+
/// </param>
55+
public RedirectResultAssertions WithPermanent(bool expectedPermanent, string reason = "", params object[] reasonArgs)
4056
{
4157
bool actualPermanent = (Subject as RedirectResult).Permanent;
4258

0 commit comments

Comments
 (0)