public void Given_Validation_Error_With_HttpCompletionOption_And_CancellationToken_When_GetAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode, HttpCompletionOption option)
        {
            var requestUri = "http://localhost";
            var payload    = "{ \"hello\": \"world\" }";

            var exception = new SchemaValidationException();
            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(exception);

            var path = "default.json";

            var func = default(Func <Task>);

            using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode, payload))
                using (var httpClient = this._fixture.CreateHttpClient(handler))
                    using (var source = this._fixture.CreateCancellationTokenSource())
                    {
                        func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, option, validator.Object, path, source.Token).ConfigureAwait(false);

                        func.Should().Throw <SchemaValidationException>();

                        func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), option, validator.Object, path, source.Token).ConfigureAwait(false);

                        func.Should().Throw <SchemaValidationException>();
                    }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Récupère les fixtures correspondant à une compétition
        /// </summary>
        /// <param name="competitionId">identifiant de la compétition</param>
        /// <param name="matchDay">numéro de la journée</param>
        /// <returns>Liste de fixtures</returns>
        public async Task <List <Fixture> > GetFixturesAsync(string competitionId, int matchDay)
        {
            Log.Debug(TAG, "GetFixturesAsync");

            string url = string.Format(GetUrl(), competitionId, matchDay);

            var result = await HttpClientExtensions.GetAsync <FixturesRootObject>(_httpClient, url);

            return(result.Fixtures);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Récupère une compétition par son identifiant
        /// </summary>
        /// <param name="id">Identifiant de la compétition</param>
        /// <returns>Compétition correspondante à l'identifiant</returns>
        public async Task <CompetitionRootObject> GetCompetition(string id)
        {
            //Log.Debug(TAG, "GetFixturesAsync");

            string url = string.Format(GetUrl(), id);

            var result = await HttpClientExtensions.GetAsync <CompetitionRootObject>(_httpClient, url);

            return(result);
        }
        public void Given_Null_Parameters_With_CancellationToken_When_GetAsync_Invoked_Then_It_Should_Throw_Exception()
        {
            var requestUri = "http://localhost";
            var validator  = new Mock <ISchemaValidator>();
            var path       = "default.json";
            var token      = default(CancellationToken);

            var func = default(Func <Task>);

            using (var httpClient = this._fixture.CreateHttpClient())
            {
                func = async() => await HttpClientExtensions.GetAsync(null, (string)null, (ISchemaValidator)null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, (string)null, null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, validator.Object, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, validator.Object, path, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(null, (Uri)null, (ISchemaValidator)null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, (Uri)null, (ISchemaValidator)null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), (ISchemaValidator)null, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), validator.Object, null, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), validator.Object, path, token).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();
            }
        }
        public void Given_Null_Parameters_With_HttpCompletionOption_When_GetAsync_Invoked_Then_It_Should_Throw_Exception(HttpCompletionOption option)
        {
            var requestUri = "http://localhost";
            var validator  = new Mock <ISchemaValidator>();

            var func = default(Func <Task>);

            using (var httpClient = this._fixture.CreateHttpClient())
            {
                func = async() => await HttpClientExtensions.GetAsync(null, (string)null, option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, (string)null, option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, option, validator.Object, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(null, (Uri)null, option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, (Uri)null, option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), option, null, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();

                func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), option, validator.Object, null).ConfigureAwait(false);

                func.Should().Throw <ArgumentNullException>();
            }
        }
        public void Given_Error_Response_When_GetAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode)
        {
            var requestUri = "http://localhost";
            var validator  = new Mock <ISchemaValidator>();
            var path       = "default.json";

            var func = default(Func <Task>);

            using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode))
                using (var httpClient = this._fixture.CreateHttpClient(handler))
                {
                    func = async() => await HttpClientExtensions.GetAsync(httpClient, requestUri, validator.Object, path).ConfigureAwait(false);

                    func.Should().Throw <HttpRequestException>();

                    func = async() => await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), validator.Object, path).ConfigureAwait(false);

                    func.Should().Throw <HttpRequestException>();
                }
        }
        public async Task Given_Validation_Result_With_HttpCompletionOption_When_GetAsync_Invoked_Then_It_Should_Return_Result(HttpStatusCode statusCode, HttpCompletionOption option)
        {
            var requestUri = "http://localhost";
            var payload    = "{ \"hello\": \"world\" }";

            var validator = new Mock <ISchemaValidator>();

            validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true);

            var path = "default.json";

            using (var response = this._fixture.CreateHttpResponseMessage(statusCode, payload))
                using (var handler = this._fixture.CreateFakeHttpMessageHandler(response))
                    using (var httpClient = this._fixture.CreateHttpClient(handler))
                        using (var result1 = await HttpClientExtensions.GetAsync(httpClient, requestUri, option, validator.Object, path).ConfigureAwait(false))
                            using (var result2 = await HttpClientExtensions.GetAsync(httpClient, new Uri(requestUri), option, validator.Object, path).ConfigureAwait(false))
                            {
                                result1.Should().Be(response);
                                result2.Should().Be(response);
                            }
        }