Ejemplo n.º 1
0
        public async Task TakeAppointment(Appointment takeSlot)
        {
            try
            {
                await _httpClientProvider
                .CreateClient(URL_CLIENT)
                .WithBasicAuthenticator(USER, PSW)
                .PostAsync(TAKE_APPOINTMENT, takeSlot);
            }
            catch (Exception err)
            {
                await _loggerProvider.Log(err);

                throw (new TakeAppointmentException(Resources.FriendlyMessageException.TakeAppointmentExceptionMessage, err));
            }
        }
        private HttpClient SetupHttpClient(SplunkLoggerOptions options)
        {
            var httpClient = httpClientFactory.CreateClient();

            httpClient.BaseAddress = GetSplunkCollectorUrl(options, endPointCustomization);

            if (options.Timeout > 0)
            {
                httpClient.Timeout = TimeSpan.FromMilliseconds(options.Timeout);
            }

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(SplunkHeaderValue, options.AuthenticationToken);
            if (options.ChannelIdType == SplunkLoggerOptions.ChannelIdOption.RequestHeader)
            {
                httpClient.DefaultRequestHeaders.Add("x-splunk-request-channel", Guid.NewGuid().ToString());
            }

            if (options.CustomHeaders != null && options.CustomHeaders.Count > 0)
            {
                options.CustomHeaders.ToList().ForEach(keyValuePair =>
                                                       httpClient.DefaultRequestHeaders.Add(keyValuePair.Key, keyValuePair.Value));
            }

            return(httpClient);
        }
        public void GetHttpClient()
        {
            // given
            var mockClient = Substitute.For <IHttpClient>();

            mockHttpClientProvider.CreateClient(Arg.Any <IHttpClientConfiguration>()).Returns(mockClient);

            var target = CreateSendingContext().Build();

            Assert.That(mockHttpClientConfig.ReceivedCalls(), Is.Empty);
            Assert.That(mockHttpClientProvider.ReceivedCalls(), Is.Empty);

            // when
            var obtained = target.GetHttpClient();

            // then
            Assert.That(obtained, Is.Not.Null);
            Assert.That(obtained, Is.SameAs(mockClient));

            mockHttpClientProvider.Received(1).CreateClient(mockHttpClientConfig);
            Assert.That(mockClient.ReceivedCalls(), Is.Empty);
            Assert.That(mockHttpClientConfig.ReceivedCalls(), Is.Empty);
        }
        public void Setup()
        {
            mockLogger = Substitute.For <ILogger>();
            mockLogger.IsInfoEnabled.Returns(true);
            mockLogger.IsDebugEnabled.Returns(true);

            mockHttpClientConfig = Substitute.For <IHttpClientConfiguration>();

            var statusResponse = Substitute.For <IStatusResponse>();

            statusResponse.ResponseCode.Returns(StatusResponse.HttpOk);
            statusResponse.IsErroneousResponse.Returns(false);

            var httpClient = Substitute.For <IHttpClient>();

            httpClient.SendBeaconRequest(Arg.Any <string>(), Arg.Any <byte[]>(), Arg.Any <IAdditionalQueryParameters>())
            .Returns(statusResponse);

            mockHttpClientProvider = Substitute.For <IHttpClientProvider>();
            mockHttpClientProvider.CreateClient(Arg.Any <IHttpClientConfiguration>()).Returns(httpClient);

            mockTimingProvider  = Substitute.For <ITimingProvider>();
            mockThreadSuspender = Substitute.For <IInterruptibleThreadSuspender>();
        }