public void Can_create_exception_with_status_code() { var sut = new HttpProblemDetails { Status = (int)HttpStatusCode.BadRequest }; sut.Status.Should().Be((int)HttpStatusCode.BadRequest); }
public HttpProblemDetailsShould() { _browser = new Browser(with => { with.RequestStartup((container, pipelines, context) => HttpProblemDetails.Enable(pipelines, container.Resolve <IResponseNegotiator>())); with.Module <PaymentModule>(); }); }
public void When_setting_instance_with_a_relative_uri_should_throw() { var sut = new HttpProblemDetails { Status = (int)HttpStatusCode.BadRequest }; Action act = () => sut.Instance = "/relative"; act.ShouldThrow <InvalidOperationException>(); }
public CommandModule() { For <CommandThatIsAccepted>().Handle(message => Console.WriteLine("Command {0} with {1}", message.CommandId, message.Command.Value)); For <CommandThatThrowsProblemDetailsException>().Handle(_ => { var details = new HttpProblemDetails { Status = (int)HttpStatusCode.BadRequest, Title = "A Bad Request", Detail = "A command that is not accepted" }; throw new HttpProblemDetailsException <HttpProblemDetails>(details); }); }
private CommandHandlerModule CreateCommandHandlerModule() { var module = new CommandHandlerModule(); module.For <Command>() .Handle(commandMessage => { _receivedCommands.Add(commandMessage); }); module.For <CommandThatThrowsStandardException>() .Handle(_ => { throw new InvalidOperationException(); }); module.For <CommandThatThrowsProblemDetailsException>() .Handle((_, __) => { var problemDetails = new HttpProblemDetails { Status = (int)HttpStatusCode.BadRequest, Type = "http://localhost/type", Detail = "You done goof'd", Instance = "http://localhost/errors/1", Title = "Jimmies Ruslted" }; throw new HttpProblemDetailsException <HttpProblemDetails>(problemDetails); }); module.For <CommandThatThrowsMappedException>() .Handle((_, __) => { throw new ApplicationException("Mapped application exception"); }); module.For <CommandThatThrowsCustomProblemDetailsException>() .Handle((_, __) => { var problemDetails = new CustomHttpProblemDetails() { Status = (int)HttpStatusCode.BadRequest, Type = "http://localhost/type", Detail = "You done goof'd", Instance = "http://localhost/errors/1", Title = "Jimmies Ruslted", Name = "Damo" }; throw new CustomProblemDetailsException(problemDetails); }); return(module); }
// 1. Example of handlers thowing the various exceptions public CommandModule() { For <CommandThatThrowsStandardException>() .Handle(_ => { // 2. Standard exception that will result in a 404 throw new Exception(); }); For <CommandThatThrowsProblemDetailsException>() .Handle(_ => { // 3. Throwing an explicit HttpProblemDetailsException var details = new HttpProblemDetails { Status = (int)HttpStatusCode.NotImplemented }; throw new HttpProblemDetailsException <HttpProblemDetails>(details); }); For <CommandThatThrowsMappedException>() .Handle(_ => { // 4. This exception type is mapped to an HttpProblemDetails in the settings. throw new InvalidOperationException("jimms rustled"); }); For <CommandThatThrowsCustomProblemDetailsException>() .Handle(_ => { // 5. Throwing custom problem details exception. var problemDetails = new CustomHttpProblemDetails { Status = (int)HttpStatusCode.NotImplemented, Name = "Damo" }; throw new CustomHttpProblemDetailsException(problemDetails); }); }
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { HttpProblemDetails.Enable(pipelines, container.Resolve <IResponseNegotiator>()); }