Esempio n. 1
0
        public async Task It_supports_actions_that_accept_an_array_of_complex_types()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(SuppliersController)))) {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route and post data to the test controller is valid
                var suppliers = new SupplierDtos {
                    Suppliers = new List <SupplierDto>
                    {
                        new SupplierDto
                        {
                            Name        = "SupplierNameOne",
                            Code        = "CodeOne",
                            Description = "SupplierOneDescription"
                        },
                        new SupplierDto
                        {
                            Name        = "SupplierNameTwo",
                            Code        = "CodeTwo",
                            Description = "SupplierTwoDescription"
                        }
                    }
                };

                var result = await httpClient.PostAsJsonAsync("/odata/Suppliers/Default.PostArrayOfSuppliers", suppliers);

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

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Suppliers/Default.PostArrayOfSuppliers", 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().name.Should().Be("parameters");
                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("suppliers");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "suppliers").Value.type.Should().Be("array");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "suppliers").Value.items.Should().NotBeNull();
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "suppliers")[email protected]().Be("#/definitions/SupplierDto");

                swaggerDocument.definitions.Keys.Should().Contain("SupplierDto");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 2
0
        public async Task It_handles_a_null_route_prefix()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(PinsController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the OData route in the test controller is valid
                var result = await httpClient.GetAsync("/Pins");

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

                // Act and Assert
                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 3
0
        public static async Task ValidateSwaggerJson()
        {
            // Arrange
            var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

            // Act
            var response = await httpClient.GetAsync("swagger/docs/v1");

            // Assert
            await response.ValidateSuccessAsync();

            await IsValidAgainstJsonSchemaAsync(response);

            await HasUniqueOperationIdsAsync(response);
        }
Esempio n. 4
0
        public async Task It_generates_a_single_get_path_issue_28_problem_3()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(Products1Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                swaggerDocument.paths.Count.Should().Be(2);

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 5
0
        public async Task Schema_contains_nested_reference_types_for_web_api_controllers()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, builder => Configuration(builder, typeof(ClientsController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                swaggerDocument.definitions["Client"].properties.ContainsKey("projects").Should().BeTrue();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 6
0
        public async Task It_supports_odata_routes_that_dont_map_to_a_controller()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, builder => Configuration(builder)))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                swaggerDocument.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 7
0
        public async Task It_applies_document_filters()
        {
            // Arrange
            Action <SwaggerDocsConfig> config = c => c.DocumentFilter <ApplyNewHostName>();
            var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

            using (WebApp.Start(HttpClientUtils.BaseAddress, builder => Configuration(builder, swaggerDocsConfig: config)))
            {
                // Act
                var swaggerDocument = await httpClient.GetJsonAsync <SwaggerDocument>("swagger/docs/v1");

                // Assert
                swaggerDocument.host.Should().Be("foo");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_wraps_string_type_url_params_with_single_quotes()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductsV1Controller))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/v1/Products({Id})/Default.CalculateGeneralSalesTax(state='{state}')", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();
            }
        }
Esempio n. 9
0
        public async Task By_default_the_schema_does_not_contain_nested_reference_types_for_odata_controllers()
        {
            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
                swaggerDocument.definitions["Customer"].properties.ContainsKey("Orders").Should().BeFalse();
                swaggerDocument.definitions["Order"].properties.ContainsKey("Customer").Should().BeFalse();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 10
0
        public async Task Schema_can_be_configured_to_display_nested_reference_types_for_odata_controllers()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(CustomersController), oc => oc.IncludeNavigationProperties())))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                swaggerDocument.definitions["Customer"].properties.ContainsKey("Orders").Should().BeTrue();
                swaggerDocument.definitions["Order"].properties.ContainsKey("Customer").Should().BeTrue();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 11
0
        public async Task It_supports_actions_against_an_entity()
        {
            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 rating = new RatingDto {
                    Rating = 1
                };
                var result = await httpClient.PostAsJsonAsync("/odata/Suppliers(1)/Default.Rate", rating);

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

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Suppliers({Id})/Default.Rate", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.post.Should().NotBeNull();
                pathItem.post.parameters.Count.Should().Be(2);

                var idParameter = pathItem.post.parameters.SingleOrDefault(parameter => parameter.@in == "path");
                idParameter.Should().NotBeNull();
                idParameter.type.Should().Be("integer");
                idParameter.format.Should().Be("int32");
                idParameter.name.Should().Be("Id");

                var bodyParameter = pathItem.post.parameters.SingleOrDefault(parameter => parameter.@in == "body");
                bodyParameter.Should().NotBeNull();
                [email protected]().Be("body");
                bodyParameter.schema.Should().NotBeNull();
                bodyParameter.schema.type.Should().Be("object");
                bodyParameter.schema.properties.Should().NotBeNull();
                bodyParameter.schema.properties.Count.Should().Be(1);
                bodyParameter.schema.properties.Should().ContainKey("Rating");
                bodyParameter.schema.properties.Single(pair => pair.Key == "Rating").Value.type.Should().Be("integer");
                bodyParameter.schema.properties.Single(pair => pair.Key == "Rating").Value.format.Should().Be("int32");
                bodyParameter.schema.required.Should().NotBeNull();
                bodyParameter.schema.required.Count.Should().Be(1);
                bodyParameter.schema.required.Should().Contain("Rating");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 12
0
        public async Task It_has_single_entity_odata_query_parameters()
        {
            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({Id})", out pathItem);
                pathItem.get.parameters.Where(parameter => parameter.name.StartsWith("$")).Should().HaveCount(2);

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 13
0
        public async Task It_supports_a_parameterless_function_bound_to_a_collection()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductsV1Controller)))) {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/v1/Products/Default.MostExpensive()", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
        public async Task It_allows_definition_of_custom_delete_routes()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, builder => Configuration(builder, typeof(OrdersController)))) {
                // 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({Id})/Orders({orderID})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.delete.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 15
0
        public async Task It_supports_unbound_functions()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(ProductsV1Controller)))) {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/v1/GetSalesTaxRate(state='{state}')", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 16
0
        public async Task It_handles_an_odata_route_prefix_attribute(string path)
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(RoutePrefixedPinsController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue(path, out pathItem);
                pathItem.Should().NotBeNull();

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

            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => SharedModelsSetup.ConfigurationWithFormatters(appBuilder, config, typeof(SharedModelsSetup.SharedModelsController), typeof(SharedModelsSetup.SharedModelsWebApiController))))
            {
                // Access swagger doc first
                await ValidationUtils.ValidateSwaggerJson();

                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);
                // Verify that the custom web api model can be serialized
                var webApiResults = await httpClient.GetJsonAsync <List <SharedModelsSetup.CustomApiModel> >("CustomApiModels");

                webApiResults.Should().NotBeNull();
                webApiResults.Count.Should().Be(2);
            }
        }
