public void CreatePathsReturnsForBasicModelWithPrefix()
        {
            // Arrange
            IEdmModel model = EdmModelHelper.BasicEdmModel;
            OpenApiConvertSettings settings = new OpenApiConvertSettings
            {
                EnableKeyAsSegment = true,
                PathPrefix         = "some/prefix"
            };
            ODataContext context = new ODataContext(model, settings);

            // Act
            var paths = context.CreatePaths();

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(7, paths.Count);

            Assert.Contains("/some/prefix/People", paths.Keys);
            Assert.Contains("/some/prefix/People/{UserName}", paths.Keys);
            Assert.Contains("/some/prefix/City", paths.Keys);
            Assert.Contains("/some/prefix/City/{Name}", paths.Keys);
            Assert.Contains("/some/prefix/CountryOrRegion", paths.Keys);
            Assert.Contains("/some/prefix/CountryOrRegion/{Name}", paths.Keys);
            Assert.Contains("/some/prefix/Me", paths.Keys);
        }
        /// <summary>
        /// Create a <see cref="OpenApiDocument"/>, it's a single Open API Object.
        /// </summary>
        /// <param name="context">The OData to Open API context.</param>
        /// <returns>The created <see cref="OpenApiDocument"/> object.</returns>
        public static OpenApiDocument CreateDocument(this ODataContext context)
        {
            Utils.CheckArgumentNull(context, nameof(context));

            // An OAS document consists of a single OpenAPI Object represented as OpenApiDocument object.
            // {
            //   "openapi":"3.0.0",
            //   "info": …,
            //   "servers": …,
            //   "tags": …,
            //   "paths": …,
            //   "components": …
            // }
            OpenApiDocument doc = new OpenApiDocument
            {
                Info = context.CreateInfo(),

                Servers = context.CreateServers(),

                //   Tags = context.CreateTags(),

                Paths = context.CreatePaths(),

                Components = context.CreateComponents(),

                SecurityRequirements = null,

                ExternalDocs = null
            };

            doc.Tags = context.CreateTags();

            return(doc);
        }
        public void CreatePathsThrowArgumentNullContext()
        {
            // Arrange
            ODataContext context = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>("context", () => context.CreatePaths());
        }
示例#4
0
        public void CreatePathsReturnsForBasicModelWithPrefix(bool useAnnotationToGeneratePath, int pathCount)
        {
            // Arrange
            IEdmModel model = EdmModelHelper.BasicEdmModel;
            OpenApiConvertSettings settings = new OpenApiConvertSettings
            {
                EnableKeyAsSegment = true,
                PathPrefix         = "some/prefix",
                RequireRestrictionAnnotationsToGenerateComplexPropertyPaths = useAnnotationToGeneratePath
            };
            ODataContext context = new ODataContext(model, settings);

            // Act
            var paths = context.CreatePaths();

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(pathCount, paths.Count);

            if (useAnnotationToGeneratePath)
            {
                Assert.Contains("/some/prefix/People", paths.Keys);
                Assert.Contains("/some/prefix/People/$count", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}", paths.Keys);
                Assert.Contains("/some/prefix/City", paths.Keys);
                Assert.Contains("/some/prefix/City/$count", paths.Keys);
                Assert.Contains("/some/prefix/City/{Name}", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion/$count", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion/{Name}", paths.Keys);
                Assert.Contains("/some/prefix/Me", paths.Keys);
            }
            else
            {
                Assert.Contains("/some/prefix/People", paths.Keys);
                Assert.Contains("/some/prefix/People/$count", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}/Addresses", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}/Addresses/$count", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}/HomeAddress", paths.Keys);
                Assert.Contains("/some/prefix/People/{UserName}/HomeAddress/City", paths.Keys);
                Assert.Contains("/some/prefix/City", paths.Keys);
                Assert.Contains("/some/prefix/City/$count", paths.Keys);
                Assert.Contains("/some/prefix/City/{Name}", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion/$count", paths.Keys);
                Assert.Contains("/some/prefix/CountryOrRegion/{Name}", paths.Keys);
                Assert.Contains("/some/prefix/Me", paths.Keys);
                Assert.Contains("/some/prefix/Me/Addresses", paths.Keys);
                Assert.Contains("/some/prefix/Me/Addresses/$count", paths.Keys);
                Assert.Contains("/some/prefix/Me/HomeAddress", paths.Keys);
                Assert.Contains("/some/prefix/Me/HomeAddress/City", paths.Keys);
                Assert.Contains("/some/prefix/Me/WorkAddress", paths.Keys);
                Assert.Contains("/some/prefix/Me/WorkAddress/City", paths.Keys);
            }
        }
        public void CreatePathsReturnsForEmptyModel()
        {
            // Arrange
            IEdmModel    model   = EdmModelHelper.EmptyModel;
            ODataContext context = new ODataContext(model);

            // Act
            var paths = context.CreatePaths();

            // Assert
            Assert.NotNull(paths);
            Assert.Empty(paths);
        }
        public void CreatePathsReturnsForContractModelWithHierarhicalClass()
        {
            // Arrange
            IEdmModel model = EdmModelHelper.ContractServiceModel;
            OpenApiConvertSettings settings = new OpenApiConvertSettings
            {
                EnableKeyAsSegment    = true,
                EnableUnqualifiedCall = true
            };
            ODataContext context = new ODataContext(model, settings);

            // Act
            var paths = context.CreatePaths();

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(4, paths.Count);

            Assert.Contains("/Accounts", paths.Keys);
            Assert.Contains("/Accounts/{id}", paths.Keys);
            Assert.Contains("/Accounts/{id}/Attachments()", paths.Keys);
            Assert.Contains("/Accounts/{id}/AttachmentsAdd", paths.Keys);
        }