Exemplo n.º 1
0
        public async void SwaggerFileSourceYamlWithWhitelistTest()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "getSupportTicketCasesList" }
                });
            });

            var requests = await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/support-tickets-ok.yaml")
            });

            _logger.LogInformation(JsonConvert.SerializeObject(requests));

            Assert.Equal("https://petstore3.swagger.io/api/support/v2", requests.FirstOrDefault().BasePath);
            Assert.Equal(HttpMethod.Get, requests.FirstOrDefault().Method);
            Assert.Equal("getSupportTicketCasesList", requests.FirstOrDefault().OperationId);
            Assert.Empty(requests.FirstOrDefault().RequestBodies);
            Assert.Equal(4, requests.FirstOrDefault().Responses.Count);
            Assert.Equal(2, requests.FirstOrDefault().Parameters.Count);
            Assert.Null(requests.FirstOrDefault().Parameters.FirstOrDefault(p => p.Name == "Area").Value);
            Assert.Single(requests);
        }
Exemplo n.º 2
0
        public async Task UploadPetImageWithExampleValuesTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "uploadFile" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Single(requests);

            Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
            Assert.Equal("https://petstore3.swagger.io/api/v3", requests.FirstOrDefault().BasePath);
            Assert.Equal("", requests.FirstOrDefault().Description);
            Assert.Equal(HttpMethod.Post, requests.FirstOrDefault().Method);
            Assert.Equal("uploadFile", requests.FirstOrDefault().OperationId);
            Assert.Equal("/pet/{petId}/uploadImage", requests.FirstOrDefault().Path);
            Assert.Single(requests.FirstOrDefault().Responses);
            Assert.Equal(2, requests.FirstOrDefault().Parameters.Count);

            /* var expectedUploadPetImageParameters = UploadPetImageParameters.Get(true).ToExpectedObject();
             * expectedUploadPetImageParameters.ShouldEqual(requests.FirstOrDefault().Parameters);
             *
             * var expectedUploadPetImageBody = UploadPetImageBody.Get().ToExpectedObject();
             * expectedUploadPetImageBody.ShouldEqual(requests.FirstOrDefault().RequestBodies
             *   .Where(c => c.ContentType == ContentType.OctetStream.Value()).ToList());
             *
             * var expectedUploadPetImageResponse = UploadPetImageResponse.Get().ToExpectedObject();
             * expectedUploadPetImageResponse.ShouldEqual(requests.FirstOrDefault().Responses);
             */
            var expectedUploadPetImageParameters = JsonConvert.SerializeObject(UploadPetImageParameters.Get(true), Formatting.None);

            Assert.Equal(expectedUploadPetImageParameters.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().Parameters, Formatting.None).ToLower());

            var expectedUploadPetImageBody = JsonConvert.SerializeObject(UploadPetImageBody.Get(), Formatting.None);

            Assert.Equal(expectedUploadPetImageBody.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().RequestBodies.Where(c => c.ContentType == ContentType.OctetStream.Value()), Formatting.None).ToLower());

            var expectedUploadPetImageResponse = JsonConvert.SerializeObject(UploadPetImageResponse.Get().OrderBy(x => x.StatusCode), Formatting.None);

            Assert.Equal(expectedUploadPetImageResponse.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().Responses.OrderBy(x => x.StatusCode), Formatting.None).ToLower());

            Assert.Equal("uploads an image", requests.FirstOrDefault().Summary);
            Assert.Collection(requests.FirstOrDefault().Tags, item =>
            {
                item = "pet";
            });
            Assert.Empty(requests.FirstOrDefault().TestTypes);
        }
Exemplo n.º 3
0
        public async void UnsupportedSwaggerFilev3_1_Fails()
        {
            var fileSource = new SwaggerFileSource();

            Assert.ThrowsAsync <UnsupportedSwaggerException>(async() => await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/swagger-pets-test-unsuppoted-v3.1.json")
            }));
        }
Exemplo n.º 4
0
        public async void InvalidSwaggerFile_Fails()
        {
            var fileSource = new SwaggerFileSource();

            Assert.ThrowsAsync <InvalidSwaggerException>(async() => await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/invalid.swagger.json")
            }));
        }
Exemplo n.º 5
0
        public async void SwaggerFileSourceYamlWithoutWhitelistTest_Fails()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
            });

            Assert.ThrowsAsync <InvalidSwaggerException>(async() => await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/support-tickets.yaml")
            }));
        }
