public void LinksBuilderThrows() { var httpContext = new DefaultHttpContext(); var context = new ControllerContext { HttpContext = httpContext }; var rootLinksBuilder = new Mock <IRootLinksBuilder>(); rootLinksBuilder.Setup(r => r.Build(context.HttpContext.Request)).Throws(new Exception()); var controller = new ApiRootHeadController(rootLinksBuilder.Object) { ControllerContext = context }; Assert.ThrowsAsync <Exception>(async() => await controller.HeadAsync()); }
public async Task ControllerSucceeds() { var httpContext = new DefaultHttpContext(); var context = new ControllerContext { HttpContext = httpContext }; var rootLinksBuilder = new Mock <IRootLinksBuilder>(); rootLinksBuilder.Setup(r => r.Build(context.HttpContext.Request)).Returns("daLinks"); var controller = new ApiRootHeadController(rootLinksBuilder.Object) { ControllerContext = context }; var actionResult = await controller.HeadAsync() as OkResult; Assert.NotNull(actionResult); }