Skip to content

Commit 2419a7f

Browse files
authored
Merge pull request #37 from rikrak/JsonResultAssertions
Added JsonResult Assertions
2 parents e5219d0 + 80333a9 commit 2419a7f

7 files changed

+416
-55
lines changed

src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs

+29
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,34 @@ public ViewResultAssertions BeViewResult(string reason, params object[] reasonAr
209209

210210
return new ViewResultAssertions (Subject as ViewResult);
211211
}
212+
213+
/// <summary>
214+
/// Asserts that the subject is a <see cref="JsonResult"/>.
215+
/// </summary>
216+
public JsonResultAssertions BeJsonResult()
217+
{
218+
return BeJsonResult(string.Empty, null);
219+
}
220+
221+
/// <summary>
222+
/// Asserts that the subject is a <see cref="JsonResult"/>.
223+
/// </summary>
224+
/// <param name="reason">
225+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
226+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
227+
/// </param>
228+
/// <param name="reasonArgs">
229+
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
230+
/// </param>
231+
public JsonResultAssertions BeJsonResult(string reason, params object[] reasonArgs)
232+
{
233+
Execute.Assertion
234+
.BecauseOf(reason, reasonArgs)
235+
.ForCondition(Subject is JsonResult)
236+
.FailWith(Constants.CommonFailMessage, typeof(JsonResult).Name, Subject.GetType().Name);
237+
238+
return new JsonResultAssertions(Subject as JsonResult);
239+
}
240+
212241
}
213242
}

src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs

+94-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FluentAssertions.Mvc.Shared/FailureMessages.resx

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@
120120
<data name="CommonFailMessage" xml:space="preserve">
121121
<value>Expected {0} to be '{1}' but found '{2}'</value>
122122
</data>
123+
<data name="JsonResult_WithDataPredicate" xml:space="preserve">
124+
<value>Expected {0} to match the predicate test, but '{1}' did not</value>
125+
</data>
123126
<data name="RouteData_DataTokens_ContainsKey" xml:space="preserve">
124127
<value>RouteData.DataTokens does not contain key {0}.</value>
125128
</data>

src/FluentAssertions.Mvc.Shared/FluentAssertions.Mvc.Shared.projitems

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpContext.cs" />
2323
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpRequest.cs" />
2424
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpResponse.cs" />
25+
<Compile Include="$(MSBuildThisFileDirectory)JsonResultAssertions.cs" />
2526
<Compile Include="$(MSBuildThisFileDirectory)PartialViewResultAssertions.cs" />
2627
<Compile Include="$(MSBuildThisFileDirectory)RedirectResultAssertions.cs" />
2728
<Compile Include="$(MSBuildThisFileDirectory)RedirectToRouteAssertions.cs" />

0 commit comments

Comments
 (0)