Skip to content

Commit 741a8cf

Browse files
committed
Added missing tests for some action results (#359)
1 parent cc85008 commit 741a8cf

4 files changed

Lines changed: 101 additions & 9 deletions

File tree

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/ConflictTests/ConflictTestBuilderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
public class ConflictTestBuilderTests
1010
{
11+
[Fact]
12+
public void ConflictShouldNotThrowExceptionWithCorrectActionResult()
13+
{
14+
MyController<MvcController>
15+
.Instance()
16+
.Calling(c => c.ConflictAction())
17+
.ShouldReturn()
18+
.Conflict();
19+
}
20+
21+
[Fact]
22+
public void ConflictShouldThrowExceptionWithIncorrectActionResult()
23+
{
24+
Test.AssertException<InvocationResultAssertionException>(
25+
() =>
26+
{
27+
MyController<MvcController>
28+
.Instance()
29+
.Calling(c => c.OkResultAction())
30+
.ShouldReturn()
31+
.Conflict();
32+
},
33+
"When calling OkResultAction action in MvcController expected result to be ConflictResult, but instead received OkResult.");
34+
}
35+
1136
[Fact]
1237
public void WithStatusCodeShouldNotThrowExceptionWithCorrectStatusCode()
1338
{

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/SignInTests/SignInTestBuilderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
public class SignInTestBuilderTests
1010
{
11+
[Fact]
12+
public void SignInShouldNotThrowExceptionWithCorrectActionResult()
13+
{
14+
MyController<MvcController>
15+
.Instance()
16+
.Calling(c => c.SignInWithAuthenticationPropertiesAndScheme())
17+
.ShouldReturn()
18+
.SignIn();
19+
}
20+
21+
[Fact]
22+
public void ConflictShouldThrowExceptionWithIncorrectActionResult()
23+
{
24+
Test.AssertException<InvocationResultAssertionException>(
25+
() =>
26+
{
27+
MyController<MvcController>
28+
.Instance()
29+
.Calling(c => c.OkResultAction())
30+
.ShouldReturn()
31+
.SignIn();
32+
},
33+
"When calling OkResultAction action in MvcController expected result to be SignInResult, but instead received OkResult.");
34+
}
35+
1136
[Fact]
1237
public void ShouldReturnSignInShouldNotThrowExceptionIfResultIsSignInWithCorrectAuthenticationScheme()
1338
{

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/SignOutTests/SignOutTestBuilderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@
99

1010
public class SignOutTestBuilderTests
1111
{
12+
[Fact]
13+
public void SignInShouldNotThrowExceptionWithCorrectActionResult()
14+
{
15+
MyController<MvcController>
16+
.Instance()
17+
.Calling(c => c.SignOutWithAuthenticationProperties())
18+
.ShouldReturn()
19+
.SignOut();
20+
}
21+
22+
[Fact]
23+
public void ConflictShouldThrowExceptionWithIncorrectActionResult()
24+
{
25+
Test.AssertException<InvocationResultAssertionException>(
26+
() =>
27+
{
28+
MyController<MvcController>
29+
.Instance()
30+
.Calling(c => c.OkResultAction())
31+
.ShouldReturn()
32+
.SignOut();
33+
},
34+
"When calling OkResultAction action in MvcController expected result to be SignOutResult, but instead received OkResult.");
35+
}
36+
1237
[Fact]
1338
public void ShouldReturnSignOutShouldNotThrowExceptionIfResultIsSignOutWithCorrectAuthenticationScheme()
1439
{

test/MyTested.AspNetCore.Mvc.Controllers.ActionResults.Test/BuildersTests/ActionResultsTests/UnprocessableEntityTests/UnprocessableEntityTestBuilderTests.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
public class UnprocessableEntityTestBuilderTests
1010
{
11+
[Fact]
12+
public void UnprocessableEntityShouldNotThrowExceptionWithCorrectActionResult()
13+
{
14+
MyController<MvcController>
15+
.Instance()
16+
.Calling(c => c.UnprocessableEntityAction())
17+
.ShouldReturn()
18+
.UnprocessableEntity();
19+
}
20+
21+
[Fact]
22+
public void UnprocessableEntityShouldThrowExceptionWithIncorrectActionResult()
23+
{
24+
Test.AssertException<InvocationResultAssertionException>(
25+
() =>
26+
{
27+
MyController<MvcController>
28+
.Instance()
29+
.Calling(c => c.OkResultAction())
30+
.ShouldReturn()
31+
.UnprocessableEntity();
32+
},
33+
"When calling OkResultAction action in MvcController expected result to be UnprocessableEntityResult, but instead received OkResult.");
34+
}
35+
1136
[Fact]
1237
public void WithStatusCodeShouldNotThrowExceptionWithCorrectStatusCode()
1338
{
@@ -43,11 +68,7 @@ public void WithStatusCodeShouldThrowExceptionWithIncorrectStatusCode()
4368
.UnprocessableEntity(unprocessableEntity => unprocessableEntity
4469
.WithStatusCode(415));
4570
},
46-
#if NETCOREAPP
4771
"When calling UnprocessableEntityAction action in MvcController expected unprocessable entity result to have 415 (UnsupportedMediaType) status code, but instead received 422 (UnprocessableEntity).");
48-
#else
49-
"When calling UnprocessableEntityAction action in MvcController expected unprocessable entity result to have 415 (UnsupportedMediaType) status code, but instead received 422 (422).");
50-
#endif
5172
}
5273

5374
[Fact]
@@ -63,11 +84,7 @@ public void WithStatusCodeAsEnumShouldThrowExceptionWithIncorrectStatusCode()
6384
.UnprocessableEntity(unprocessableEntity => unprocessableEntity
6485
.WithStatusCode(HttpStatusCode.UnsupportedMediaType));
6586
},
66-
#if NETCOREAPP
6787
"When calling UnprocessableEntityAction action in MvcController expected unprocessable entity result to have 415 (UnsupportedMediaType) status code, but instead received 422 (UnprocessableEntity).");
68-
#else
69-
"When calling UnprocessableEntityAction action in MvcController expected unprocessable entity result to have 415 (UnsupportedMediaType) status code, but instead received 422 (422).");
70-
#endif
7188
}
7289

7390
[Fact]
@@ -107,7 +124,7 @@ public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion()
107124
.UnprocessableEntity(unprocessableEntity => unprocessableEntity
108125
.Passing(ue => ue.ContentTypes?.Count == 0));
109126
},
110-
$"When calling FullUnprocessableEntityAction action in MvcController expected the UnprocessableEntityObjectResult to pass the given predicate, but it failed.");
127+
"When calling FullUnprocessableEntityAction action in MvcController expected the UnprocessableEntityObjectResult to pass the given predicate, but it failed.");
111128
}
112129

113130
[Fact]

0 commit comments

Comments
 (0)