Skip to content

Commit 10ac900

Browse files
committed
Fix test (ApiControllerTest.Setting_CustomActionSelector()) that now hits NRE
- aspnet#20 - provide a controller instance and use one of its methods - avoids NRE because compiler now generates an instance method for `testDelegate` - makes tested scenario more realistic
1 parent 31bfa83 commit 10ac900

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/System.Web.Http.Test/Controllers/ApiControllerTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public async Task Setting_CustomActionInvoker()
6969
public async Task Setting_CustomActionSelector()
7070
{
7171
// Arrange
72-
ApiController api = new UsersController();
73-
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext();
72+
var api = new UsersController();
73+
HttpControllerContext controllerContext = ContextUtil.CreateControllerContext(instance: api);
7474

7575
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(controllerContext.Configuration, "test", typeof(UsersController));
7676
controllerContext.ControllerDescriptor = controllerDescriptor;
@@ -80,8 +80,7 @@ public async Task Setting_CustomActionSelector()
8080
.Setup(invoker => invoker.SelectAction(It.IsAny<HttpControllerContext>()))
8181
.Returns(() =>
8282
{
83-
Func<HttpResponseMessage> testDelegate =
84-
() => new HttpResponseMessage { Content = new StringContent("This is a test") };
83+
Func<HttpResponseMessage> testDelegate = api.Delete;
8584
return new ReflectedHttpActionDescriptor
8685
{
8786
Configuration = controllerContext.Configuration,
@@ -97,7 +96,7 @@ public async Task Setting_CustomActionSelector()
9796
CancellationToken.None);
9897

9998
// Assert
100-
Assert.Equal("This is a test", await message.Content.ReadAsStringAsync());
99+
Assert.Equal("User deleted", await message.Content.ReadAsStringAsync());
101100
}
102101

103102
[Fact]

0 commit comments

Comments
 (0)