internal Api(BardHttpClient httpClient) { _httpClient = httpClient; _badRequestProvider = httpClient.RequestProvider; _eventAggregator = httpClient.EventAggregator; _logWriter = httpClient.Writer; }
protected Scenario(HttpClient?client, Action <string> logMessage, IBadRequestProvider badRequestProvider, IServiceProvider?services, int?maxElapsedTime, EventAggregator eventAggregator, JsonSerializerOptions?jsonDeserializeOptions, JsonSerializerOptions?jsonSerializeOptions) { _client = client ?? throw new BardConfigurationException("client not set."); if (badRequestProvider is BadRequestProviderBase badRequestProviderBase) { badRequestProviderBase.SetSerializer(new BardJsonSerializer(jsonDeserializeOptions, jsonSerializeOptions)); } _badRequestProvider = badRequestProvider; _eventAggregator = eventAggregator; LogWriter = new LogWriter(logMessage, _eventAggregator, new BardJsonSerializer(jsonDeserializeOptions, jsonSerializeOptions)); var pipeline = new PipelineBuilder(LogWriter); Context = new ScenarioContext(pipeline, FullLoggingApi(), LogWriter, services); var when = new When.When(RequestLoggingApi(), _eventAggregator, LogWriter); InternalWhen = when; _then = new Then.Then(maxElapsedTime, LogWriter); _eventAggregator.Subscribe(_then); _eventAggregator.Subscribe(pipeline); }
internal ShouldBe(ApiResult apiResult, IBadRequestProvider badRequestProvider, LogWriter logWriter) { _apiResult = apiResult; _logWriter = logWriter; badRequestProvider.StringContent = apiResult.ResponseString; BadRequest = new BadRequestProviderDecorator(this, badRequestProvider); _httpResponse = apiResult.ResponseMessage; _httpResponseString = apiResult.ResponseString; }
internal Response(EventAggregator eventAggregator, ApiResult apiResult, IBadRequestProvider badRequestProvider, LogWriter logWriter) { _apiResult = apiResult; _logWriter = logWriter; _shouldBe = new ShouldBe(apiResult, badRequestProvider, logWriter); _headers = new Headers(apiResult, logWriter); eventAggregator.Subscribe(_shouldBe); }
internal BardHttpClient(EventAggregator eventAggregator, BardResponsePublisher messageHandler, IBadRequestProvider badRequestProvider, LogWriter logWriter) : base( messageHandler) { messageHandler.PublishApiResult = NotifyObservers; EventAggregator = eventAggregator; RequestProvider = badRequestProvider; Writer = logWriter; }
internal ShouldBe(ApiResult apiResult, IBadRequestProvider badRequestProvider, LogWriter logWriter, BardJsonSerializer jsonSerializer) { _apiResult = apiResult; _logWriter = logWriter; _jsonSerializer = jsonSerializer; badRequestProvider.StringContent = apiResult.ResponseString; BadRequest = new BadRequestProviderDecorator(this, badRequestProvider); _httpResponse = apiResult.ResponseMessage; _httpResponseString = apiResult.ResponseString; _performanceMonitor = new PerformanceMonitor(_logWriter); }
internal Response(EventAggregator eventAggregator, ApiResult?apiResult, IBadRequestProvider badRequestProvider, LogWriter logWriter) { _apiResult = apiResult ?? throw new BardException("apiResult cannot be null"); _logWriter = logWriter; _shouldBe = new ShouldBe(apiResult, badRequestProvider, logWriter, logWriter.Serializer); _headers = new Headers(apiResult, logWriter); eventAggregator.Subscribe(_shouldBe); eventAggregator.SubscribeToApiRequests(_shouldBe); eventAggregator.SubscribeToApiRequests(_headers); eventAggregator.SubscribeToApiRequests(this); }
private static BardHttpClient CloneHttpClient(HttpClient client, LogWriter logWriter, IBadRequestProvider badRequestProvider, EventAggregator eventAggregator, BardResponsePublisher bardResponsePublisher) { var bardHttpClient = new BardHttpClient(eventAggregator, bardResponsePublisher, badRequestProvider, logWriter) { BaseAddress = client.BaseAddress, Timeout = client.Timeout, MaxResponseContentBufferSize = client.MaxResponseContentBufferSize }; foreach (var(key, value) in client.DefaultRequestHeaders) { bardHttpClient.DefaultRequestHeaders.TryAddWithoutValidation(key, value); } return(bardHttpClient); }
internal static BardHttpClient CreateRequestLoggingClient(HttpClient client, LogWriter logWriter, IBadRequestProvider badRequestProvider, EventAggregator eventAggregator) { var httpMessageHandler = GetInstanceField(client); if (httpMessageHandler == null) { throw new BardException("Cannot find client handler"); } var grpcMessageHandler = new GrpcMessageHandler(httpMessageHandler); var requestLoggerMessageHandler = new RequestLoggerMessageHandler(logWriter, grpcMessageHandler); var bardResponsePublisher = new BardResponsePublisher(requestLoggerMessageHandler); var bardHttpClient = CloneHttpClient(client, logWriter, badRequestProvider, eventAggregator, bardResponsePublisher); return(bardHttpClient); }
protected Scenario(HttpClient?client, Action <string> logMessage, IBadRequestProvider badRequestProvider, IServiceProvider?services, int?maxElapsedTime) { _client = client ?? throw new BardConfigurationException("client not set."); _badRequestProvider = badRequestProvider; _eventAggregator = new EventAggregator(); LogWriter = new LogWriter(logMessage, _eventAggregator); var pipeline = new PipelineBuilder(LogWriter); Context = new ScenarioContext(pipeline, FullLoggingApi(), LogWriter, services); var when = new When.When(RequestLoggingApi(), LogWriter); InternalWhen = when; _then = new Then.Then(maxElapsedTime); _eventAggregator.Subscribe(_then); _eventAggregator.Subscribe(pipeline); }
public BadRequestProviderDecorator(IShouldBe shouldBe, IBadRequestProvider decorate) { _shouldBe = shouldBe; _toDecorate = decorate; }