本文整理汇总了C#中AfterPipeline类的典型用法代码示例。如果您正苦于以下问题:C# AfterPipeline类的具体用法?C# AfterPipeline怎么用?C# AfterPipeline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AfterPipeline类属于命名空间,在下文中一共展示了AfterPipeline类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HandleRequest_should_allow_module_after_hook_to_add_items_to_context
public void HandleRequest_should_allow_module_after_hook_to_add_items_to_context()
{
// Given
var route = new FakeRoute();
var before = new BeforePipeline();
before += ctx => null;
var after = new AfterPipeline();
after += ctx => ctx.Items.Add("RoutePostReq", new object());
var resolvedRoute = new ResolveResult(
route,
DynamicDictionary.Empty,
before,
after,
null);
A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
var context =
new NancyContext { Request = new Request("GET", "/", "http") };
// When
this.requestDispatcher.Dispatch(context, new CancellationToken());
// Then
context.Items.ContainsKey("RoutePostReq").ShouldBeTrue();
}
开发者ID:rahulchrty,项目名称:Nancy,代码行数:29,代码来源:DefaultRequestDispatcherFixture.cs
示例2: When_cast_from_func_creates_a_pipeline_with_one_item
public void When_cast_from_func_creates_a_pipeline_with_one_item()
{
var castPipeline = new AfterPipeline();
castPipeline += r => { };
Assert.Equal(1, castPipeline.PipelineDelegates.Count());
}
开发者ID:JulianRooze,项目名称:Nancy,代码行数:7,代码来源:AfterPipelineFixture.cs
示例3: ResolveResult
/// <summary>
/// Initializes a new instance of the <see cref="ResolveResult"/> class, with
/// the provided <paramref name="route"/>, <paramref name="parameters"/>, <paramref name="before"/>,
/// <paramref name="after"/> and <paramref name="onError"/>.
/// </summary>
/// <param name="route">The request route instance.</param>
/// <param name="parameters">The parameters.</param>
/// <param name="before">The before pipeline instance</param>
/// <param name="after">The after pipeline instace.</param>
/// <param name="onError">The on error interceptor instance.</param>
public ResolveResult(Route route, DynamicDictionary parameters, BeforePipeline before, AfterPipeline after, Func<NancyContext, Exception, dynamic> onError)
{
this.Route = route;
this.Parameters = parameters;
this.Before = before;
this.After = after;
this.OnError = onError;
}
开发者ID:uliian,项目名称:Nancy,代码行数:18,代码来源:ResolveResult.cs
示例4: Should_add_pre_and_post_hooks_when_enabled
public void Should_add_pre_and_post_hooks_when_enabled() {
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);
hooks.Enable(_fakeSessionManager);
Assert.Equal(1, beforePipeline.PipelineDelegates.Count());
Assert.Equal(1, afterPipeline.PipelineItems.Count());
}
开发者ID:DavidLievrouw,项目名称:Nancy.Session.InProc,代码行数:12,代码来源:InProcSessionsFixture.cs
示例5: ExecutePost
private static void ExecutePost(NancyContext context, CancellationToken cancellationToken, AfterPipeline postHook, Func<NancyContext, Exception, Response> onError, TaskCompletionSource<Response> tcs)
{
if (postHook == null)
{
tcs.SetResult(context.Response);
return;
}
postHook.Invoke(context, cancellationToken).WhenCompleted(
completedTask => tcs.SetResult(context.Response),
completedTask => HandlePostHookFaultedTask(context, onError, completedTask, tcs),
false);
}
开发者ID:adglopez,项目名称:Nancy,代码行数:13,代码来源:DefaultRequestDispatcher.cs
示例6: Should_add_pre_and_post_hooks_when_enabled
public void Should_add_pre_and_post_hooks_when_enabled()
{
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");
beforePipeline.PipelineItems.Count().ShouldEqual(1);
afterPipeline.PipelineItems.Count().ShouldEqual(1);
}
开发者ID:ToJans,项目名称:Nancy,代码行数:13,代码来源:CookieBasedSessionsFixture.cs
示例7: Should_add_pre_and_post_hooks_when_enabled
public void Should_add_pre_and_post_hooks_when_enabled()
{
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));
beforePipeline.PipelineDelegates.Count().ShouldEqual(1);
afterPipeline.PipelineItems.Count().ShouldEqual(1);
}
开发者ID:Borzoo,项目名称:Nancy,代码行数:13,代码来源:CookieBasedSessionsFixture.cs
示例8: PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline
public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
{
pipeline.AddItemToEndOfPipeline(r => { });
pipeline.AddItemToEndOfPipeline(r => { });
var pipeline2 = new AfterPipeline();
pipeline2.AddItemToEndOfPipeline(r => { });
pipeline2.AddItemToEndOfPipeline(r => { });
pipeline += pipeline2;
Assert.Equal(4, pipeline.PipelineItems.Count());
Assert.Same(pipeline2.PipelineDelegates.ElementAt(0), pipeline.PipelineDelegates.ElementAt(2));
Assert.Same(pipeline2.PipelineDelegates.ElementAt(1), pipeline.PipelineDelegates.Last());
}
开发者ID:JulianRooze,项目名称:Nancy,代码行数:14,代码来源:AfterPipelineFixture.cs
示例9: Should_invoke_module_before_hook_followed_by_resolved_route_followed_by_module_after_hook
public async Task Should_invoke_module_before_hook_followed_by_resolved_route_followed_by_module_after_hook()
{
// Given
var capturedExecutionOrder = new List<string>();
var expectedExecutionOrder = new[] { "Prehook", "RouteInvoke", "Posthook" };
var route = new FakeRoute
{
Action = (parameters, token) =>
{
capturedExecutionOrder.Add("RouteInvoke");
return Task.FromResult<object>(null);
}
};
var before = new BeforePipeline();
before += (ctx) =>
{
capturedExecutionOrder.Add("Prehook");
return null;
};
var after = new AfterPipeline();
after += (ctx) =>
{
capturedExecutionOrder.Add("Posthook");
};
var resolvedRoute = new ResolveResult
{
Route = route,
Parameters = DynamicDictionary.Empty,
Before = before,
After = after,
OnError = null
};
A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
var context =
new NancyContext { Request = new Request("GET", "/", "http") };
// When
await this.requestDispatcher.Dispatch(context, new CancellationToken());
// Then
capturedExecutionOrder.Count().ShouldEqual(3);
capturedExecutionOrder.SequenceEqual(expectedExecutionOrder).ShouldBeTrue();
}
开发者ID:sloncho,项目名称:Nancy,代码行数:49,代码来源:DefaultRequestDispatcherFixture.cs
示例10: PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline
public void PlusEquals_with_another_pipeline_adds_those_pipeline_items_to_end_of_pipeline()
{
Action<NancyContext> item1 = (r) => { };
Action<NancyContext> item2 = (r) => { };
pipeline.AddItemToEndOfPipeline(item1);
pipeline.AddItemToEndOfPipeline(item2);
Action<NancyContext> item3 = (r) => { };
Action<NancyContext> item4 = (r) => { };
var pipeline2 = new AfterPipeline();
pipeline2.AddItemToEndOfPipeline(item3);
pipeline2.AddItemToEndOfPipeline(item4);
pipeline += pipeline2;
Assert.Equal(4, pipeline.PipelineItems.Count());
Assert.Same(item3, pipeline.PipelineDelegates.ElementAt(2));
Assert.Same(item4, pipeline.PipelineDelegates.Last());
}
开发者ID:leoduran,项目名称:Nancy,代码行数:18,代码来源:AfterPipelineFixture.cs
示例11: Should_add_response_cookie_if_it_has_changed
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);
}
开发者ID:Borzoo,项目名称:Nancy,代码行数:19,代码来源:CookieBasedSessionsFixture.cs
示例12: Should_add_response_cookie_if_it_has_changed
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);
}
开发者ID:ToJans,项目名称:Nancy,代码行数:19,代码来源:CookieBasedSessionsFixture.cs
示例13: Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines
public void Pipeline_containing_another_pipeline_will_invoke_items_in_both_pipelines()
{
var item1Called = false;
Action<NancyContext> item1 = (r) => { item1Called = true; };
var item2Called = false;
Action<NancyContext> item2 = (r) => { item2Called = true; };
var item3Called = false;
Action<NancyContext> item3 = (r) => { item3Called = true; };
var item4Called = false;
Action<NancyContext> item4 = (r) => { item4Called = true; };
pipeline += item1;
pipeline += item2;
var subPipeline = new AfterPipeline();
subPipeline += item3;
subPipeline += item4;
pipeline.AddItemToEndOfPipeline(subPipeline);
pipeline.Invoke(CreateContext());
Assert.True(item1Called);
Assert.True(item2Called);
Assert.True(item3Called);
Assert.True(item4Called);
}
开发者ID:nuxleus,项目名称:Nancy,代码行数:24,代码来源:PostRequestHooksPipelineFixture.cs
示例14: Should_allow_module_after_hook_to_change_response
public async Task Should_allow_module_after_hook_to_change_response()
{
// Given
var before = new BeforePipeline();
before += ctx => null;
var response = new Response();
Func<NancyContext, Response> moduleAfterHookResponse = ctx => response;
var after = new AfterPipeline();
after += ctx =>
{
ctx.Response = moduleAfterHookResponse(ctx);
};
var route = new FakeRoute();
var resolvedRoute = new ResolveResult(
route,
DynamicDictionary.Empty,
before,
after,
null);
A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
var context =
new NancyContext { Request = new Request("GET", "/", "http") };
// When
await this.requestDispatcher.Dispatch(context, new CancellationToken());
// Then
context.Response.ShouldBeSameAs(response);
}
开发者ID:sloncho,项目名称:Nancy,代码行数:36,代码来源:DefaultRequestDispatcherFixture.cs
示例15: BeforePipeline
public async Task Should_not_invoke_resolved_route_if_module_before_hook_returns_response_but_should_invoke_module_after_hook()
{
// Given
var capturedExecutionOrder = new List<string>();
var expectedExecutionOrder = new[] { "Prehook", "Posthook" };
var route = new FakeRoute
{
Action = (parameters, token) =>
{
capturedExecutionOrder.Add("RouteInvoke");
return null;
}
};
var before = new BeforePipeline();
before += ctx =>
{
capturedExecutionOrder.Add("Prehook");
return new Response();
};
var after = new AfterPipeline();
after += ctx => capturedExecutionOrder.Add("Posthook");
var resolvedRoute = new ResolveResult(
route,
DynamicDictionary.Empty,
before,
after,
null);
A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
var context =
new NancyContext { Request = new Request("GET", "/", "http") };
// When
await this.requestDispatcher.Dispatch(context, new CancellationToken());
// Then
capturedExecutionOrder.Count().ShouldEqual(2);
capturedExecutionOrder.SequenceEqual(expectedExecutionOrder).ShouldBeTrue();
}
开发者ID:sloncho,项目名称:Nancy,代码行数:44,代码来源:DefaultRequestDispatcherFixture.cs
示例16: Should_set_formatter_when_using_formatter_selector
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);
}
开发者ID:jbattermann,项目名称:Nancy,代码行数:17,代码来源:CookieBasedSessionsFixture.cs
示例17: After
/// <summary>
/// Adds an after-request process pipeline to the module.
/// </summary>
/// <param name="after">An <see cref="AfterPipeline"/> instance.</param>
/// <returns>An instance to the current <see cref="ConfigurableNancyModuleConfigurator"/>.</returns>
public ConfigurableNancyModuleConfigurator After(AfterPipeline after)
{
this.module.After = after;
return this;
}
开发者ID:ryanki1,项目名称:Nancy,代码行数:11,代码来源:ConfigurableNancyModule.cs
示例18: Should_rethrow_exception_when_onerror_hook_does_return_response
public void Should_rethrow_exception_when_onerror_hook_does_return_response()
{
// Given
var route = new FakeRoute
{
Action = (parameters, ct) => { throw 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) => { return null; });
A.CallTo(() => this.routeResolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
var context =
new NancyContext { Request = new Request("GET", "/", "http") };
//When
// Then
Assert.Throws<Exception>(() => this.requestDispatcher.Dispatch(context, new CancellationToken()));
}
开发者ID:Borzoo,项目名称:Nancy,代码行数:31,代码来源:DefaultRequestDispatcherFixture.cs
示例19: AfterPipelineFixture
public AfterPipelineFixture()
{
pipeline = new AfterPipeline();
}
开发者ID:JulianRooze,项目名称:Nancy,代码行数:4,代码来源:AfterPipelineFixture.cs
示例20: Should_not_rethrow_exception_when_onerror_hook_returns_response
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();
}
开发者ID:sloncho,项目名称:Nancy,代码行数:32,代码来源:DefaultRequestDispatcherFixture.cs
注:本文中的AfterPipeline类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论