Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JsonResult Assertions #37

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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