public async Task It_supports_actions_with_an_optional_enum_parameter()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(SuppliersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var supplierDto = new SupplierWithEnumDto
                {
                    EnumValue = MyEnum.ValueOne
                };
                var result = await httpClient.PostAsJsonAsync("/odata/Suppliers/Default.CreateWithEnum", supplierDto);

                result.IsSuccessStatusCode.Should().BeTrue();

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Suppliers/Default.CreateWithEnum", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.post.Should().NotBeNull();
                pathItem.post.parameters.Count.Should().Be(1);
                pathItem.post.parameters.Single()[email protected]().Be("body");
                pathItem.post.parameters.Single().schema.Should().NotBeNull();
                pathItem.post.parameters.Single().schema.type.Should().Be("object");
                pathItem.post.parameters.Single().schema.properties.Should().NotBeNull();
                pathItem.post.parameters.Single().schema.properties.Count.Should().Be(1);
                pathItem.post.parameters.Single().schema.properties.Should().ContainKey("EnumValue");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "EnumValue").Value.type.Should().Be("string");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "EnumValue")[email protected]().NotBeNull();
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "EnumValue")[email protected]().Be(2);
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "EnumValue")[email protected]().Should().Be(MyEnum.ValueOne.ToString());
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "EnumValue")[email protected](1).First().Should().Be(MyEnum.ValueTwo.ToString());
                pathItem.post.parameters.Single().schema.required.Should().BeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #2
0
        public async Task It_consumes_application_json()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(CustomersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Customers", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.post.Should().NotBeNull();
                pathItem.post.consumes.Should().NotBeNull();
                pathItem.post.consumes.Count.Should().Be(1);
                pathItem.post.consumes.First().Should().Be("application/json");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #3
0
        public async Task It_has_a_restier_get_users_response_of_type_array()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, Configuration))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/restier/Users", out pathItem);
                var getUsersResponse = pathItem.get.responses.SingleOrDefault(response => response.Key == "200");
                getUsersResponse.Should().NotBeNull();
                [email protected]().BeNull();
                [email protected]().Be("#/definitions/User");
                getUsersResponse.Value.schema.type.Should().Be("array");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #4
0
        public async Task It_produces_an_accurate_odata_response_model_for_iqueryable_return_type()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductResponsesController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var oDataResponse = await httpClient.GetJsonAsync <ODataResponse <List <ProductResponse> > >("/odata/ProductResponses");

                oDataResponse.Value.Should().NotBeNull();
                oDataResponse.Value.Count.Should().Be(20);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/ProductResponses", out pathItem);
                pathItem.get.Should().NotBeNull();
                pathItem.get.produces.Should().NotBeNull();
                pathItem.get.produces.Count.Should().Be(1);
                pathItem.get.produces.First().Should().Be("application/json");
                var getResponse = pathItem.get.responses.SingleOrDefault(response => response.Key == "200");
                getResponse.Should().NotBeNull();
                [email protected]().Be("#/definitions/ODataResponse[List[ProductResponse]]");
                swaggerDocument.definitions.Should().ContainKey("ODataResponse[List[ProductResponse]]");
                var responseSchema = swaggerDocument.definitions["ODataResponse[List[ProductResponse]]"];
                responseSchema.Should().NotBeNull();
                responseSchema.properties.Should().NotBeNull();
                responseSchema.properties.Should().ContainKey("@odata.context");
                responseSchema.properties["@odata.context"].type.Should().Be("string");
                responseSchema.properties["value"].type.Should().Be("array");
                responseSchema.properties["value"].items.Should().NotBeNull();
                responseSchema.properties["value"][email protected]().Be("#/definitions/ProductResponse");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_supports_entity_with_a_decimal_key()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(DecimalParametersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var result = await httpClient.GetJsonAsync <DecimalParameter>("/odata/DecimalParameters(2.3m)");

                result.Should().NotBeNull();

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/DecimalParameters({Id})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_supports_get_by_id_action_with_http_method_name_issue_28_problem_1()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(Products1Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var product = await httpClient.GetJsonAsync <Product1>("/odata/Products1(1)");

                product.Should().NotBeNull();

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Products1({Id})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #7
0
        public async Task It_includes_the_filter_parameter()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(CustomersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Customers", out pathItem);
                pathItem.Should().NotBeNull();
                var filterParameter = pathItem.get.parameters.SingleOrDefault(parameter => parameter.name == "$filter");
                filterParameter.Should().NotBeNull();
                filterParameter.description.Should().NotBeNullOrWhiteSpace();
                filterParameter.type.Should().BeEquivalentTo("string");
                [email protected]().BeEquivalentTo("query");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_supports_a_function_bound_to_an_entity_with_enum_parameters()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductsV1Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var match = await httpClient.GetJsonAsync <ODataResponse <bool> >("/odata/v1/Products(3)/Default.IsEnumValueMatch(EnumValue=SwashbuckleODataSample.Models.MyEnum'ValueOne')");

                match.Should().NotBeNull();

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/v1/Products({Id})/Default.IsEnumValueMatch(EnumValue=SwashbuckleODataSample.Models.MyEnum'{EnumValue}')", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_supports_custom_attribute_routing_convention()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => MillsSetup.Configuration(appBuilder, typeof(MillsSetup.MillsController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var results = await httpClient.GetJsonAsync <ODataResponse <List <MillsSetup.Mill> > >("odata/Mills");

                results.Should().NotBeNull();
                results.Value.Count.Should().Be(4);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Mills", out pathItem);
                pathItem.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #10
0
        public async Task It_supports_uris_that_contain_arrays()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(Products2Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var products = await httpClient.GetJsonAsync <ODataResponse <List <Product2> > >("/odata/ProductsWithIds(Ids=[0,1])");

                products.Should().NotBeNull();
                products.Value.Count.Should().Be(2);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/ProductsWithIds(Ids=[{Ids}])", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_consolidates_tags_in_final_swagger_model()
        {
            Action <SwaggerDocsConfig> config = c => c.DocumentFilter <ApplySharedModelsDocumentation>();

            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => SharedModelsSetup.Configuration(appBuilder, config, typeof(SharedModelsSetup.SharedModelsController), typeof(SharedModelsSetup.SharedModelsWebApiController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var results = await httpClient.GetJsonAsync <ODataResponse <List <SharedModelsSetup.SharedModel> > >("odata/SharedModels");

                results.Should().NotBeNull();
                results.Value.Count.Should().Be(4);

                // Verify that the WebApi route in the test controller is valid
                var webApiResults = await httpClient.GetJsonAsync <List <SharedModelsSetup.SharedModel> >("SharedModels");

                webApiResults.Should().NotBeNull();
                webApiResults.Count.Should().Be(4);

                // Act and Assert
                await ValidationUtils.ValidateSwaggerJson();
            }
        }
예제 #12
0
        public async Task It_supports_functions_with_multiple_parameters()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductsV1Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var products = await httpClient.GetJsonAsync <ODataResponse <List <Product1> > >("/odata/v1/Products/Default.MultipleParams(Id=3,Year=2015)");

                products.Should().NotBeNull();
                products.Value.Count.Should().Be(2);

                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/v1/Products/Default.MultipleParams(Id={Id},Year={Year})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }