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); }
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); }