Skip to content

Commit 2ba35e7

Browse files
committed
Improve Casting test's names.
1 parent 54ef634 commit 2ba35e7

9 files changed

+31
-68
lines changed

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,32 @@ public void WithControllerName_GivenUnexpectedControllerName_ShouldFail()
5555
}
5656

5757
[Fact]
58-
public void WithRouteValue_GivenKeyDoesntExist_ShouldFail()
58+
public void WithRouteValue_GivenExpectedKeyValuePair_ShouldPass()
5959
{
6060
var expectedKey = "expectedKey";
61-
var failureMessage = FailureMessageHelper.ExpectedContextContainValueAtKeyButKeyNotFound
62-
("AcceptedAtActionResult.RouteValues", "MyValue", expectedKey);
63-
var routeValues = new { myKey = "MyValue" };
61+
var expectedValue = "expectedValue";
62+
var routeValues = new { expectedKey = expectedValue };
6463
var result = new AcceptedAtActionResult(string.Empty, string.Empty, routeValues, null);
6564

66-
Action a = () => result.Should().BeAcceptedAtActionResult().WithRouteValue(expectedKey, "MyValue", Reason, ReasonArgs);
67-
68-
a.Should().Throw<Exception>().WithMessage(failureMessage);
65+
result.Should().BeAcceptedAtActionResult().WithRouteValue(expectedKey, expectedValue);
6966
}
7067

7168
[Fact]
72-
public void WithRouteValue_GivenExpectedKeyValuePair_ShouldPass()
69+
public void WithRouteValue_GivenKeyDoesntExist_ShouldFail()
7370
{
7471
var expectedKey = "expectedKey";
75-
var expectedValue = "expectedValue";
76-
var routeValues = new { expectedKey = expectedValue };
72+
var failureMessage = FailureMessageHelper.ExpectedContextContainValueAtKeyButKeyNotFound
73+
("AcceptedAtActionResult.RouteValues", "MyValue", expectedKey);
74+
var routeValues = new { myKey = "MyValue" };
7775
var result = new AcceptedAtActionResult(string.Empty, string.Empty, routeValues, null);
7876

79-
result.Should().BeAcceptedAtActionResult().WithRouteValue(expectedKey, expectedValue);
77+
Action a = () => result.Should().BeAcceptedAtActionResult().WithRouteValue(expectedKey, "MyValue", Reason, ReasonArgs);
78+
79+
a.Should().Throw<Exception>().WithMessage(failureMessage);
8080
}
8181

8282
[Fact]
83-
public void HaveValue_GivenUnexpectedKeyValuePair_ShouldFail()
83+
public void WithRouteValue_GivenUnexpectedKeyValuePair_ShouldFail()
8484
{
8585
var expectedKey = "expectedKey";
8686
var expectedValue = "expectedValue";
@@ -95,7 +95,7 @@ public void HaveValue_GivenUnexpectedKeyValuePair_ShouldFail()
9595
}
9696

9797
[Fact]
98-
public void ValueAs_GivenExpectedValue_ShouldPass()
98+
public void ValueAs_GivenAcceptedAtActionResult_ShouldHaveTheSameValue()
9999
{
100100
var result = new TestController().AcceptedAtAction(string.Empty, string.Empty, null, TestValue);
101101
result.Should().BeAcceptedAtActionResult().ValueAs<string>().Should().BeSameAs(TestValue);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void HaveValue_GivenUnexpectedKeyValuePair_ShouldFail()
7474
}
7575

