Skip to content

Commit 2c745ae

Browse files
committed
Replace WithValue with WithContentType.
1 parent 8e13336 commit 2c745ae

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/FluentAssertions.AspNetCore.Mvc/JsonResultAssertions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,25 @@ public JsonResultAssertions(JsonResult subject) : base(subject)
4343
#region Public Methods
4444

4545
/// <summary>
46-
/// Asserts that the value is the expected value using Equals.
46+
/// Asserts that the content type is the expected content type.
4747
/// </summary>
48-
/// <param name="expectedValue">The expected value.</param>
48+
/// <param name="expectedContentType">The expected content type.</param>
4949
/// <param name="reason">
5050
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
5151
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
5252
/// </param>
5353
/// <param name="reasonArgs">
5454
/// Zero or more objects to format using the placeholders in <see cref="reason" />.
5555
/// </param>
56-
/// <returns></returns>
57-
public JsonResultAssertions WithValue(object expectedValue, string reason = "",
56+
public JsonResultAssertions WithContentType(string expectedContentType, string reason = "",
5857
params object[] reasonArgs)
5958
{
60-
var actualValue = JsonResultSubject.Value;
59+
var actualContentType = JsonResultSubject.ContentType;
6160

6261
Execute.Assertion
63-
.ForCondition(Equals(expectedValue, actualValue))
62+
.ForCondition(string.Equals(expectedContentType, actualContentType, StringComparison.OrdinalIgnoreCase))
6463
.BecauseOf(reason, reasonArgs)
65-
.FailWith(FailureMessages.CommonFailMessage, "JsonResult.Value", expectedValue, actualValue);
64+
.FailWith(FailureMessages.CommonFailMessage, "JsonResult.ContentType", expectedContentType, actualContentType);
6665
return this;
6766
}
6867

tests/FluentAssertions.AspNetCore.Mvc.Tests/JsonResultAssertions_Tests.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,28 @@ namespace FluentAssertions.AspNetCore.Mvc.Tests
88
public class JsonResultAssertions_Tests
99
{
1010
[Fact]
11-
public void WithValue_GivenValue_ShouldPass()
11+
public void WithContentType_GivenValue_ShouldPass()
1212
{
13-
ActionResult result = new JsonResult("value");
14-
result.Should().BeJsonResult().WithValue("value");
13+
ActionResult result = new JsonResult("value")
14+
{
15+
ContentType = "text/plain"
16+
};
17+
18+
result.Should().BeJsonResult().WithContentType("text/plain");
1519
}
1620

1721
[Fact]
18-
public void WithValue_GivenUnexpected_ShouldFail()
22+
public void WithContentType_GivenUnexpected_ShouldFail()
1923
{
20-
var actualValue = "xyz";
21-
var expectedValue = "value";
22-
ActionResult result = new JsonResult(actualValue);
23-
var failureMessage = FailureMessageHelper.Format(FailureMessages.CommonFailMessage, "JsonResult.Value", expectedValue, actualValue);
24-
25-
Action a = () => result.Should().BeJsonResult().WithValue(expectedValue);
24+
var actualValue = "text/css";
25+
var expectedValue = "text/plain";
26+
ActionResult result = new JsonResult("value")
27+
{
28+
ContentType = actualValue
29+
};
30+
var failureMessage = FailureMessageHelper.Format(FailureMessages.CommonFailMessage, "JsonResult.ContentType", expectedValue, actualValue);
31+
32+
Action a = () => result.Should().BeJsonResult().WithContentType(expectedValue);
2633

2734
a.Should().Throw<Exception>()
2835
.WithMessage(failureMessage);

0 commit comments

Comments
 (0)