Exemplo n.º 6
0
        public async void SwaggerFileSourceWithOptionsTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
            });

            var requests = await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/swagger-pets-test.json")
            });

            Assert.NotNull(requests);
            Assert.Equal(19, requests.Count());
        }
        public async Task PetsSwaggerGetByPetByIdWithExcampleValuesTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "findPetsByTags" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Single(requests);
            Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
            Assert.Equal("https://petstore3.swagger.io/api/v3", requests.FirstOrDefault().BasePath);
            Assert.Equal("Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", requests.FirstOrDefault().Description);
            Assert.Equal(HttpMethod.Get, requests.FirstOrDefault().Method);
            Assert.Equal("findPetsByTags", requests.FirstOrDefault().OperationId);
            Assert.Single(requests.FirstOrDefault().Parameters);
            Assert.False(requests.FirstOrDefault().Parameters.FirstOrDefault().Nullable);
            Assert.False(requests.FirstOrDefault().Parameters.FirstOrDefault().Required);
            Assert.Equal(Location.Query, requests.FirstOrDefault().Parameters.FirstOrDefault().Location);
            Assert.Equal("array", requests.FirstOrDefault().Parameters.FirstOrDefault().Type);
            Assert.Equal("tags", requests.FirstOrDefault().Parameters.FirstOrDefault().Name);
            Assert.Null(requests.FirstOrDefault().Parameters.FirstOrDefault().Value);
            Assert.Equal("/pet/findByTags", requests.FirstOrDefault().Path);
            Assert.Empty(requests.FirstOrDefault().RequestBodies);
            Assert.Equal(2, requests.FirstOrDefault().Responses.Count);

            var expectedPetsResponse = JsonConvert.SerializeObject(FindPetsByTagsResponses.Get(true).OrderBy(x => x.StatusCode), Formatting.None);

            Assert.Equal(expectedPetsResponse.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().Responses.OrderBy(x => x.StatusCode), Formatting.None).ToLower());


            Assert.Equal("Finds Pets by tags", requests.FirstOrDefault().Summary);
            Assert.Collection(requests.FirstOrDefault().Tags, item =>
            {
                item = "pet";
            });
            Assert.Empty(requests.FirstOrDefault().TestTypes);
        }
        public async Task AllEndpointsSuccessfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Equal(19, requests.Count());
        }
Exemplo n.º 9
0
        public async Task PetsSwaggerGetPetByIdWithExampleValuesTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "getPetById" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Single(requests);
            Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
            Assert.Equal("https://petstore3.swagger.io/api/v3", requests.FirstOrDefault().BasePath);
            Assert.Equal("Returns a single pet", requests.FirstOrDefault().Description);
            Assert.Equal(HttpMethod.Get, requests.FirstOrDefault().Method);
            Assert.Equal("getPetById", requests.FirstOrDefault().OperationId);
            Assert.Single(requests.FirstOrDefault().Parameters);
            Assert.Equal("petId", requests.FirstOrDefault().Parameters.FirstOrDefault().Name);
            Assert.False(requests.FirstOrDefault().Parameters.FirstOrDefault().Nullable);
            Assert.True(requests.FirstOrDefault().Parameters.FirstOrDefault().Required);
            Assert.Equal(Location.Path, requests.FirstOrDefault().Parameters.FirstOrDefault().Location);
            Assert.Equal("integer", requests.FirstOrDefault().Parameters.FirstOrDefault().Type);
            Assert.Null(requests.FirstOrDefault().Parameters.FirstOrDefault().Value);
            Assert.Equal("/pet/{petId}", requests.FirstOrDefault().Path);
            Assert.Empty(requests.FirstOrDefault().RequestBodies);
            Assert.Equal(3, requests.FirstOrDefault().Responses.Count);

            var expectedPetsResponse = GetPetByIdResponse.Get(true).ToExpectedObject();

            expectedPetsResponse.ShouldEqual(requests.FirstOrDefault().Responses);

            Assert.Equal("Find pet by ID", requests.FirstOrDefault().Summary);
            Assert.Collection(requests.FirstOrDefault().Tags, item =>
            {
                item = "pet";
            });
            Assert.Empty(requests.FirstOrDefault().TestTypes);
        }
        public async Task UpdatePetWithExampleValuesTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "updatePet" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Single(requests);
            Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
            Assert.Equal("https://petstore3.swagger.io/api/v3", requests.FirstOrDefault().BasePath);
            Assert.Equal("Update an existing pet by Id", requests.FirstOrDefault().Description);
            Assert.Equal(HttpMethod.Put, requests.FirstOrDefault().Method);
            Assert.Equal("updatePet", requests.FirstOrDefault().OperationId);
            Assert.Empty(requests.FirstOrDefault().Parameters);
            Assert.Equal("/pet", requests.FirstOrDefault().Path);
            Assert.Equal(4, requests.FirstOrDefault().Responses.Count);

            var expectedPetsBody = JsonConvert.SerializeObject(UpdatePetBody.Get(true).FirstOrDefault(), Formatting.None);

            Assert.Equal(expectedPetsBody.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().RequestBodies
                                                                                 .SingleOrDefault(c => c.ContentType == ContentType.Json.Value()), Formatting.None).ToLower());

            var expectedPetsResponse = JsonConvert.SerializeObject(UpdatePetResponse.Get(true), Formatting.None);

            Assert.Equal(expectedPetsResponse.ToLower(), JsonConvert.SerializeObject(requests.FirstOrDefault().Responses, Formatting.None).ToLower());


            Assert.Equal("Update an existing pet", requests.FirstOrDefault().Summary);
            Assert.Collection(requests.FirstOrDefault().Tags, item =>
            {
                item = "pet";
            });
            Assert.Empty(requests.FirstOrDefault().TestTypes);
        }
