コード例 #1
0
        public void GetPathsWithContainedNavigationPropertytWorks()
        {
            // Arrange
            string entityType =
                @"<EntityType Name=""Order"">
    <Key>
      <PropertyRef Name=""id"" />
    </Key>
    <NavigationProperty Name=""MultipleCustomers"" Type=""Collection(NS.Customer)"" ContainsTarget=""true"" />
    <NavigationProperty Name=""SingleCustomer"" Type=""NS.Customer"" ContainsTarget=""true"" />
  </EntityType>";

            string            entitySet = @"<EntitySet Name=""Orders"" EntityType=""NS.Order"" />";
            IEdmModel         model     = GetEdmModel(entityType, entitySet);
            ODataPathProvider provider  = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

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

            var pathItems = paths.Select(p => p.GetPathItemName()).ToList();

            Assert.Contains("/Orders({id})/MultipleCustomers", pathItems);
            Assert.Contains("/Orders({id})/MultipleCustomers({ID})", pathItems);
            Assert.Contains("/Orders({id})/SingleCustomer", pathItems);
        }
コード例 #2
0
        public void GetPathsWithStreamPropertyAndWithEntityHasStreamWorks(bool hasStream, string streamPropName)
        {
            // Arrange
            IEdmModel         model    = GetEdmModel(hasStream, streamPropName);
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);

            if (hasStream && !streamPropName.Equals("Content", StringComparison.OrdinalIgnoreCase))
            {
                Assert.Equal(7, paths.Count());
                Assert.Equal(new[] { "/me", "/me/photo", "/me/photo/$value", "/Todos", "/Todos({Id})", "/Todos({Id})/$value", "/Todos({Id})/Logo" },
                             paths.Select(p => p.GetPathItemName()));
            }
            else if ((hasStream && streamPropName.Equals("Content", StringComparison.OrdinalIgnoreCase)) ||
                     (!hasStream && streamPropName.Equals("Content", StringComparison.OrdinalIgnoreCase)))
            {
                Assert.Equal(6, paths.Count());
                Assert.Equal(new[] { "/me", "/me/photo", "/me/photo/$value", "/Todos", "/Todos({Id})", "/Todos({Id})/Content" },
                             paths.Select(p => p.GetPathItemName()));
            }
            else // !hasStream && !streamPropName.Equals("Content")
            {
                Assert.Equal(6, paths.Count());
                Assert.Equal(new[] { "/me", "/me/photo", "/me/photo/$value", "/Todos", "/Todos({Id})", "/Todos({Id})/Logo" },
                             paths.Select(p => p.GetPathItemName()));
            }
        }
コード例 #3
0
        public void GetPathsWithUnboundOperationImportWorks()
        {
            // Arrange
            string boundAction =
                @"<Function Name=""GetNearestCustomers"">
   <ReturnType Type=""NS.Customer"" />
  </Function >
  <Action Name=""ResetDataSource"" />";

            string    unbounds = @"
<FunctionImport Name=""GetNearestCustomers"" Function=""NS.GetNearestCustomers"" EntitySet=""Customers"" />
<ActionImport Name =""ResetDataSource"" Action =""NS.ResetDataSource"" />";
            IEdmModel model    = GetEdmModel(boundAction, unbounds);

            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(4, paths.Count());
            Assert.Contains("/GetNearestCustomers()", paths.Select(p => p.GetPathItemName()));
            Assert.Contains("/ResetDataSource", paths.Select(p => p.GetPathItemName()));
        }
コード例 #4
0
        public void GetPathsWithBoundFunctionOperationForContainmentNavigationPropertyPathsWorks(bool containsTarget)
        {
            // Arrange
            string navProp     = $@"<NavigationProperty Name=""Referral"" Type=""NS.NiceCustomer"" ContainsTarget=""{containsTarget}""/>";
            string boundAction =
                @"<Function Name=""Search"" IsBound=""true"">
   <Parameter Name=""bindingParameter"" Type=""NS.NiceCustomer"" />
     <ReturnType Type=""Collection(NS.Customer)"" />
</Function>
<EntityType Name=""NiceCustomer"">
    <Property Name=""Other"" Type=""Edm.Int32"" Nullable=""true"" />
</EntityType>";

            IEdmModel         model    = GetEdmModel(boundAction, "", navProp);
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);

            if (containsTarget)
            {
                Assert.Equal(5, paths.Count());
                Assert.Contains("/Customers({ID})/Referral/NS.Search()", paths.Select(p => p.GetPathItemName()));
            }
            else
            {
                Assert.Equal(4, paths.Count());
                Assert.DoesNotContain("/Customers({ID})/Referral/NS.Search()", paths.Select(p => p.GetPathItemName()));
            }
        }
