Пример #1
0
        internal Scenario(GrpcScenarioOptions options)
        {
            if (options.GrpcClients.Any() == false && options.Client == null)
            {
                throw new BardConfigurationException("Client not set");
            }

            _eventAggregator = new EventAggregator();

            _logWriter = new LogWriter(options.LogMessage, _eventAggregator);

            var originalClient = options.Client ?? throw new BardConfigurationException("client not set.");

            var bardClient = HttpClientBuilder
                             .CreateFullLoggingClient(originalClient, _logWriter, options.BadRequestProvider, _eventAggregator);

            _clientFactory = new GrpcClientFactory(options.GrpcClients, bardClient, _logWriter);

            _api = new Api(bardClient);

            var pipeline = new PipelineBuilder(_logWriter);

            Context = new GrpcScenarioContext(pipeline, _api, _logWriter,
                                              options.Services, _clientFactory);

            _when = new When(_api, _eventAggregator, _logWriter);

            _then = new Then(null, _logWriter);

            _eventAggregator.Subscribe(_then);
            _eventAggregator.Subscribe(pipeline);
        }
Пример #2
0
            /// <summary>
            /// Configure the gRPC Scenario
            /// </summary>
            /// <param name="configure"></param>
            /// <returns></returns>
            public IScenario Configure(Action <GrpcScenarioOptions> configure)
            {
                var options = new GrpcScenarioOptions();

                configure(options);

                return(new Scenario(options));
            }
Пример #3
0
            /// <summary>
            /// Configure the gRPC Scenario
            /// </summary>
            /// <param name="configure"></param>
            /// <returns></returns>
            public IScenario <TGrpcClient> Configure(Action <GrpcScenarioOptions <TGrpcClient> > configure)
            {
                var options = new GrpcScenarioOptions <TGrpcClient>();

                configure(options);

                return(new Scenario <TGrpcClient>(options));
            }
Пример #4
0
            /// <summary>
            ///     Supply the required configuration values for the scenario
            /// </summary>
            /// <param name="configure">The action that configures the scenario</param>
            /// <returns>The created scenario</returns>
            public IScenario <TStoryBook, TStoryData> Configure(
                Action <GrpcScenarioOptions <TStoryBook> > configure)
            {
                var options = new GrpcScenarioOptions <TStoryBook>();

                configure(options);

                return(new Scenario <TStoryBook, TStoryData>(options));
            }
Пример #5
0
        internal Scenario(GrpcScenarioOptions <TGrpcClient> options)
        {
            if (options.Client == null)
            {
                throw new BardConfigurationException("Client not set");
            }

            var eventAggregator = new EventAggregator();

            var logWriter = new LogWriter(options.LogMessage, eventAggregator);

            var originalClient = options.Client;

            var bardClient = HttpClientBuilder
                             .CreateFullLoggingClient(originalClient, logWriter, options.BadRequestProvider, eventAggregator);

            GrpcChannelOptions channelOptions = new GrpcChannelOptions
            {
                HttpClient = bardClient
            };

            var channel = GrpcChannel.ForAddress(bardClient.BaseAddress, channelOptions);

            TGrpcClient GRpcFactory()
            {
                if (options.GrpcClient == null)
                {
                    throw new BardConfigurationException($"{nameof(options.GrpcClient)} has not been configured.");
                }

                return(options.GrpcClient.Invoke(channel.Intercept(new BardClientInterceptor(logWriter))));
            }

            var api      = new Api(bardClient);
            var pipeline = new PipelineBuilder(logWriter);

            Context = new GrpcScenarioContext <TGrpcClient>(pipeline, api, logWriter,
                                                            options.Services, GRpcFactory);

            var when = new When <TGrpcClient>(GRpcFactory, eventAggregator, api, logWriter,
                                              () => Context.ExecutePipeline());

            When = when;

            _then = new Then(null);

            eventAggregator.Subscribe(_then);
            eventAggregator.Subscribe(pipeline);
        }