Skip to content

Commit 0034f98

Browse files
committed
- adds unit test for set deprecation and get deprecation information
Signed-off-by: Vincent Biret <[email protected]>
1 parent ea7dd94 commit 0034f98

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,58 @@ namespace Microsoft.OpenApi.OData.Operation.Tests
1616
{
1717
public class EdmFunctionOperationHandlerTests
1818
{
19-
private EdmFunctionOperationHandler _operationHandler = new EdmFunctionOperationHandler();
19+
private EdmFunctionOperationHandler _operationHandler = new();
20+
#region OperationHandlerTests
21+
[Fact]
22+
public void SetsDeprecationInformation()
23+
{
24+
// Arrange
25+
IEdmModel model = EdmModelHelper.TripServiceModel;
26+
ODataContext context = new(model);
27+
IEdmEntitySet people = model.EntityContainer.FindEntitySet("People");
28+
Assert.NotNull(people);
29+
30+
IEdmFunction function = model.SchemaElements.OfType<IEdmFunction>().First(f => f.Name == "GetFriendsTrips");
31+
Assert.NotNull(function);
32+
33+
ODataPath path = new(new ODataNavigationSourceSegment(people), new ODataKeySegment(people.EntityType()), new ODataOperationSegment(function));
34+
35+
// Act
36+
var operation = _operationHandler.CreateOperation(context, path);
37+
38+
// Assert
39+
Assert.NotNull(operation);
40+
Assert.True(operation.Deprecated);
41+
Assert.NotEmpty(operation.Extensions);
42+
var extension = operation.Extensions["x-ms-deprecation"];
43+
Assert.NotNull(extension);
44+
}
45+
[Fact]
46+
public void DoesntSetDeprecationInformation()
47+
{
48+
// Arrange
49+
IEdmModel model = EdmModelHelper.TripServiceModel;
50+
ODataContext context = new(model);
51+
IEdmEntitySet people = model.EntityContainer.FindEntitySet("People");
52+
Assert.NotNull(people);
53+
54+
IEdmFunction function = model.SchemaElements.OfType<IEdmFunction>().First(f => f.Name == "GetFavoriteAirline");
55+
Assert.NotNull(function);
56+
57+
ODataPath path = new(new ODataNavigationSourceSegment(people), new ODataKeySegment(people.EntityType()), new ODataOperationSegment(function));
58+
59+
// Act
60+
var operation = _operationHandler.CreateOperation(context, path);
61+
62+
// Assert
63+
Assert.NotNull(operation);
64+
Assert.True(operation.Deprecated);
65+
Assert.NotEmpty(operation.Extensions);
66+
var extension = operation.Extensions["x-ms-deprecation"];
67+
Assert.NotNull(extension);
68+
}
69+
70+
#endregion
2071

2172
[Fact]
2273
public void CreateOperationForEdmFunctionReturnsCorrectOperation()

0 commit comments

Comments
 (0)