예제 #1
0
        // following the Fixture convention.
        protected static void UpdateConfigureServices(IServiceCollection services)
        {
            IEdmModel model = UnboundFunctionEdmModel.GetEdmModel();

            services.ConfigureControllers(typeof(ConventionCustomersController), typeof(MetadataController));

            services.AddControllers().AddOData(opt => opt.AddModel("odata", model)
                                               .Count().Filter().OrderBy().Expand().SetMaxTop(null).Select());
        }
예제 #2
0
        public async Task ServiceDocumentTest()
        {
            // Arrange
            var        requestUri = "odata";
            HttpClient client     = CreateClient();

            // Act
            var response = await client.GetAsync(requestUri);

            var stream = await response.Content.ReadAsStreamAsync();

            //Assert
            var oDataMessageReaderSettings = new ODataMessageReaderSettings();
            IODataResponseMessage message  = new ODataMessageWrapper(stream, response.Content.Headers);
            var reader         = new ODataMessageReader(message, oDataMessageReaderSettings, UnboundFunctionEdmModel.GetEdmModel());
            var oDataWorkSpace = reader.ReadServiceDocument();

            var function1 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetAllConventionCustomers");

            Assert.Single(function1);
            var function2 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionOrderByCustomerIdAndOrderName");

            // ODL spec says:
            // The edm:FunctionImport for a parameterless function MAY include the IncludeInServiceDocument attribute
            // whose Boolean value indicates whether the function import is advertised in the service document.
            // So the below 2 FunctionImports are not displayed in ServiceDocument.
            Assert.Empty(function2);
            var function3 = oDataWorkSpace.FunctionImports.Where(odataResourceCollectionInfo => odataResourceCollectionInfo.Name == "GetConventionCustomerById");

            Assert.Empty(function3);
        }