Exemplo n.º 1
0
        public void ReplacePathAndUrlTest_Successfull()
        {
            var content  = File.ReadAllText("Assets/getPetByIdAndStatus.json");
            var requests = JsonConvert.DeserializeObject <IList <HttpRequest> >(content);

            var generator = new HttpRequestUrlGenerator(requests.FirstOrDefault(), options =>
            {
                options.AddReplacementValues(new Dictionary <string, object> {
                    {
                        "petId",
                        "1000"
                    },
                    {
                        "status",
                        2
                    }
                });
            });

            var url = generator.GetUrl();

            _logger.LogInformation(url.ToString());

            Assert.Equal("https://petstore3.swagger.io/api/v3/pet/1000?status=2", url.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate and replace URL parameters with replacement values
        /// </summary>
        /// <param name="request"></param>
        /// <param name="bombardierGeneratorOptions"></param>
        /// <returns></returns>
        internal static string GenerateUrlParameters(HttpRequest request, BombardierGeneratorOptions bombardierGeneratorOptions)
        {
            var generator = new HttpRequestUrlGenerator(request, options =>
            {
                options.AddReplacementValues(bombardierGeneratorOptions.ReplacementValues);
            });

            var url = generator.GetUrl();

            return(url);
        }
        public async Task HttpTesterClientWithSwagger_Success()
        {
            var urlSource = new SwaggerUrlSource(options =>
            {
                options.AddBaseUrl(new Uri("https://qatoolkitapi.azurewebsites.net/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "NewBike" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await urlSource.Load(new Uri[]
            {
                new Uri("https://qatoolkitapi.azurewebsites.net/swagger/v1/swagger.json")
            });

            var replacementValues = new Dictionary <string, object>
            {
                { "api-version", 1 }
            };

            var urlGenerator = new HttpRequestUrlGenerator(requests.FirstOrDefault(),
                                                           options => { options.AddReplacementValues(replacementValues); });

            using (var client = new HttpTesterClient())
            {
                var response = await client
                               .CreateHttpRequest(new Uri(urlGenerator.GetUrl()))
                               .WithHeaders(new Dictionary <string, string>()
                {
                    { "Content-Type", "application/json" }
                })
                               .WithMethod(HttpMethod.Post)
                               .WithJsonBody(BicycleFixture.Get())
                               .Start();

                var msg = await response.GetResponseJsonBody <Bicycle>();

                Assert.True(client.Duration < 2000);
                Assert.True(response.IsSuccessStatusCode);
                Assert.Equal("Giant", msg.Brand);
            }
        }
Exemplo n.º 4
0
        public void GetRequestDataGeneratorWithOneRequest()
        {
            var request = GetUserByIdHttpRequest.Get();


            var generator = new HttpRequestUrlGenerator(request, options =>
            {
                options.AddReplacementValues(new Dictionary <string, object> {
                    {
                        "userId",
                        "100"
                    }
                });
            });

            var url = generator.GetUrl();

            _logger.LogInformation(JsonConvert.SerializeObject(url, Formatting.Indented));

            Assert.NotNull(url);
            Assert.Equal("https://myapi.com/users/100", url);
        }