public void HelloWorldTest() { // resolve mock service var mockService = GetContainer().Resolve<IHelloWorldService>(); // Use default constructor with resolved mock service TestController target = new TestController(mockService); ContentResult actual; actual = target.HelloWorld(); Assert.IsTrue(actual.Content.StartsWith("I'm a mock service.")); }
private static TestController GetTestController() { RequestContext requestContext = new RequestContext(new MockHttpContext(), new RouteData()); IHelloWorldService hellowWorldService = new MockHelloWorldService(); TestController controller = new TestController(hellowWorldService) { Url = new UrlHelper(requestContext), }; controller.ControllerContext = new ControllerContext() { Controller = controller, RequestContext = requestContext }; return controller; }