Esempio n. 18
0
        public async Task It_supports_types_with_a_guid_primary_key()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(OrdersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

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

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 19
0
        public async Task It_explores_the_correct_controller()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, builder => Configuration(builder, typeof(CustomersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem defaultCustomerController;
                swaggerDocument.paths.TryGetValue("/odata/Customers({Id})", out defaultCustomerController);
                defaultCustomerController.Should().NotBeNull();
                defaultCustomerController.put.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 20
0
        public async Task It_includes_a_put_operation()
        {
            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({Id})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.put.Should().NotBeNull();

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 21
0
        public async Task It_has_a_body_parameter_with_a_schema()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(OrdersController))))
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Orders({OrderId})", out pathItem);
                pathItem.patch.parameters.Single(parameter => parameter.@in == "body").schema.Should().NotBeNull();
                pathItem.patch.parameters.Single(parameter => parameter.@in == "body")[email protected]().Be("#/definitions/Order");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 22
0
        public async Task It_has_a_parameter_with_a_name_equal_to_the_path_name()
        {
            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({Id})", out pathItem);
                pathItem.Should().NotBeNull();
                pathItem.get.Should().NotBeNull();
                pathItem.get.parameters.Should().Contain(parameter => parameter.name == "Id");

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 23
0
        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();
            }
        }
Esempio n. 24
0
        public async Task It_supports_composite_key_with_enum_issue_108()
        {
            using (WebApp.Start(HttpClientUtils.BaseAddress,
                                appBuilder => ConfigurationCompositeKey(appBuilder, true))
                   )
            {
                // Arrange
                var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress);

                // Verify that the OData route in the test controller is valid
                var response = await httpClient.GetAsync($"/{ODataRoutePrefix}/{CompositeKeyEndpointName}");

                await response.ValidateSuccessAsync();

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

                // Assert
                PathItem pathItem;
                var      testEndpoint = $"/{ODataRoutePrefix}/{CompositeKeyEndpointName}({IdKeyName}={{{IdKeyName}}},{EnumKeyName}='{{{EnumKeyName}}}')";
                swaggerDocument.paths.TryGetValue(testEndpoint, out pathItem);
                pathItem.Should().NotBeNull();

                // Assert Enum Pararemter
                var enumParamter = [email protected](p => p.name == EnumKeyName);
                enumParamter.Should().NotBeNull();
                [email protected]().NotBeEmpty();
                [email protected]().Be("path");
                [email protected]().Be("string");
                //enumParamter?.required.Should().BeEquivalentTo(true);

                // Assert Id Pararemter
                var idParamter = [email protected](p => p.name == IdKeyName);
                idParamter.Should().NotBeNull();
                [email protected]().Be("path");
                [email protected]().Be("integer");
                //idParamter?.required.Should().BeEquivalentTo(true);

                await ValidationUtils.ValidateSwaggerJson();
            }
        }
Esempio n. 25
0
        public async Task It_supports_actions_with_only_body_paramters()
        {
            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 SupplierDto {
                    Name        = "SupplierName",
                    Code        = "SDTO",
                    Description = "SupplierDescription"
                };
                var result = await httpClient.PostAsJsonAsync("/odata/Suppliers/Default.Create", supplierDto);

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

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

                // Assert
                PathItem pathItem;
                swaggerDocument.paths.TryGetValue("/odata/Suppliers/Default.Create", 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.properties.Should().NotBeNull();
                pathItem.post.parameters.Single().schema.properties.Count.Should().Be(3);
                pathItem.post.parameters.Single().schema.properties.Should().ContainKey("code");
                pathItem.post.parameters.Single().schema.properties.Should().ContainKey("name");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "name").Value.type.Should().Be("string");
                pathItem.post.parameters.Single().schema.properties.Should().ContainKey("description");
                pathItem.post.parameters.Single().schema.properties.Single(pair => pair.Key == "description").Value.type.Should().Be("string");
                pathItem.post.parameters.Single().schema.required.Should().NotBeNull();
                pathItem.post.parameters.Single().schema.required.Count.Should().Be(2);
                pathItem.post.parameters.Single().schema.required.Should().Contain("code");
                pathItem.post.parameters.Single().schema.required.Should().Contain("name");

                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();
            }
        }
Esempio n. 27
0
        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();
            }
        }
Esempio n. 28
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();
            }
        }
Esempio n. 29
0
        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();
            }
        }
Esempio n. 30
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();
            }
        }