Skip to content

Commit

Permalink
Merge pull request #37 from rikrak/JsonResultAssertions
Browse files Browse the repository at this point in the history
Added JsonResult Assertions
  • Loading branch information
kevinkuszyk authored Jun 22, 2018
2 parents e5219d0 + 80333a9 commit 2419a7f
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 55 deletions.
29 changes: 29 additions & 0 deletions src/FluentAssertions.Mvc.Shared/ActionResultAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,34 @@ public ViewResultAssertions BeViewResult(string reason, params object[] reasonAr

return new ViewResultAssertions (Subject as ViewResult);
}

/// <summary>
/// Asserts that the subject is a <see cref="JsonResult"/>.
/// </summary>
public JsonResultAssertions BeJsonResult()
{
return BeJsonResult(string.Empty, null);
}

/// <summary>
/// Asserts that the subject is a <see cref="JsonResult"/>.
/// </summary>
/// <param name="reason">
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
/// </param>
/// <param name="reasonArgs">
/// Zero or more objects to format using the placeholders in <paramref name="reason"/>.
/// </param>
public JsonResultAssertions BeJsonResult(string reason, params object[] reasonArgs)
{
Execute.Assertion
.BecauseOf(reason, reasonArgs)
.ForCondition(Subject is JsonResult)
.FailWith(Constants.CommonFailMessage, typeof(JsonResult).Name, Subject.GetType().Name);

return new JsonResultAssertions(Subject as JsonResult);
}

}
}
149 changes: 94 additions & 55 deletions src/FluentAssertions.Mvc.Shared/FailureMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/FluentAssertions.Mvc.Shared/FailureMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="CommonFailMessage" xml:space="preserve">
<value>Expected {0} to be '{1}' but found '{2}'</value>
</data>
<data name="JsonResult_WithDataPredicate" xml:space="preserve">
<value>Expected {0} to match the predicate test, but '{1}' did not</value>
</data>
<data name="RouteData_DataTokens_ContainsKey" xml:space="preserve">
<value>RouteData.DataTokens does not contain key {0}.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fakes\FakeHttpResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)JsonResultAssertions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PartialViewResultAssertions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RedirectResultAssertions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RedirectToRouteAssertions.cs" />
Expand Down
Loading

0 comments on commit 2419a7f

Please sign in to comment.