Skip to content

Commit 1f5a211

Browse files
committed
Fixed a bug with .PassingAs used in extension method with .Result (#359)
1 parent dc7c3c7 commit 1f5a211

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Base/BaseTestBuilderWithActionContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ private set
3333

3434
protected IAndTestBuilder Passing<TActionResult>(Action<TActionResult> assertions)
3535
{
36+
InvocationResultValidator.ValidateInvocationResultType<TActionResult>(this.TestContext);
37+
3638
assertions(this.TestContext.MethodResultAs<TActionResult>());
3739

3840
return new AndTestBuilder(this.TestContext);
3941
}
4042

4143
protected IAndTestBuilder Passing<TActionResult>(Func<TActionResult, bool> predicate)
4244
{
45+
InvocationResultValidator.ValidateInvocationResultType<TActionResult>(this.TestContext);
46+
4347
if (!predicate(this.TestContext.MethodResultAs<TActionResult>()))
4448
{
4549
throw new InvocationResultAssertionException(string.Format(

test/MyTested.AspNetCore.Mvc.Helpers.Test/BuildersTests/ActionResultsTests/CustomTests/CustomActionResultTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void CustomActionResultShouldNotThrowExceptionWithCorrectValues()
2121
[Fact]
2222
public void CustomActionResultShouldThrowExceptionWithIncorrectActionResult()
2323
{
24-
Test.AssertException<ResponseModelAssertionException>(
24+
Test.AssertException<InvocationResultAssertionException>(
2525
() =>
2626
{
2727
MyController<CustomActionResultController>
@@ -30,13 +30,13 @@ public void CustomActionResultShouldThrowExceptionWithIncorrectActionResult()
3030
.ShouldReturn()
3131
.Custom("Value", "CustomValue");
3232
},
33-
"When calling CustomActionResult action in CustomActionResultController expected response model CustomActionResult to pass the given predicate, but it failed.");
33+
"When calling Ok action in CustomActionResultController expected result to be CustomActionResult, but instead received OkResult.");
3434
}
3535

3636
[Fact]
37-
public void CustomActionResultShouldNotThrowExceptionWithIncorrectValues()
37+
public void CustomActionResultShouldThrowExceptionWithIncorrectValues()
3838
{
39-
Test.AssertException<ResponseModelAssertionException>(
39+
Test.AssertException<InvocationResultAssertionException>(
4040
() =>
4141
{
4242
MyController<CustomActionResultController>
@@ -45,7 +45,7 @@ public void CustomActionResultShouldNotThrowExceptionWithIncorrectValues()
4545
.ShouldReturn()
4646
.Custom("InvalidValue", "CustomValue");
4747
},
48-
"When calling CustomActionResult action in CustomActionResultController expected response model CustomActionResult to pass the given predicate, but it failed.");
48+
"When calling CustomActionResult action in CustomActionResultController expected the CustomActionResult to pass the given predicate, but it failed.");
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)