public void Empty_pipeline_returns_completed_task() { var pipeline = _sut.Build(); var actual = pipeline.Invoke(_fakeMessageContext); Assert.True(actual.IsCompleted); }
/// <summary> /// Build the pipeline /// </summary> /// <returns>Constructed pipeline</returns> public IDomainEventDispatcher Build() { if (_inner == null) { throw new InvalidOperationException( "You must specify a dispatcher, either through the UseContainer() method or by the UseCustomDispatcher() method."); } var builder = new PipelineBuilder(); if (_unitOfWorkAdapter != null) { builder.RegisterDownstream(new TransactionalHandler(_unitOfWorkAdapter, _storage)); } if (_maxWorkers > 0) { builder.RegisterDownstream(new AsyncHandler(_maxWorkers)); } builder.RegisterDownstream(_inner); builder.RegisterUpstream(_errorHandler); var pipeline = builder.Build(); pipeline.Start(); return(new EventPipelineDispatcher(pipeline)); }
public async Task <PipelineResult <Wrapper <bool> > > Execute(IWorkItem?workItem, BaseOperation from, Func <VariableCollection, ResolveContext, Task> resolveCallback, OperationWatcher watcher, ILogger logger) { Assert.IsNotNull(from); Assert.IsNotNull(resolveCallback); ResolveContext context = new ResolveContext(); WorkspaceSettings?settings = await Settings.ConfigureAwait(false); if (settings != null) { _ = context.SetShell(settings.DefaultShell); } _ = context.SetWorkingDirectory(PathRoot.FullName); if (workItem != null && workItem is WorkItem item) { _ = context.SetInputPath(item.RelativePath); } await resolveCallback(from.GetVariables(), context).ConfigureAwait(false); PipelineBuilder <OperationWatcher, Wrapper <bool> > builder = await from.Resolve(context).ConfigureAwait(false); Pipeline <OperationWatcher, Wrapper <bool> > pipeline = await builder.Build(watcher, logger).ConfigureAwait(false); return(await pipeline.Consume().ConfigureAwait(false)); }
public void When_Building_A_Pipeline_With_Global_Inbox() { // Settings for UseInbox on MyCommandInboxedHandler // [UseInbox(step:0, contextKey: typeof(MyCommandInboxedHandler), onceOnly: false)] // Settings for InboxConfifguration as above // _inboxConfiguration = new InboxConfiguration(InboxScope.All, context: true, onceOnly: true); // so global will not allow repeated requests ans calls, but local should override this and allow //act _chainOfResponsibility = _chainBuilder.Build(_requestContext); var chain = _chainOfResponsibility.First(); var myCommand = new MyCommand(); //First pass not impacted by UseInbox Handler chain.Handle(myCommand); bool noException = true; try { chain.Handle(myCommand); } catch (OnceOnlyException) { noException = false; } //assert noException.Should().BeTrue(); }
public void When_Building_A_Handler_For_A_Command() { _chainOfResponsibility = _chainBuilder.Build(_requestContext).First(); Assert.NotNull(_chainOfResponsibility.Context); Assert.AreSame(_requestContext, _chainOfResponsibility.Context); }
public void Build() { var pipeline = new PipelineBuilder <DummySource, DummyContext>(); var factoryLogs = new List <int?>(); var filterLogs = new List <int?>(); { Func <SequenceFilterFunc <DummySource, DummyContext>, SequenceFilterFunc <DummySource, DummyContext> > FilterFactory(int id) { return(next => { factoryLogs.Add(id); return (source, context) => { filterLogs.Add(id); return next(source, context); }; }); } pipeline.Add(FilterFactory(0)); pipeline.Add(FilterFactory(1)); pipeline.Add(FilterFactory(2)); } new TestCaseRunner() .Run(() => pipeline.Build()) .Verify((actual, _) => { var source = new DummySource[] { new DummySource(), new DummySource() }; var context = new DummyContext(); var actualSource = actual(source, context).GetAwaiter().GetResult(); CollectionAssert.AreEqual(new int[] { 2, 1, 0 }, factoryLogs, "フィルターファクトリーの呼び出し順序が一致しません。"); CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, filterLogs, "フィルターの適用順序が一致しません。"); Assert.AreEqual(source, actualSource, "入力シーケンスが出力に素通しされていません。"); }, (Type)null); }
public void When_A_Handler_Is_Part_of_A_Pipeline() { _pipeline = _pipelineBuilder.Build(new RequestContext()).First(); TracePipeline().ToString().Should().Contain("MyImplicitHandler"); TracePipeline().ToString().Should().Contain("MyLoggingHandler"); }
static async Task Main(string[] args) { PipelineBuilder pipelineBuilder = new PipelineBuilder(); pipelineBuilder.Use <StartInit>(); pipelineBuilder.Use(async(ctx, next) => { await next(ctx); }); PipelineBuilder item_pipelineBuilder = new PipelineBuilder(); item_pipelineBuilder.Use <FlowCommonMarkToHtml>(); item_pipelineBuilder.Use <FlowTemplateProcessor>(); pipelineBuilder.Use <StartProcess>(item_pipelineBuilder.Build()); Pipeline pipeline = pipelineBuilder.Build(); var context = new MiddlewareContext("E:/openjw/open") { HandlerExecutor = async() => { var response = await Task.FromResult(1); } }; await pipeline.Process(context); Console.WriteLine("Hello World!"); Console.ReadLine(); }
public void Test() { var down1 = new ForwardingDownHandler(); var down2 = new ForwardingDownHandler(); var up1 = new ForwardingUpHandler(); var up2 = new ForwardingUpHandler(); var handler = Substitute.For <IUpstreamHandler>(); var bp = new PipelineBuilder(); bp.RegisterDownstream(down1); bp.RegisterDownstream(down2); bp.RegisterUpstream(up1); bp.RegisterUpstream(up2); bp.RegisterUpstream(handler); var pipeline = bp.Build(); pipeline.Start(); pipeline.Send(new DispatchEvent(new FakeEvent())); foreach (var call in handler.ReceivedCalls()) { Console.WriteLine(call.GetArguments()[1]); } }
public void When_Building_A_Handler_For_A_Command() { _chainOfResponsibility = _chainBuilder.Build(_requestContext).First(); _chainOfResponsibility.Context.Should().NotBeNull(); _chainOfResponsibility.Context.Should().BeSameAs(_requestContext); }
public void When_Building_A_Sync_Pipeline_That_Has_Async_Handlers() { _exception = Catch.Exception(() => _pipeline = _pipelineBuilder.Build(new RequestContext()).First()); _exception.Should().NotBeNull(); _exception.Should().BeOfType <ConfigurationException>(); _exception.Message.Should().Contain(typeof(MyLoggingHandlerAsync <>).Name); }
public void When_Building_A_Pipeline_Failures_Should_Be_ConfigurationErrors() { var exception = Catch.Exception(() => _chainBuilder.Build(_requestContext)); exception.Should().NotBeNull(); exception.Should().BeOfType <ConfigurationException>(); exception.InnerException.Should().BeOfType <InvalidOperationException>(); }
private static IServiceCollection BuildPipeline <T>(this IServiceCollection services, Action <IPipelineBuilder <T> > builderAction, string name = null) { var builder = new PipelineBuilder <T>(services, name ?? Constants.DefaultPipeline); builderAction(builder); builder.Build(); return(services); }
public void When_Building_A_Sync_Pipeline_That_Has_Async_Handlers() { _exception = Catch.Exception(() => _pipeline = _pipelineBuilder.Build(new RequestContext()).First()); Assert.NotNull(_exception); Assert.IsInstanceOf(typeof(ConfigurationException), _exception); StringAssert.Contains(typeof(MyLoggingHandlerAsync <>).Name, _exception.Message); }
public static async Task <int> Main(string[] args) { Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; ILogger logger = new Logger(); ExtensionCollection extensions = new ExtensionCollection(); { extensions.Load(new ExtensionLoader(typeof(Extensions.Builtin.Console.ConsoleExtension).Assembly)); extensions.Load(new ExtensionLoader(typeof(Extensions.Builtin.Workspace.WorkspaceExtension).Assembly)); } PipelineBuilder <string[], Wrapper <int> > builder = new PipelineBuilder <string[], Wrapper <int> >(); _ = builder.ConfigureLogger(logger) .ConfigureExtensions(extensions) .ConfigureHost(new ExtensionHost()) .ConfigureCliCommand(); if (Environment == EnvironmentType.Test) { if (TestView.Input == null) { throw new NullReferenceException(nameof(TestView.Input)); } _ = builder.ConfigureConsole(new TestTerminal(), TestView.Input); } else { _ = builder.ConfigureConsole(new SystemConsole(), Console.In); } _ = builder.UseCommandsService().UseReplCommandService(); _ = builder.UseCliCommand(); if (Environment == EnvironmentType.Test) { _ = builder.UseTestView(); } _ = builder.UseReplCommand(); Pipeline <string[], Wrapper <int> > pipeline = await builder.Build(args, logger); PipelineResult <Wrapper <int> > result = await pipeline.Consume(); if (result.IsOk) { return(result.Result !); } else { Console.Error.WriteLine(result.Exception !.ToString()); return(-1); } }
public void When_Finding_A_Handler_For_A_Command() { _pipeline = _pipelineBuilder.Build(new RequestContext()).First(); //_should_return_the_my_command_handler_as_the_implicit_handler Assert.IsAssignableFrom(typeof(MyCommandHandler), _pipeline); //_should_be_the_only_element_in_the_chain Assert.AreEqual("MyCommandHandler|", TracePipeline().ToString()); }
public void When_Finding_A_Handler_That_Has_Dependencies() { _pipeline = _pipelineBuilder.Build(new RequestContext()).First(); // _should_return_the_command_handler_as_the_implicit_handler _pipeline.Should().BeOfType <MyDependentCommandHandler>(); // _should_be_the_only_element_in_the_chain TracePipeline().ToString().Should().Be("MyDependentCommandHandler|"); }
/// <summary> /// Creates pipeline from current components. /// </summary> /// <param name="sp">Application service provider.</param> private static IPipeline <SomeContext> BuildPipeline(IServiceProvider sp) { var pipeline = new PipelineBuilder <SomeContext>(); pipeline.Use <Subdomain1Middleware>(); // chain other subdomain 1 middlewares return(pipeline.Build(sp)); }
public void When_Building_A_Pipeline_With_Global_Inbox() { //act _chainOfResponsibility = _chainBuilder.Build(_requestContext); //assert var tracer = TracePipeline(_chainOfResponsibility.First()); tracer.ToString().Should().NotContain("UseInboxHandler"); }
public void PipelineBuilder_Builds_No_Processors() { PipelineBuilder pb = new PipelineBuilder(); Pipeline pipeline = pb.Build( Enumerable.Empty <Processor>(), Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>()); Assert.IsNotNull(pipeline); }
public IPipeline<ClientActionContext> CreatePipeline(Func<ActionDelegate<ClientActionContext>, ClientActionContext, Task> next = null) { PipelineBuilder<ClientActionContext> builder = new PipelineBuilder<ClientActionContext>(); builder.Use(new SessionMiddleware(SessionHandler.Object, SessionErrorHandling.Object)); if (next != null) { builder.Use(next); } return builder.Build(); }
public IPipeline <ServerActionContext> Build() { PipelineBuilder <ServerActionContext> builder = new PipelineBuilder <ServerActionContext>(); builder.Use(new HandleErrorMiddleware()); builder.Use(new SerializationMiddleware()); builder.Use(new InstanceProviderMiddleware()); builder.Use(new ActionInvokerMiddleware()); return(builder.Build()); }
public IPipeline<ServerActionContext> Build() { PipelineBuilder<ServerActionContext> builder = new PipelineBuilder<ServerActionContext>(); builder.Use(new HandleErrorMiddleware()); builder.Use(new SerializationMiddleware()); builder.Use(new InstanceProviderMiddleware()); builder.Use(new ActionInvokerMiddleware()); return builder.Build(); }
public async Task Basic() { PipelineBuilder <int, Wrapper <int> > builder = TPipelineBuilder.GetBasicBuilder(2).Use("", TPipelineBuilder.initial).Use("", TPipelineBuilder.plus).Use("", TPipelineBuilder.plus).Use("", TPipelineBuilder.multiply); { Pipeline <int, Wrapper <int> > pipeline = await builder.Build(0, new CodeRunner.Loggings.Logger()); PipelineResult <Wrapper <int> > res = await pipeline.Consume(); Assert.IsTrue(res.IsOk); Assert.AreEqual <int>(8, res.Result !); } }
/// <summary> /// Build the dispatcher. /// </summary> /// <returns>Created dispatcher</returns> public ICommandDispatcher Build() { if (_lastHandler == null && _container == null) { throw new InvalidOperationException( "You must have specified a handler which can actually invoke the correct command handler. For instance the 'IocDispatcher'."); } if (_container == null && _lastHandler == null) { throw new InvalidOperationException( "You must have specified a SINGLE handler that can invoke the correct command handler. Either use 'IocDispatcher' or another one, not both alternatives."); } var builder = new PipelineBuilder(); // must be registered before the storage since the storage listens on CommandAborted if (_maxAttempts > 0) { var handler = new RetryingHandler(_maxAttempts); builder.RegisterUpstream(handler); } // Must be registered before the async handler. if (_storageHandler != null) { builder.RegisterDownstream(_storageHandler); builder.RegisterUpstream(_storageHandler); } if (_workers > 0) { builder.RegisterDownstream(new AsyncHandler(_workers)); } if (_container != null) { builder.RegisterDownstream(new Pipeline.IocDispatcher(_container)); } else { builder.RegisterDownstream(_lastHandler); } builder.RegisterUpstream(_errorHandler); var pipeline = builder.Build(); pipeline.Start(); var dispatcher = new PipelineDispatcher(pipeline); return(dispatcher); }
public void PipelineBuilder_Throws_Null_OutArguments() { PipelineBuilder pb = new PipelineBuilder(); ExceptionAssert.ThrowsArgumentNull( "Build should throw if null out arguments", "outArguments", () => pb.Build( Enumerable.Empty <Processor>(), Enumerable.Empty <ProcessorArgument>(), null) ); }
public void PipelineBuilder_Throws_Null_Processors() { PipelineBuilder pb = new PipelineBuilder(); ExceptionAssert.ThrowsArgumentNull( "Build should throw if null processors", "processors", () => pb.Build( null, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>()) ); }
public async Task Pipeline_Should_Preserve_OwnPipelineComponents_AfterBuild() { // arrange var sp = new ServiceCollection().BuildServiceProvider(); var pipelineBuilder = new PipelineBuilder <TestCtx>(); pipelineBuilder.Use <Middleware1>(); var firstPipeline = pipelineBuilder.Build(sp); pipelineBuilder.Use(async(ctx, next) => { ctx.Msg += "Before_LambdaMiddleware"; await next(); ctx.Msg += "After_LambdaMiddleware"; }); var secondPipeline = pipelineBuilder.Build(sp); var testContext = new TestCtx(); // act await firstPipeline.ExecuteAsync(testContext); // this pipeline has no lambda middleware in pipeline. Assert.AreEqual("Before_Middleware1After_Middleware1", testContext.Msg); testContext.Msg = null; // clear before second pipeline execution await secondPipeline.ExecuteAsync(testContext); // this has full pipeline. // assert Assert.AreEqual( "Before_Middleware1Before_LambdaMiddlewareAfter_LambdaMiddlewareAfter_Middleware1", testContext.Msg ); }
public IBotConfigurationBuilder ConfigurePipeline(Action <IPipelineBuilder> configure) { services.AddSingleton(x => { var builder = new PipelineBuilder(x.GetRequiredService <IBotCore>()); configure(builder); return(builder.Build()); }); return(this); }
public void Setup() { var logger = new Mock <ILog>().Object; var registry = new SubscriberRegistry(); registry.Register <TestCommand, TestCommandHandler>(); var handlerFactory = new TestHandlerFactory <TestCommand, TestCommandHandler>(() => new TestCommandHandler(logger)); pipelineBuilder = new PipelineBuilder <TestCommand>(registry, handlerFactory, logger); pipeline = pipelineBuilder.Build(new RequestContext()).First(); }
public IPipeline<ServerActionContext> Build(IEnumerable<IMiddleware<ServerActionContext>> middlewares) { if (middlewares == null) throw new ArgumentNullException(nameof(middlewares)); PipelineBuilder<ServerActionContext> builder = new PipelineBuilder<ServerActionContext>(); foreach (var middleware in middlewares) { builder.Use(middleware); } return builder.Build(); }
public void Build_ShouldCreatePipelineWithCurrentSteps() { // Arrange PipelineBuilder <string, string> builder = PipelineBuilder.Create <string>() .AddStep(arg => arg + "sync") .AddStep(async arg => await Task.FromResult(arg + "async")); // Act Pipeline <string, string> pipeline = builder.Build(); // Assert Assert.IsType <DelegatePipelineStep <string, string> >(pipeline.Steps[0]); Assert.IsType <AsyncDelegatePipelineStep <string, string> >(pipeline.Steps[1]); }
public async Task Exception() { PipelineBuilder <int, Wrapper <int> > builder = TPipelineBuilder.GetBasicBuilder(2).Use("", TPipelineBuilder.initial).Use("", TPipelineBuilder.plus).Use("", TPipelineBuilder.plus).Use("", TPipelineBuilder.expNotImp).Use("", TPipelineBuilder.multiply); { Pipeline <int, Wrapper <int> > pipeline = await builder.Build(0, new CodeRunner.Loggings.Logger()); PipelineResult <Wrapper <int> > res = await pipeline.Consume(); Assert.AreEqual <int>(4, res.Result !); Assert.IsTrue(res.IsError); Assert.IsInstanceOfType(res.Exception !.InnerException, typeof(NotImplementedException)); Assert.AreEqual(CodeRunner.Loggings.LogLevel.Error, res.Logs.Last().Level); } }
public IPipeline<ClientActionContext> CreatePipeline(int retries) { PipelineBuilder<ClientActionContext> builder = new PipelineBuilder<ClientActionContext>(); builder.Use(new RetryRequestMiddleware(ErrorHandling.Object) {Retries = retries}); builder.Use( (next, ctxt) => { Callback.Object.Handle(ctxt); return next(ctxt); }); return builder.Build(); }