public void Should_add_response_cookie_if_it_has_changed() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake <IPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithSerializer(this.fakeObjectSerializer); var request = CreateRequest("encryptedkey1=value1"); A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;"); var response = A.Fake <Response>(); var nancyContext = new NancyContext() { Request = request, Response = response }; beforePipeline.Invoke(nancyContext, new CancellationToken()); request.Session["Testing"] = "Test"; afterPipeline.Invoke(nancyContext, new CancellationToken()); response.Cookies.Count.ShouldEqual(1); }
public async Task Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines() { // Given var item1Called = false; Func <NancyContext, Response> item1 = (r) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Response> item2 = (r) => { item2Called = true; return(null); }; var item3Called = false; Func <NancyContext, Response> item3 = (r) => { item3Called = true; return(null); }; var item4Called = false; Func <NancyContext, Response> item4 = (r) => { item4Called = true; return(null); }; pipeline += item1; pipeline += item2; var subPipeline = new BeforePipeline(); subPipeline += item3; subPipeline += item4; // When pipeline.AddItemToEndOfPipeline(subPipeline); await pipeline.Invoke(CreateContext(), new CancellationToken()); // Then Assert.True(item1Called); Assert.True(item2Called); Assert.True(item3Called); Assert.True(item4Called); }
public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines() { var item1Called = false; Func <NancyContext, Response> item1 = (r) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Response> item2 = (r) => { item2Called = true; return(null); }; var item3Called = false; Func <NancyContext, Response> item3 = (r) => { item3Called = true; return(null); }; var item4Called = false; Func <NancyContext, Response> item4 = (r) => { item4Called = true; return(null); }; pipeline += item1; pipeline += item2; var subPipeline = new BeforePipeline(); subPipeline += item3; subPipeline += item4; pipeline.AddItemToEndOfPipeline(subPipeline); pipeline.Invoke(CreateContext()); Assert.True(item1Called); Assert.True(item2Called); Assert.True(item3Called); Assert.True(item4Called); }
public void Should_add_response_cookie_if_it_has_changed() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake <IApplicationPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); CookieBasedSessions.Enable(hooks, encryptionProvider, hmacProvider, "this passphrase", "this is a salt", "hmac passphrase").WithFormatter(new Fakes.FakeSessionObjectFormatter()); var request = CreateRequest("encryptedkey1=value1"); A.CallTo(() => this.encryptionProvider.Decrypt("encryptedkey1=value1", A <string> .Ignored, A <byte[]> .Ignored)).Returns("key1=value1;"); var response = A.Fake <Response>(); var nancyContext = new NancyContext() { Request = request, Response = response }; beforePipeline.Invoke(nancyContext); request.Session["Testing"] = "Test"; afterPipeline.Invoke(nancyContext); response.Cookies.Count.ShouldEqual(1); }
public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines() { // Given var item1Called = false; Func<NancyContext, Response> item1 = (r) => { item1Called = true; return null; }; var item2Called = false; Func<NancyContext, Response> item2 = (r) => { item2Called = true; return null; }; var item3Called = false; Func<NancyContext, Response> item3 = (r) => { item3Called = true; return null; }; var item4Called = false; Func<NancyContext, Response> item4 = (r) => { item4Called = true; return null; }; pipeline += item1; pipeline += item2; var subPipeline = new BeforePipeline(); subPipeline += item3; subPipeline += item4; // When pipeline.AddItemToEndOfPipeline(subPipeline); pipeline.Invoke(CreateContext(), new CancellationToken()); // Then Assert.True(item1Called); Assert.True(item2Called); Assert.True(item3Called); Assert.True(item4Called); }
private static Task <Response> ExecuteRoutePreReq(NancyContext context, CancellationToken cancellationToken, BeforePipeline resolveResultPreReq) { if (resolveResultPreReq == null) { return(TaskHelpers.GetCompletedTask <Response>(null)); } return(resolveResultPreReq.Invoke(context, cancellationToken)); }
public void When_invoked_pipeline_member_returning_a_response_stops_pipeline_execution() { var item1Called = false; Func <NancyContext, Response> item1 = (r) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Response> item2 = (r) => { item2Called = true; return(CreateResponse()); }; var item3Called = false; Func <NancyContext, Response> item3 = (r) => { item3Called = true; return(null); }; pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(item3); pipeline.Invoke(CreateContext()); Assert.True(item1Called); Assert.True(item2Called); Assert.False(item3Called); }
public async Task When_invoked_pipeline_member_returning_a_response_stops_pipeline_execution() { // Given var item1Called = false; Func <NancyContext, Response> item1 = (r) => { item1Called = true; return(null); }; var item2Called = false; Func <NancyContext, Response> item2 = (r) => { item2Called = true; return(CreateResponse()); }; var item3Called = false; Func <NancyContext, Response> item3 = (r) => { item3Called = true; return(null); }; pipeline.AddItemToEndOfPipeline(item1); pipeline.AddItemToEndOfPipeline(item2); pipeline.AddItemToEndOfPipeline(item3); // When await pipeline.Invoke(CreateContext(), new CancellationToken()); // Then Assert.True(item1Called); Assert.True(item2Called); Assert.False(item3Called); }
private static void ExecuteRoutePreReq(NancyContext context, CancellationToken cancellationToken, BeforePipeline resolveResultPreReq) { if (resolveResultPreReq == null) { return; } var resolveResultPreReqResponse = resolveResultPreReq.Invoke(context, cancellationToken).Result; if (resolveResultPreReqResponse != null) { context.Response = resolveResultPreReqResponse; } }
public void Should_add_response_cookie_if_it_has_changed() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake<IApplicationPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); CookieBasedSessions.Enable(hooks, encryptionProvider, "this passphrase", "this is a salt").WithFormatter(new Fakes.FakeSessionObjectFormatter()); var request = CreateRequest("encryptedkey1=value1"); A.CallTo(() => this.encryptionProvider.Decrypt("encryptedkey1=value1", A<string>.Ignored, A<byte[]>.Ignored)).Returns("key1=value1;"); var response = A.Fake<Response>(); var nancyContext = new NancyContext() { Request = request, Response = response }; beforePipeline.Invoke(nancyContext); request.Session["Testing"] = "Test"; afterPipeline.Invoke(nancyContext); response.Cookies.Count.ShouldEqual(1); }
public void Should_add_response_cookie_if_it_has_changed() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake<IPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithSerializer(this.fakeObjectSerializer); var request = CreateRequest("encryptedkey1=value1"); A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;"); var response = A.Fake<Response>(); var nancyContext = new NancyContext() { Request = request, Response = response }; beforePipeline.Invoke(nancyContext, new CancellationToken()); request.Session["Testing"] = "Test"; afterPipeline.Invoke(nancyContext, new CancellationToken()); response.Cookies.Count.ShouldEqual(1); }
public void Should_set_formatter_when_using_formatter_selector() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake <IPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); var fakeFormatter = A.Fake <IObjectSerializer>(); A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;"); CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithSerializer(fakeFormatter); var request = CreateRequest("encryptedkey1=value1"); var nancyContext = new NancyContext() { Request = request }; beforePipeline.Invoke(nancyContext, new CancellationToken()); A.CallTo(() => fakeFormatter.Deserialize(A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
public void Should_set_formatter_when_using_formatter_selector() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake <IApplicationPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); var fakeFormatter = A.Fake <ISessionObjectFormatter>(); A.CallTo(() => this.encryptionProvider.Decrypt("encryptedkey1=value1", A <string> .Ignored, A <byte[]> .Ignored)).Returns("key1=value1;"); CookieBasedSessions.Enable(hooks, encryptionProvider, hmacProvider, "this passphrase", "this is a salt", "hmac passphrase").WithFormatter(fakeFormatter); var request = CreateRequest("encryptedkey1=value1"); var nancyContext = new NancyContext() { Request = request }; beforePipeline.Invoke(nancyContext); A.CallTo(() => fakeFormatter.Deserialize(A <string> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
private static Task <Response> InvokePreRequestHook(Context context, CancellationToken cancellationToken, BeforePipeline pipeline) { return(pipeline == null?Task.FromResult <Response>(null) : pipeline.Invoke(context, cancellationToken)); }
public void Should_only_not_add_response_cookie_if_it_has_not_changed() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake<IApplicationPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithFormatter(new Fakes.FakeSessionObjectFormatter()); var request = CreateRequest("encryptedkey1=value1"); A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;"); var response = A.Fake<Response>(); var nancyContext = new NancyContext() { Request = request, Response = response }; beforePipeline.Invoke(nancyContext); afterPipeline.Invoke(nancyContext); response.Cookies.Count.ShouldEqual(0); }
public void Should_set_formatter_when_using_formatter_selector() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake<IPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); var fakeFormatter = A.Fake<IObjectSerializer>(); A.CallTo(() => this.fakeEncryptionProvider.Decrypt("encryptedkey1=value1")).Returns("key1=value1;"); CookieBasedSessions.Enable(hooks, new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider)).WithSerializer(fakeFormatter); var request = CreateRequest("encryptedkey1=value1"); var nancyContext = new NancyContext() { Request = request }; beforePipeline.Invoke(nancyContext, new CancellationToken()); A.CallTo(() => fakeFormatter.Deserialize(A<string>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
private static Task<Response> ExecuteRoutePreReq(NancyContext context, CancellationToken cancellationToken, BeforePipeline resolveResultPreReq) { if (resolveResultPreReq == null) { return TaskHelpers.GetCompletedTask<Response>(null); } return resolveResultPreReq.Invoke(context, cancellationToken); }
public void Should_set_formatter_when_using_formatter_selector() { var beforePipeline = new BeforePipeline(); var afterPipeline = new AfterPipeline(); var hooks = A.Fake<IApplicationPipelines>(); A.CallTo(() => hooks.BeforeRequest).Returns(beforePipeline); A.CallTo(() => hooks.AfterRequest).Returns(afterPipeline); var fakeFormatter = A.Fake<ISessionObjectFormatter>(); A.CallTo(() => this.encryptionProvider.Decrypt("encryptedkey1=value1", A<string>.Ignored, A<byte[]>.Ignored)).Returns("key1=value1;"); CookieBasedSessions.Enable(hooks, encryptionProvider, "this passphrase", "this is a salt").WithFormatter(fakeFormatter); var request = CreateRequest("encryptedkey1=value1"); var nancyContext = new NancyContext() { Request = request }; beforePipeline.Invoke(nancyContext); A.CallTo(() => fakeFormatter.Deserialize(A<string>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }