public async Task should_preserve_stacktrace_when_rethrowing_the_excption() { // Given var route = new FakeRoute { Action = (o, ct) => BrokenMethod() }; var before = new BeforePipeline(); before += ctx => null; var after = new AfterPipeline(); after += ctx => { }; var resolvedRoute = new ResolveResult( route, DynamicDictionary.Empty, before, after, (ctx, ex) => null); A.CallTo(() => this.routeResolver.Resolve(A <NancyContext> .Ignored)).Returns(resolvedRoute); var context = new NancyContext { Request = new Request("GET", "/", "http") }; var exception = await RecordAsync.Exception(async() => await this.requestDispatcher.Dispatch(context, new CancellationToken())); exception.StackTrace.ShouldContain("BrokenMethod"); }
public async Task HandleRequest_Should_Throw_ArgumentNullException_When_Given_A_Null_Request() { // Given, Request request = null; // When var exception = await RecordAsync.Exception(async() => await engine.HandleRequest(request)); // Then exception.ShouldBeOfType <ArgumentNullException>(); }
public async Task Should_not_try_and_serve_view_with_invalid_name() { // Given var browser = new Browser(with => with.Module <NegotiationModule>()); // When var result = await RecordAsync.Exception(() => browser.Get("/invalid-view-name")); // Then Assert.True(result.ToString().Contains("Unable to locate view")); }
public async Task When_Partial_View_Could_Not_Be_Found_An_Meaningful_Exception_Should_Be_Thrown() { var ex = await RecordAsync.Exception(async() => { var response = await this.browser.Get(@"/razor-partialnotfound"); response.Body.AsString(); }); Assert.IsType <ViewNotFoundException>(ex.GetBaseException()); }
public async Task Should_throw_an_exception_when_the_cert_couldnt_be_found() { //Given, When var exception = await RecordAsync.Exception(() => { return(browser.Get("/ajax", with => with.Certificate( StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "aa aa aa"))); }); //Then exception.ShouldBeOfType <InvalidOperationException>(); }
public async Task Should_throw_operationcancelledexception_when_disposed_handling_request() { // Given var request = new Request("GET", "/", "http"); var engine = new NancyEngine(A.Fake <IRequestDispatcher>(), A.Fake <INancyContextFactory>(), new[] { this.statusCodeHandler }, A.Fake <IRequestTracing>(), new DisabledStaticContentProvider(), this.negotiator, this.environment); engine.Dispose(); // When var exception = await RecordAsync.Exception(async() => await engine.HandleRequest(request)); // Then exception.ShouldBeOfType <OperationCanceledException>(); }
public async Task Should_throw_exception_if_view_location_fails() { var browser = new Browser(with => { with.ResponseProcessor <ViewProcessor>(); with.Module(new ConfigurableNancyModule(x => x.Get("/FakeModuleInvalidViewName", CreateNegotiatedResponse(neg => neg.WithView("blahblahblah"))))); }); // When var result = await RecordAsync.Exception(() => browser.Get( "/FakeModuleInvalidViewName", with => { with.Accept("text/html", 1.0m); }) ); // Then Assert.NotNull(result); Assert.Contains("Unable to locate view", result.ToString()); }
public async Task When_AutoRegistration_Is_Enabled_Should_Throw() { var ex = await RecordAsync.Exception(async() => { // Given var bootstrapper = new ConfigurableBootstrapper(config => { config.Module <NoAppStartupsModule>(); config.Dependency <INoAppStartupsTestDependency>(typeof(AutoDependency)); }); var browser = new Browser(bootstrapper); // When await browser.Get("/"); }); //Then ex.ShouldNotBeNull(); }
public async Task Should_not_rethrow_exception_when_onerror_hook_returns_response() { // Given var route = new FakeRoute { Action = (parameters, ct) => TaskHelpers.GetFaultedTask <dynamic>(new Exception()) }; var before = new BeforePipeline(); before += ctx => null; var after = new AfterPipeline(); after += ctx => { }; var resolvedRoute = new ResolveResult( route, DynamicDictionary.Empty, before, after, (ctx, ex) => new Response()); A.CallTo(() => this.routeResolver.Resolve(A <NancyContext> .Ignored)).Returns(resolvedRoute); var context = new NancyContext { Request = new Request("GET", "/", "http") }; //When var exception = await RecordAsync.Exception(async() => await this.requestDispatcher.Dispatch(context, new CancellationToken())); // Then exception.ShouldBeNull(); }
public async Task When_get_async_then_should_throw() { var ex = await RecordAsync.Exception(async() => await this.browser.Get("/sync")); Assert.NotNull(ex); }