7676
[Fact]
77-
public void ValueAs_GivenExpectedValue_ShouldPass()
77+
public void ValueAs_GivenAcceptedAtRouteResult_ShouldHaveTheSameValue()
7878
{
7979
var result = new TestController().AcceptedAtRoute(string.Empty, null, TestValue);
8080

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public class AcceptedResultAssertions_Tests
1919
private readonly Uri TestWrongUri = new Uri(TestWrongUriAsString);
2020

2121
[Fact]
22-
public void Value_GivenExpectedValue_ShouldPass()
22+
public void Value_GivenAcceptedResult_ShouldHaveTheSameValue()
2323
{
2424
var result = new TestController().Accepted(TestUri, TestValue);
2525

2626
result.Should().BeAcceptedResult().Value.Should().BeSameAs(TestValue);
2727
}
2828

2929
[Fact]
30-
public void ValueAs_GivenExpectedValue_ShouldPass()
30+
public void ValueAs_GivenAcceptedResult_ShouldHaveTheSameValue()
3131
{
3232
var result = new TestController().Accepted(TestUri, TestValue);
3333
result.Should().BeAcceptedResult().ValueAs<string>().Should().BeSameAs(TestValue);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class BadRequestObjectResultAssertions_Tests
1010
{
1111
private const string TestError = "testError";
1212
[Fact]
13-
public void Error_GivenExpectedError_ShouldPass()
13+
public void Error_GivenBadRequestObjectResult_ShouldHaveTheSameError()
1414
{
1515
var result = new TestController().BadRequest(TestError);
1616
result.Should().BeBadRequestObjectResult().Error.Should().BeSameAs(TestError);

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,10 @@ public void WithRouteValue_GivenUnexpectedValue_ShouldFail()
9797
}
9898

9999
[Fact]
100-
public void ValueAs_GivenExpectedValue_ShouldPass()
100+
public void ValueAs_GivenCreatedAtActionResult_ShouldHaveTheSameValue()
101101
{
102102
var result = new TestController().CreatedAtAction(string.Empty, string.Empty, null, TestValue);
103-
result.Should().BeCreatedAtActionResult().ValueAs<string>().Should().Be(TestValue);
104-
}
105-
106-
[Fact]
107-
public void ValueAs_GivenUnexpectedValue_ShouldFail()
108-
{
109-
var result = new TestController().CreatedAtAction(string.Empty, string.Empty, null, TestValue);
110-
Action a = () => result.Should().BeCreatedAtActionResult().ValueAs<string>().Should().Be("xyx");
111-
a.Should().Throw<Exception>();
103+
result.Should().BeCreatedAtActionResult().ValueAs<string>().Should().BeSameAs(TestValue);
112104
}
113105

114106
[Fact]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void WithRouteValue_GivenUnexpectedKeyValuePair_ShouldFail()
7272
}
7373

7474
[Fact]
75-
public void ValueAs_GivenExpectedValue_ShouldPass()
75+
public void ValueAs_GivenCreatedAtRouteResult_ShouldHaveTheSameValue()
7676
{
7777
var result = new TestController().CreatedAtRoute(string.Empty, null, TestValue);
7878

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ public class CreatedResultAssertions_Tests
1818
private readonly Uri TestWrongUri = new Uri(TestWrongUriAsString);
1919

2020
[Fact]
21-
public void Value_GivenExpectedValue_ShouldPass()
21+
public void Value_GivenCreatedResult_ShouldHaveTheSameValue()
2222
{
2323
var result = new TestController().Created(TestUri, TestValue);
2424

2525
result.Should().BeCreatedResult().Value.Should().BeSameAs(TestValue);
2626
}
2727

2828
[Fact]
29-
public void ValueAs_GivenExpectedValue_ShouldPass()
29+
public void ValueAs_GivenCreatedResult_ShouldHaveTheSameValue()
3030
{
3131
var result = new TestController().Created(TestUri, TestValue);
3232

33-
result.Should().BeCreatedResult().ValueAs<string>().Should().Be(TestValue);
33+
result.Should().BeCreatedResult().ValueAs<string>().Should().BeSameAs(TestValue);
3434
}
3535

3636
[Fact]

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

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,18 @@ public class NotFoundObjectResultAssertions_Tests
99
{
1010
private const string TestValue = "testValue";
1111
[Fact]
12-
public void Value_GivenExpectedValue_ShouldPass()
12+
public void Value_GivenNotFoundObjectResult_ShouldHaveTheSameValue()
1313
{
1414
var result = new TestController().NotFound(TestValue);
15-
result.Should().BeNotFoundObjectResult().Value.Should().Be(TestValue);
15+
result.Should().BeNotFoundObjectResult().Value.Should().BeSameAs(TestValue);
1616
}
1717

1818
[Fact]
19-
public void Value_GivenUnexpectedValue_ShouldFail()
19+
public void ValueAs_GivenNotFoundObjectResult_ShouldHaveTheSameValue()
2020
{
2121
var result = new TestController().NotFound(TestValue);
2222

23-
Action a = () => result.Should().BeNotFoundObjectResult().Value.Should().Be("xyx");
24-
a.Should().Throw<Exception>();
25-
}
26-
27-
[Fact]
28-
public void ValueAs_GivenExpectedValue_ShouldPass()
29-
{
30-
var result = new TestController().NotFound(TestValue);
31-
32-
result.Should().BeNotFoundObjectResult().ValueAs<string>().Should().Be(TestValue);
23+
result.Should().BeNotFoundObjectResult().ValueAs<string>().Should().BeSameAs(TestValue);
3324
}
3425

3526
[Fact]

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

+4-24
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,18 @@ public class OkObjectResultAssertions_Tests
99
{
1010
private const string TestValue = "testValue";
1111
[Fact]
12-
public void Value_GivenExpectedValue_ShouldPass()
12+
public void Value_GivenOkObjectResult_ShouldHaveTheSameValue()
1313
{
1414
var result = new TestController().Ok(TestValue);
15-
result.Should().BeOkObjectResult().Value.Should().Be(TestValue);
15+
result.Should().BeOkObjectResult().Value.Should().BeSameAs(TestValue);
1616
}
1717

1818
[Fact]
19-
public void Value_GivenUnexpectedValue_ShouldFail()
19+
public void ValueAs_GivenOkObjectResult_ShouldHaveTheSameValue()
2020
{
2121
var result = new TestController().Ok(TestValue);
2222

23-
Action a = () => result.Should().BeOkObjectResult().Value.Should().Be("xyx");
24-
25-
a.Should().Throw<Exception>();
26-
}
27-
28-
[Fact]
29-
public void ValueAs_GivenExpectedValue_ShouldPass()
30-
{
31-
var result = new TestController().Ok(TestValue);
32-
33-
result.Should().BeOkObjectResult().ValueAs<string>().Should().Be(TestValue);
34-
}
35-
36-
[Fact]
37-
public void ValueAs_GivenUnexpectedValue_ShouldFail()
38-
{
39-
var result = new TestController().Ok(TestValue);
40-
41-
Action a = () => result.Should().BeOkObjectResult().ValueAs<string>().Should().Be("xyx");
42-
43-
a.Should().Throw<Exception>();
23+
result.Should().BeOkObjectResult().ValueAs<string>().Should().BeSameAs(TestValue);
4424
}
4525

4626
[Fact]

0 commit comments

Comments
 (0)