コード例 #5
0
        public void GetPathsForGraphBetaModelReturnsAllPaths()
        {
            // Arrange
            IEdmModel         model    = EdmModelHelper.GraphBetaModel;
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(4481, paths.Count());
        }
コード例 #6
0
        public void GetPathsForEmptyEdmModelReturnsEmptyPaths()
        {
            // Arrange
            IEdmModel         model    = new EdmModel();
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model);

            // Assert
            Assert.NotNull(paths);
            Assert.Empty(paths);
        }
コード例 #7
0
        public void GetPathsWithSingletonWorks()
        {
            // Arrange
            IEdmModel         model    = GetEdmModel("", @"<Singleton Name=""Me"" Type=""NS.Customer"" />");
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(3, paths.Count());
            Assert.Contains("/Me", paths.Select(p => p.GetPathItemName()));
        }
コード例 #8
0
        public void GetPathsForSingleEntitySetWorks()
        {
            // Arrange
            IEdmModel         model    = GetEdmModel("", "");
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(2, paths.Count());
            Assert.Equal(new[] { "/Customers", "/Customers({ID})" }, paths.Select(p => p.GetPathItemName()));
        }
コード例 #9
0
        public void GetPathsForGraphBetaModelReturnsAllPaths()
        {
            // Arrange
            IEdmModel         model    = EdmModelHelper.GraphBetaModel;
            var               settings = new OpenApiConvertSettings();
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(4887, paths.Count());
        }
コード例 #10
0
        public void GetPathsForInheritanceModelWithoutDerivedTypesConstraintReturnsMore()
        {
            // Arrange
            IEdmModel         model    = GetInheritanceModel(string.Empty);
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(3, paths.Count());
        }
コード例 #11
0
        public void GetPathsForGraphBetaModelReturnsAllPaths()
        {
            // Arrange
            IEdmModel model    = EdmModelHelper.GraphBetaModel;
            var       settings = new OpenApiConvertSettings()
            {
                ExpandDerivedTypesNavigationProperties = false
            };
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(13836, paths.Count());
        }
コード例 #12
0
        public void GetPathsDoesntReturnPathsForCountWhenDisabled()
        {
            // Arrange
            IEdmModel         model    = GetInheritanceModel(string.Empty);
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings {
                EnableDollarCountPath = false,
                AppendBoundOperationsOnDerivedTypeCastSegments = true
            };

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(3, paths.Count());
        }
コード例 #13
0
        public void GetPathsForInheritanceModelWithDerivedTypesConstraintNoAnnotationReturnsFewer()
        {
            // Arrange
            IEdmModel         model    = GetInheritanceModel(string.Empty);
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings
            {
                RequireDerivedTypesConstraintForBoundOperations = true
            };

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(2, paths.Count());
        }
コード例 #14
0
        public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
        {
            // Arrange
            IEdmModel         model    = EdmModelHelper.GraphBetaModel;
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings
            {
                RequireDerivedTypesConstraintForBoundOperations = true
            };

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(4544, paths.Count());
        }
コード例 #15
0
        public void GetPathsWithReferenceableNavigationPropertyWorks()
        {
            // Arrange
            string entityType =
                @"<EntityType Name=""Order"">
    <Key>
      <PropertyRef Name=""id"" />
    </Key>
    <NavigationProperty Name=""MultipleCustomers"" Type=""Collection(NS.Customer)"">
        <Annotation Term=""Org.OData.Capabilities.V1.NavigationRestrictions"">
          <Record>
            <PropertyValue Property=""Referenceable"" Bool=""true"" />
          </Record>
        </Annotation>
     </NavigationProperty>
    <NavigationProperty Name=""SingleCustomer"" Type=""NS.Customer"">
        <Annotation Term=""Org.OData.Capabilities.V1.NavigationRestrictions"">
          <Record>
            <PropertyValue Property=""Referenceable"" Bool=""true"" />
          </Record> 
        </Annotation>
     </NavigationProperty>
  </EntityType>";

            string    entitySet = @"<EntitySet Name=""Orders"" EntityType=""NS.Order"" />";
            IEdmModel model     = GetEdmModel(entityType, entitySet);

            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

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

            var pathItems = paths.Select(p => p.GetPathItemName()).ToList();

            Assert.Contains("/Orders({id})/MultipleCustomers", pathItems);
            Assert.Contains("/Orders({id})/SingleCustomer", pathItems);
            Assert.Contains("/Orders({id})/SingleCustomer/$ref", pathItems);
            Assert.Contains("/Orders({id})/MultipleCustomers/$ref", pathItems);
            Assert.Contains("/Orders({id})/MultipleCustomers({ID})/$ref", pathItems);
        }
