예제 #1
0
파일: Api.cs 프로젝트: sjblacknz/Bard
 internal Api(BardHttpClient httpClient)
 {
     _httpClient         = httpClient;
     _badRequestProvider = httpClient.RequestProvider;
     _eventAggregator    = httpClient.EventAggregator;
     _logWriter          = httpClient.Writer;
 }
예제 #2
0
파일: Scenario.cs 프로젝트: sjclark76/Bard
        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);
        }
예제 #3
0
 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;
 }
예제 #4
0
파일: Response.cs 프로젝트: mir-dhaka/Bard
 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);
 }
예제 #5
0
        internal BardHttpClient(EventAggregator eventAggregator, BardResponsePublisher messageHandler,
                                IBadRequestProvider badRequestProvider, LogWriter logWriter) : base(
                messageHandler)
        {
            messageHandler.PublishApiResult = NotifyObservers;

            EventAggregator = eventAggregator;
            RequestProvider = badRequestProvider;
            Writer          = logWriter;
        }
예제 #6
0
 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);
 }
예제 #7
0
 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);
 }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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;
 }