|
4 | 4 | // ------------------------------------------------------------ |
5 | 5 |
|
6 | 6 | using System; |
| 7 | +using System.Runtime.CompilerServices; |
7 | 8 | using Microsoft.OData.Edm; |
| 9 | +using Microsoft.OData.Edm.Csdl; |
8 | 10 | using Xunit; |
9 | 11 |
|
10 | 12 | namespace Microsoft.OpenApi.OData.Edm.Tests |
@@ -73,26 +75,51 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo |
73 | 75 | } |
74 | 76 |
|
75 | 77 | [Theory] |
76 | | - [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null, "NS.XY")] |
77 | | - [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null, "NS.XY")] |
78 | | - [InlineData(false, true, "NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY")] |
79 | | - [InlineData(false, true, "MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY")] |
80 | | - [InlineData(false, false, "NS.XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS", "NS.XY")] |
81 | | - [InlineData(false, false, "MyFunction(entity={entity},param={param},param2=@param2)", "NS.XY", "NS.XY")] |
82 | | - public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip, string namespaceName) |
| 78 | + [InlineData(true, true, "MyFunction(param={param},param2=@param2)")] |
| 79 | + [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)")] |
| 80 | + [InlineData(false, true, "NS.MyFunction(param={param},param2=@param2)")] |
| 81 | + [InlineData(false, false, "NS.MyFunction(entity={entity},param={param},param2=@param2)")] |
| 82 | + public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected) |
83 | 83 | { |
84 | 84 | // Arrange & Act |
85 | | - IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS.XY", "Entity"), false); |
| 85 | + IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), false); |
86 | 86 | IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); |
87 | | - EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: namespaceName); |
| 87 | + EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: "NS"); |
88 | 88 | boundFunction.AddParameter("param", parameterType); |
89 | 89 | boundFunction.AddOptionalParameter("param2", parameterType); |
90 | 90 |
|
91 | | - var segment = new ODataOperationSegment(boundFunction, EdmCoreModel.Instance); |
| 91 | + var segment = new ODataOperationSegment(boundFunction); |
92 | 92 | OpenApiConvertSettings settings = new OpenApiConvertSettings |
93 | 93 | { |
94 | | - EnableUnqualifiedCall = unqualifiedCall, |
| 94 | + EnableUnqualifiedCall = unqualifiedCall |
| 95 | + }; |
| 96 | + |
| 97 | + // Assert |
| 98 | + Assert.Equal(expected, segment.GetPathItemName(settings)); |
| 99 | + } |
| 100 | + |
| 101 | + [Theory] |
| 102 | + [InlineData("NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", false)] |
| 103 | + [InlineData("MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", false)] |
| 104 | + [InlineData("N.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", true)] |
| 105 | + [InlineData("N.MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", true)] |
| 106 | + public void GetPathItemNameReturnsCorrectFunctionLiteralWhenSegmentAliasedOrNamespacePrefixStripped(string expected, string namespacePrefixToStrip, string namespaceName, bool enableAlias) |
| 107 | + { |
| 108 | + // Arrange & Act |
| 109 | + IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType(namespaceName, "Entity"), false); |
| 110 | + IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); |
| 111 | + EdmFunction boundFunction = BoundFunction("MyFunction", true, entityTypeReference, namespaceIdentifier: namespaceName); |
| 112 | + boundFunction.AddParameter("param", parameterType); |
| 113 | + boundFunction.AddOptionalParameter("param2", parameterType); |
| 114 | + EdmModel model = new(); |
| 115 | + model.AddElement(boundFunction); |
| 116 | + model.SetNamespaceAlias(namespaceName, "N"); |
| 117 | + |
| 118 | + var segment = new ODataOperationSegment(boundFunction, model); |
| 119 | + OpenApiConvertSettings settings = new() |
| 120 | + { |
95 | 121 | NamespacePrefixToStripForInMethodPaths = namespacePrefixToStrip, |
| 122 | + EnableAliasForOperationSegments = enableAlias |
96 | 123 | }; |
97 | 124 |
|
98 | 125 | // Assert |
|
0 commit comments