Skip to content

Commit f222ad6

Browse files
committed
Update operation segment tests
1 parent e9fc9f1 commit f222ad6

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// ------------------------------------------------------------
55

66
using System;
7+
using System.Runtime.CompilerServices;
78
using Microsoft.OData.Edm;
9+
using Microsoft.OData.Edm.Csdl;
810
using Xunit;
911

1012
namespace Microsoft.OpenApi.OData.Edm.Tests
@@ -73,26 +75,51 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo
7375
}
7476

7577
[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)
8383
{
8484
// Arrange & Act
85-
IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS.XY", "Entity"), false);
85+
IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), false);
8686
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");
8888
boundFunction.AddParameter("param", parameterType);
8989
boundFunction.AddOptionalParameter("param2", parameterType);
9090

91-
var segment = new ODataOperationSegment(boundFunction, EdmCoreModel.Instance);
91+
var segment = new ODataOperationSegment(boundFunction);
9292
OpenApiConvertSettings settings = new OpenApiConvertSettings
9393
{
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+
{
95121
NamespacePrefixToStripForInMethodPaths = namespacePrefixToStrip,
122+
EnableAliasForOperationSegments = enableAlias
96123
};
97124

98125
// Assert

0 commit comments

Comments
 (0)