OpenAPI.NET.OData/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/RefDeleteOperationHandlerTests.cs
Irvine Sunday b1fed423ab
Describes path operations descriptions from vocabulary annotations (#104)
* Add support for operation descriptions and update tests

* Update tests for Entityset paths operations descriptions

* Code cleanup

* Update test OpenAPI output files.

Co-authored-by: Irvine Sunday <irochand@microsoft.com>
2021-05-04 17:36:03 -07:00

70 lines
2.7 KiB
C#

// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Tests;
using Xunit;
namespace Microsoft.OpenApi.OData.Operation.Tests
{
public class RefDeleteOperationHandlerTests
{
private RefDeleteOperationHandler _operationHandler = new RefDeleteOperationHandler();
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CreateNavigationRefDeleteOperationReturnsCorrectOperation(bool enableOperationId)
{
// Arrange
IEdmModel model = EdmModelHelper.TripServiceModel;
OpenApiConvertSettings settings = new OpenApiConvertSettings
{
EnableOperationId = enableOperationId
};
ODataContext context = new ODataContext(model, settings);
IEdmEntitySet people = model.EntityContainer.FindEntitySet("People");
Assert.NotNull(people);
IEdmEntityType person = model.SchemaElements.OfType<IEdmEntityType>().First(c => c.Name == "Person");
IEdmNavigationProperty navProperty = person.DeclaredNavigationProperties().First(c => c.Name == "Trips");
ODataPath path = new ODataPath(new ODataNavigationSourceSegment(people),
new ODataKeySegment(people.EntityType()),
new ODataNavigationPropertySegment(navProperty),
ODataRefSegment.Instance);
// Act
var operation = _operationHandler.CreateOperation(context, path);
// Assert
Assert.NotNull(operation);
Assert.Equal("Delete ref of navigation property Trips for People", operation.Summary);
Assert.Equal("Collection of trips.", operation.Description);
Assert.NotNull(operation.Tags);
var tag = Assert.Single(operation.Tags);
Assert.Equal("People.Trip", tag.Name);
Assert.NotNull(operation.Parameters);
Assert.NotEmpty(operation.Parameters);
Assert.Null(operation.RequestBody);
Assert.Equal(2, operation.Responses.Count);
Assert.Equal(new string[] { "204", "default" }, operation.Responses.Select(e => e.Key));
if (enableOperationId)
{
Assert.Equal("People.DeleteRefTrips", operation.OperationId);
}
else
{
Assert.Null(operation.OperationId);
}
}
}
}