Exemplo n.º 1
0
        public async Task TestWFV1(string extraPath)
        {
            await LogWebException(async() =>
            {
                var requestUrl = new UrlToWFV1(ApiBaseUrl, PathToV1WeatherForecast + extraPath).ToUri();
                LogRequestUrl(requestUrl);

                using (var response = await TestRequest <WeatherForecastV1[]>(requestUrl))
                {
                    Assert.That(response.Data.Length, Is.EqualTo(5));
                }
            });
        }
        public async Task TestV1(string endpoint, string route)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, endpoint + route).ToUri();

            await LogWebException(
                async() =>
            {
                var requestUrl = new UrlToWFV1(ApiBaseUrl, endpoint + route).ToUri();
                using (var response = await TestRequest <WeatherForecastV1[]>(requestUrl))
                {
                    Assert.That(response.Data.Length, Is.EqualTo(5));
                }
            });
        }
Exemplo n.º 3
0
        public virtual async Task TestWorkingMapToApiVersion(string endpoint, string date, string expectedSummary)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, endpoint)
            {
                From = date
            }.ToUri();

            await LogWebException(
                async() =>
            {
                using (var response = await TestRequest <WeatherForecastV1_1[]>(requestUrl))
                {
                    Assert.That(response.Data.Length, Is.EqualTo(5));
                    Assert.That(response.Data[0].Summary, Is.EqualTo(expectedSummary));
                }
            });
        }
        public async Task TestV1WithRouteParameter(string endpoint, string date,
                                                   int expectedNumberOfResults, string expectedFirstDate)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, endpoint)
            {
                From = date
            }.ToUri();

            await LogWebException(async() =>
            {
                using (var response = await TestRequest <WeatherForecastV1[]>(requestUrl))
                {
                    Assert.That(response.Data.Length, Is.EqualTo(expectedNumberOfResults));
                    Assert.That(response.Data[0].Date, Is.EqualTo(expectedFirstDate));
                }
            });
        }
Exemplo n.º 5
0
        public async Task TestWFWithInvalidDateV1(string date)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, PathToV1WeatherForecast)
            {
                From = date
            }.ToUri();

            LogRequestUrl(requestUrl);

            await VerifyWebException <ValidationErrorResponseModel>(
                test : async() =>
            {
                using (var response = await TestRequest <WeatherForecastV1[]>(requestUrl)) { }
            },
                statusCode : HttpStatusCode.InternalServerError,
                verify : err => Assert.That(err.Title,
                                            Is.EqualTo($"'{date}' in URL should be in yyyyMMdd format. (Parameter 'date')")));
        }
Exemplo n.º 6
0
        public virtual async Task TestMultipleEndpointsMatchedError(string endpoint, string date)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, endpoint)
            {
                From = date
            }.ToUri();

            await VerifyWebException <InternalServerErrorResponseModel>(
                test : async() =>
            {
                using (var response = await TestRequest <WeatherForecastV1_1[]>(requestUrl))
                {
                }
            },
                statusCode : System.Net.HttpStatusCode.InternalServerError,
                verify : err =>
            {
                Assert.That(err.Title, Does.StartWith(
                                $"The request matched multiple endpoints. Matches:"));
            });
        }
Exemplo n.º 7
0
        public async Task TestWFWithDateV1(string date, string[] dates)
        {
            var requestUrl = new UrlToWFV1(ApiBaseUrl, PathToV1WeatherForecast)
            {
                From = date
            }.ToUri();

            LogRequestUrl(requestUrl);

            await LogWebException(async() =>
            {
                using (var response = await TestRequest <WeatherForecastV1[]>(requestUrl))
                {
                    Assert.That(response.Data.Length, Is.EqualTo(5));
                    Assert.That(response.Data[0].Date, Is.EqualTo(dates[0]));
                    Assert.That(response.Data[1].Date, Is.EqualTo(dates[1]));
                    Assert.That(response.Data[2].Date, Is.EqualTo(dates[2]));
                    Assert.That(response.Data[3].Date, Is.EqualTo(dates[3]));
                    Assert.That(response.Data[4].Date, Is.EqualTo(dates[4]));
                }
            });
        }
Exemplo n.º 8
0
        public async Task TestInvalidVersion(string match, string replacement, string expectedCode, string expectedMessage)
        {
            var path       = PathToV1WeatherForecast.Replace(match, replacement);
            var requestUrl = new UrlToWFV1(ApiBaseUrl, path).ToUri();

            LogRequestUrl(requestUrl);

            expectedMessage = expectedMessage.Replace("{requestUrl}", requestUrl.ToString());

            await VerifyWebException <BadRequestResponseModel>(
                test : async() =>
            {
                using (var response = await TestRequest <WeatherForecastV2[]>(requestUrl,
                                                                              options => options.Converters.Add(new DateTimeJsonConverter()))) { }
            },
                statusCode : HttpStatusCode.BadRequest,
                verify : err =>
            {
                Assert.That(err.Error?.Code, Is.EqualTo(expectedCode));
                Assert.That(err.Error?.Message, Is.EqualTo(expectedMessage));
            });
        }