コード例 #16
0
        public void GetPathsWithStreamPropertyAndWithEntityHasStreamWorks(bool hasStream, string streamPropName)
        {
            // Arrange
            IEdmModel         model       = GetEdmModel(hasStream, streamPropName);
            ODataPathProvider provider    = new ODataPathProvider();
            var          settings         = new OpenApiConvertSettings();
            const string TodosContentPath = "/todos({id})/content";
            const string TodosValuePath   = "/todos({id})/$value";
            const string TodosLogoPath    = "/todos({id})/logo";

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Contains("/catalog/content", paths.Select(p => p.GetPathItemName()));
            Assert.Contains("/catalog/thumbnailPhoto", paths.Select(p => p.GetPathItemName()));
            Assert.Contains("/me/photo/$value", paths.Select(p => p.GetPathItemName()));

            if (streamPropName.Equals("logo"))
            {
                if (hasStream)
                {
                    Assert.Equal(14, paths.Count());
                    Assert.Contains(TodosValuePath, paths.Select(p => p.GetPathItemName()));
                    Assert.Contains(TodosLogoPath, paths.Select(p => p.GetPathItemName()));
                    Assert.DoesNotContain(TodosContentPath, paths.Select(p => p.GetPathItemName()));
                }
                else
                {
                    Assert.Equal(13, paths.Count());
                    Assert.Contains(TodosLogoPath, paths.Select(p => p.GetPathItemName()));
                    Assert.DoesNotContain(TodosContentPath, paths.Select(p => p.GetPathItemName()));
                    Assert.DoesNotContain(TodosValuePath, paths.Select(p => p.GetPathItemName()));
                }
            }
            else if (streamPropName.Equals("content"))
            {
                Assert.Equal(13, paths.Count());
                Assert.Contains(TodosContentPath, paths.Select(p => p.GetPathItemName()));
                Assert.DoesNotContain(TodosLogoPath, paths.Select(p => p.GetPathItemName()));
                Assert.DoesNotContain(TodosValuePath, paths.Select(p => p.GetPathItemName()));
            }
        }
コード例 #17
0
        public void GetPathsWithBoundFunctionOperationWorks()
        {
            // Arrange
            string boundFunction =
                @"<Function Name=""delta"" IsBound=""true"">
   <Parameter Name=""bindingParameter"" Type=""Collection(NS.Customer)"" />
     <ReturnType Type=""Collection(NS.Customer)"" />
</Function>";
            IEdmModel         model    = GetEdmModel(boundFunction, "");
            ODataPathProvider provider = new ODataPathProvider();

            // Act
            var paths = provider.GetPaths(model);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(3, paths.Count());
            Assert.Contains("/Customers/NS.delta()", paths.Select(p => p.GetPathItemName()));
        }
コード例 #18
0
        public void GetPathsForGraphBetaModelWithDerivedTypesConstraintReturnsAllPaths()
        {
            // Arrange
            IEdmModel         model    = EdmModelHelper.GraphBetaModel;
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings
            {
                RequireDerivedTypesConstraintForBoundOperations = true,
                ExpandDerivedTypesNavigationProperties          = false,
                AppendBoundOperationsOnDerivedTypeCastSegments  = true
            };

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(15293, paths.Count());
        }
コード例 #19
0
        public void GetPathsWithBoundActionOperationWorks()
        {
            // Arrange
            string boundAction =
                @"<Action Name=""renew"" IsBound=""true"">
   <Parameter Name=""bindingParameter"" Type=""NS.Customer"" />
     <ReturnType Type=""Edm.Boolean"" />
</Action>";
            IEdmModel         model    = GetEdmModel(boundAction, "");
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings();

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.NotNull(paths);
            Assert.Equal(3, paths.Count());
            Assert.Contains("/Customers({ID})/NS.renew", paths.Select(p => p.GetPathItemName()));
        }
コード例 #20
0
        public void GetPathsForInheritanceModelWithDerivedTypesConstraintWithAnnotationReturnsMore()
        {
            // Arrange
            IEdmModel         model    = GetInheritanceModel(@"
<Annotation Term=""Org.OData.Validation.V1.DerivedTypeConstraint"">
<Collection>
  <String>NS.Customer</String>
  <String>NS.NiceCustomer</String>
</Collection>
</Annotation>");
            ODataPathProvider provider = new ODataPathProvider();
            var settings = new OpenApiConvertSettings
            {
                RequireDerivedTypesConstraintForBoundOperations = true
            };

            // Act
            var paths = provider.GetPaths(model, settings);

            // Assert
            Assert.Equal(3, paths.Count());
        }