|
1 |
| -// ------------------------------------------------------------ |
| 1 | +// ------------------------------------------------------------ |
2 | 2 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
3 | 3 | // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
4 | 4 | // ------------------------------------------------------------
|
@@ -299,6 +299,99 @@ public void CreateOperationForOverloadEdmFunctionReturnsCorrectOperationId(bool
|
299 | 299 | }
|
300 | 300 | }
|
301 | 301 |
|
| 302 | + [Theory] |
| 303 | + [InlineData(true)] |
| 304 | + [InlineData(false)] |
| 305 | + public void CreateOperationForComposableOverloadEdmFunctionReturnsCorrectOperationId(bool enableOperationId) |
| 306 | + { |
| 307 | + // Arrange |
| 308 | + EdmModel model = new(); |
| 309 | + EdmEntityType customer = new("NS", "Customer"); |
| 310 | + customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); |
| 311 | + model.AddElement(customer); |
| 312 | + |
| 313 | + // Overloaded function 1 |
| 314 | + EdmFunction function1 = new("NS", "MyFunction1", EdmCoreModel.Instance.GetString(false), true, null, false); |
| 315 | + function1.AddParameter("entity", new EdmEntityTypeReference(customer, false)); |
| 316 | + model.AddElement(function1); |
| 317 | + |
| 318 | + // Overloaded function 1 |
| 319 | + EdmFunction function2 = new("NS", "MyFunction1", EdmCoreModel.Instance.GetString(false), true, null, false); |
| 320 | + function2.AddParameter("entity", new EdmEntityTypeReference(customer, false)); |
| 321 | + function2.AddParameter("param", EdmCoreModel.Instance.GetString(false)); |
| 322 | + |
| 323 | + model.AddElement(function2); |
| 324 | + |
| 325 | + // Overloaded function 2 |
| 326 | + EdmFunction function3 = new("NS", "MyFunction2", EdmCoreModel.Instance.GetString(false), true, null, false); |
| 327 | + function3.AddParameter("entity2", new EdmEntityTypeReference(customer, false)); |
| 328 | + model.AddElement(function3); |
| 329 | + |
| 330 | + // Overloaded function 2 |
| 331 | + EdmFunction function4 = new("NS", "MyFunction2", EdmCoreModel.Instance.GetString(false), true, null, false); |
| 332 | + function4.AddParameter("entity2", new EdmEntityTypeReference(customer, false)); |
| 333 | + function4.AddParameter("param", EdmCoreModel.Instance.GetString(false)); |
| 334 | + model.AddElement(function4); |
| 335 | + |
| 336 | + EdmEntityContainer container = new("NS", "Default"); |
| 337 | + EdmEntitySet customers = new(container, "Customers", customer); |
| 338 | + model.AddElement(container); |
| 339 | + |
| 340 | + OpenApiConvertSettings settings = new OpenApiConvertSettings |
| 341 | + { |
| 342 | + EnableOperationId = enableOperationId, |
| 343 | + AddSingleQuotesForStringParameters = true, |
| 344 | + }; |
| 345 | + ODataContext context = new(model, settings); |
| 346 | + |
| 347 | + ODataPath path1 = new(new ODataNavigationSourceSegment(customers), |
| 348 | + new ODataKeySegment(customer), |
| 349 | + new ODataOperationSegment(function1), |
| 350 | + new ODataOperationSegment(function3)); |
| 351 | + |
| 352 | + ODataPath path2 = new(new ODataNavigationSourceSegment(customers), |
| 353 | + new ODataKeySegment(customer), |
| 354 | + new ODataOperationSegment(function1), |
| 355 | + new ODataOperationSegment(function4)); |
| 356 | + |
| 357 | + ODataPath path3 = new(new ODataNavigationSourceSegment(customers), |
| 358 | + new ODataKeySegment(customer), |
| 359 | + new ODataOperationSegment(function2), |
| 360 | + new ODataOperationSegment(function3)); |
| 361 | + |
| 362 | + ODataPath path4 = new(new ODataNavigationSourceSegment(customers), |
| 363 | + new ODataKeySegment(customer), |
| 364 | + new ODataOperationSegment(function2), |
| 365 | + new ODataOperationSegment(function4)); |
| 366 | + |
| 367 | + // Act |
| 368 | + var operation1 = _operationHandler.CreateOperation(context, path1); |
| 369 | + var operation2 = _operationHandler.CreateOperation(context, path2); |
| 370 | + var operation3 = _operationHandler.CreateOperation(context, path3); |
| 371 | + var operation4 = _operationHandler.CreateOperation(context, path4); |
| 372 | + |
| 373 | + // Assert |
| 374 | + Assert.NotNull(operation1); |
| 375 | + Assert.NotNull(operation2); |
| 376 | + Assert.NotNull(operation3); |
| 377 | + Assert.NotNull(operation4); |
| 378 | + |
| 379 | + if (enableOperationId) |
| 380 | + { |
| 381 | + Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-c53d", operation1.OperationId); |
| 382 | + Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-4d93", operation2.OperationId); |
| 383 | + Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-a2b2", operation3.OperationId); |
| 384 | + Assert.Equal("Customers.Customer.MyFunction1.MyFunction2-7bea", operation4.OperationId); |
| 385 | + } |
| 386 | + else |
| 387 | + { |
| 388 | + Assert.Null(operation1.OperationId); |
| 389 | + Assert.Null(operation2.OperationId); |
| 390 | + Assert.Null(operation3.OperationId); |
| 391 | + Assert.Null(operation4.OperationId); |
| 392 | + } |
| 393 | + } |
| 394 | + |
302 | 395 | [Theory]
|
303 | 396 | [InlineData(true)]
|
304 | 397 | [InlineData(false)]
|
|
0 commit comments