Exemplo n.º 11
0
        public async Task DeletePetWithExampleValuesTest_Successfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "deletePet" }
                });
                options.UseSwaggerExampleValues = true;
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Single(requests);
            Assert.Empty(requests.FirstOrDefault().AuthenticationTypes);
            Assert.Equal("https://petstore3.swagger.io/api/v3", requests.FirstOrDefault().BasePath);
            Assert.Equal("", requests.FirstOrDefault().Description);
            Assert.Equal(HttpMethod.Delete, requests.FirstOrDefault().Method);
            Assert.Equal("deletePet", requests.FirstOrDefault().OperationId);
            Assert.Equal(2, requests.FirstOrDefault().Parameters.Count);

            var expectedPetDeleteResponse = DeletePetParameters.Get(true).ToExpectedObject();

            expectedPetDeleteResponse.ShouldEqual(requests.FirstOrDefault().Parameters);

            Assert.Equal("/pet/{petId}", requests.FirstOrDefault().Path);
            Assert.Single(requests.FirstOrDefault().Responses);

            var expectedPetsResponse = DeletePetResponse.Get().ToExpectedObject();

            expectedPetsResponse.ShouldEqual(requests.FirstOrDefault().Responses);

            Assert.Equal("Deletes a pet", requests.FirstOrDefault().Summary);
            Assert.Collection(requests.FirstOrDefault().Tags, item =>
            {
                item = "pet";
            });
            Assert.Empty(requests.FirstOrDefault().TestTypes);
        }
Exemplo n.º 12
0
        public async void SwaggerFileSourceYamlWithoutWhitelistTest()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
            });

            var requests = await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/support-tickets-ok.yaml")
            });

            _logger.LogInformation(JsonConvert.SerializeObject(requests));

            File.WriteAllText("d:\\support.json", JsonConvert.SerializeObject(requests, Formatting.Indented));

            Assert.Equal(7, requests.Count());
        }
        public async Task OnlySpecifiedEndpointsSuccessfull()
        {
            var fileSource = new SwaggerFileSource(options =>
            {
                options.AddBaseUrl(new Uri("https://petstore3.swagger.io/"));
                options.AddRequestFilters(new RequestFilter()
                {
                    EndpointNameWhitelist = new string[] { "findPetsByStatus", "deletePet", "addPet", "updatePet" }
                });
            });

            var requests = await fileSource.Load(new List <FileInfo>() {
                new FileInfo("Assets/swagger-pets-test.json")
            });

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

            Assert.NotNull(requests);
            Assert.Equal(4, requests.Count());
        }
Exemplo n.º 14
0
        public async void SwaggerFileSourceWithoutOptionsTest_Fails()
        {
            var fileSource = new SwaggerFileSource();

            var exception = await Assert.ThrowsAsync <QAToolKitSwaggerException>(async() =>
                                                                                 await fileSource.Load(new List <FileInfo>()
            {
                new FileInfo("Assets/swagger-pets-test.json")
            }));

            _logger.LogInformation(exception.Message);
        }