Trying to Test a Controller with a UrlHelper
问题 Trying to create a URLHelper for testing purposes throws a NullReferenceException . Example: [Fact] public async void AuthenticateAsyncTest() { // Arrange var controller = new Controller(serviceProvider) { Url = new UrlHelper(new ActionContext()) // Exception thrown }; // Act var result = await controller.Authenticate() as ViewResult; // Assert Assert.NotNull(result); } Every time I run this Test, the Exception that is thrown in Url = new UrlHelper(new ActionContext()) is: Exception.Message: