コード例 #1
0
        public void Setup()
        {
            _useCaseInteractor = Substitute.For <IInteractor <MockUseCase, IMockOutputPort> >();

            _middleware1 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware1.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            _middleware2 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware2.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            var container = new Container(c =>
            {
                c.For <IInteractor <MockUseCase, IMockOutputPort> >().Use(_useCaseInteractor);
                c.For <IMiddleware <MockUseCase, IMockOutputPort> >().Use(_middleware1);
                c.For <IMiddleware <MockUseCase, IMockOutputPort> >().Use(_middleware2);
            });

            _interactorHub = new Hub(new StructureMapResolver(container));
        }
コード例 #2
0
        public void Setup()
        {
            var builder = new ContainerBuilder();

            _useCaseInteractor = Substitute.For <IInteractor <MockUseCase, IMockOutputPort> >();

            _middleware1 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware1.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            _middleware2 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware2.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            _globalMiddleware = Substitute.For <IMiddleware>();
            _globalMiddleware.Execute(
                Arg.Any <MockUseCase>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));


            builder.RegisterInstance(_useCaseInteractor).As <IInteractor <MockUseCase, IMockOutputPort> >();

            builder.RegisterInstance(_middleware1)
            .As <IMiddleware <MockUseCase, IMockOutputPort> >();
            builder.RegisterInstance(_middleware2)
            .As <IMiddleware <MockUseCase, IMockOutputPort> >();
            builder.RegisterInstance(_globalMiddleware)
            .As <IMiddleware>();

            builder.RegisterModule(new ResolverModule());

            _container = builder.Build();

            _interactorHub = _container.Resolve <IInteractorHub>();
        }
コード例 #3
0
        public void Setup()
        {
            var kernelConfig = new KernelConfiguration(new ResolverModule());

            _useCaseInteractor = Substitute.For <IInteractor <MockUseCase, IMockOutputPort> >();

            _globalMiddleware = Substitute.For <IMiddleware>();
            _globalMiddleware.Execute(
                Arg.Any <MockUseCase>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            _middleware1 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware1.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            _middleware2 = Substitute.For <IMiddleware <MockUseCase, IMockOutputPort> >();
            _middleware2.Execute(
                Arg.Any <MockUseCase>(),
                Arg.Any <IMockOutputPort>(),
                d => Task.FromResult(new UseCaseResult(true)),
                Arg.Any <CancellationToken>())
            .ReturnsForAnyArgs(x => new UseCaseResult(true))
            .AndDoes(x => x.Arg <Func <MockUseCase, Task <UseCaseResult> > >().Invoke(x.Arg <MockUseCase>()));

            kernelConfig.Bind <IMiddleware <MockUseCase, IMockOutputPort> >()
            .ToMethod(context => _middleware1);

            kernelConfig.Bind <IMiddleware <MockUseCase, IMockOutputPort> >()
            .ToMethod(context => _middleware2);

            kernelConfig.Bind <IInteractor <MockUseCase, IMockOutputPort> >()
            .ToMethod(context => _useCaseInteractor);

            kernelConfig.Bind <IMiddleware>()
            .ToMethod(context => _globalMiddleware);

            var kernel = kernelConfig.BuildReadonlyKernel();

            _interactorHub = kernel.Get <IInteractorHub>();
        }
コード例 #4
0
        private static IMiddlewareExecutionReport Execute(IMiddleware <T> middleware, T context)
        {
            var rtn = new MiddlewareExecutionReport();

            try
            {
                rtn.TargetPipelineType = middleware.TargetPipelineType;
                rtn.ExecutionOrder     = middleware.ExecutionOrder;
                rtn.IsEnabled          = middleware.IsEnabled;
                if (rtn.IsEnabled)
                {
                    middleware.Execute(context);
                }
            }
            catch (Exception ex)
            {
                rtn.ExceptionThrown = ex;
            }


            rtn.Stop();
            return(rtn);
        }
コード例 #5
0
 public Task <UseCaseResult> Execute(TUseCase usecase, TOutputPort outputPort, Func <TUseCase, Task <UseCaseResult> > next, CancellationToken cancellationToken)
 {
     return(_middleware.Execute(usecase, next, cancellationToken));
 }