public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines() { // Given var item1Called = false; Func <NancyContext, Exception, Response> item1 = (ctx, ex) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Exception, Response> item2 = (ctx, ex) => { item2Called = true; return(null); }; var item3Called = false; Func <NancyContext, Exception, Response> item3 = (ctx, ex) => { item3Called = true; return(null); }; var item4Called = false; Func <NancyContext, Exception, Response> item4 = (ctx, ex) => { item4Called = true; return(null); }; pipeline += item1; pipeline += item2; var subPipeline = new ErrorPipeline(); subPipeline += item3; subPipeline += item4; // When pipeline.AddItemToEndOfPipeline(subPipeline); pipeline.Invoke(CreateContext(), new Exception()); // Then item1Called.ShouldBeTrue(); item2Called.ShouldBeTrue(); item3Called.ShouldBeTrue(); item4Called.ShouldBeTrue(); }
public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines() { // Given var item1Called = false; Func<NancyContext, Exception, dynamic> item1 = (ctx, ex) => { item1Called = true; return null; }; var item2Called = false; Func<NancyContext, Exception, dynamic> item2 = (ctx, ex) => { item2Called = true; return null; }; var item3Called = false; Func<NancyContext, Exception, dynamic> item3 = (ctx, ex) => { item3Called = true; return null; }; var item4Called = false; Func<NancyContext, Exception, dynamic> item4 = (ctx, ex) => { item4Called = true; return null; }; pipeline += item1; pipeline += item2; var subPipeline = new ErrorPipeline(); subPipeline += item3; subPipeline += item4; // When pipeline.AddItemToEndOfPipeline(subPipeline); pipeline.Invoke(CreateContext(), new Exception()); // Then item1Called.ShouldBeTrue(); item2Called.ShouldBeTrue(); item3Called.ShouldBeTrue(); item4Called.ShouldBeTrue(); }
private static void InvokeOnErrorHook(Context context, ErrorPipeline pipeline, Exception errorException) { try { if (pipeline == null) { throw new RequestPipelinesException(errorException); } var onErrorResult = pipeline.Invoke(context, errorException); if (onErrorResult == null) { throw new RequestPipelinesException(errorException); } context.Response = new Response { StatusCode = HttpStatusCode.InternalServerError }; } catch (Exception) { context.Response = new Response { StatusCode = HttpStatusCode.InternalServerError }; } }
public void When_cast_to_func_and_invoked_members_are_invoked() { // Given var item1Called = false; Func <NancyContext, Exception, Response> item1 = (ctx, ex) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Exception, Response> item2 = (ctx, ex) => { item2Called = true; return(null); }; var item3Called = false; Func <NancyContext, Exception, Response> item3 = (ctx, ex) => { item3Called = true; return(null); }; pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(item3); // When pipeline.Invoke(CreateContext(), new Exception()); // Then item1Called.ShouldBeTrue(); item2Called.ShouldBeTrue(); item3Called.ShouldBeTrue(); }
private static void InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex) { try { if (pipeline == null) { throw new RequestExecutionException(ex); } var onErrorResponse = pipeline.Invoke(context, ex); if (onErrorResponse == null) { throw new RequestExecutionException(ex); } context.Response = onErrorResponse; } catch (Exception e) { context.Response = new Response { StatusCode = HttpStatusCode.InternalServerError }; context.Items[ERROR_KEY] = e.ToString(); context.Items[ERROR_EXCEPTION] = e; } }
public void GivenExceptionIsNotSecurityException_WhenRunningPipeline_ThenReturnsNull() { var result = _sut.Invoke(A.Dummy <NancyContext>(), new InvalidOperationException()); Assert.That(result, Is.Null); }