public void MapType_Should_ReturnTypeAsErrorUri_WhenUseHelpLinkAsProblemDetailsTypeTrueAndDefaultHelpLinkForProblemDetailsTypeNull() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsExceptionMapper(optionsMock.Object); var exception = new ApplicationException(); var result = mapper.MapType(exception, new DefaultHttpContext()); result.Should().Be("error:application"); }
public void MapType_Should_ReturnResponseStatusCodeLinkUnauthorized_WhenUseHelpLinkAsProblemDetailsTypeTrue() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true, DefaultHelpLink = new Uri("http://www.example.com/help-page") }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsHttpResponseMapper(optionsMock.Object); var result = mapper.MapType(_unauthorizedHttpContext.Response); result.Should().Be(ResponseStatusCodeLink.Unauthorized); }
public void MapType_Should_ReturnDefaultHelpLink_WhenUseHelpLinkAsProblemDetailsTypeTrue() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true, DefaultHelpLink = new Uri("http://www.example.com/help-page") }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsExceptionMapper(optionsMock.Object); var exception = new ApplicationException(); var result = mapper.MapType(exception, new DefaultHttpContext()); result.Should().Be("http://www.example.com/help-page"); }
public void MapType_Should_ReturnTypeAsErrorUri_WhenUseHelpLinkAsProblemDetailsTypeTrueAndDefaultHelpLinkForProblemDetailsTypeNull() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsHttpResponseMapper(optionsMock.Object); var teapotHttpContext = new DefaultHttpContext(); teapotHttpContext.Request.Path = "/api/test/i-am-a-teapot"; teapotHttpContext.Response.StatusCode = 418; var result = mapper.MapType(teapotHttpContext.Response); result.Should().Be("error:418"); }
public void MapType_Should_ReturnExceptionHelpLink_WhenUseHelpLinkAsProblemDetailsTypeTrue() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true, DefaultHelpLink = new Uri("http://www.example.com/help-page") }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsExceptionMapper(optionsMock.Object); var helpLink = "https://docs.microsoft.com/en-us/dotnet/api/system.exception.helplink?view=netcore-2.2"; var exception = new ApplicationException { HelpLink = helpLink }; var result = mapper.MapType(exception, new DefaultHttpContext()); result.Should().Be(helpLink); }
public void MapType_Should_ReturnDefaultHelpLink_WhenUseHelpLinkAsProblemDetailsTypeTrue() { var options = new HttpExceptionsOptions { UseHelpLinkAsProblemDetailsType = true, DefaultHelpLink = new Uri("http://www.example.com/help-page") }; var optionsMock = new Mock <IOptions <HttpExceptionsOptions> >(); optionsMock.Setup(o => o.Value).Returns(options); var mapper = new ExposeProtectedProblemDetailsHttpResponseMapper(optionsMock.Object); var teapotHttpContext = new DefaultHttpContext(); teapotHttpContext.Request.Path = "/api/test/i-am-a-teapot"; teapotHttpContext.Response.StatusCode = 418; var result = mapper.MapType(teapotHttpContext.Response); result.Should().Be("http://www.example.com/help-page"); }