50 lines
2.1 KiB
C#
50 lines
2.1 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 NavigationPropertyGetOperationHandlerTests
|
|
{
|
|
private NavigationPropertyGetOperationHandler _operationHandler = new NavigationPropertyGetOperationHandler();
|
|
|
|
[Fact]
|
|
public void CreateNavigationGetOperationReturnsCorrectOperation()
|
|
{
|
|
// Arrange
|
|
IEdmModel model = EdmModelHelper.TripServiceModel;
|
|
ODataContext context = new ODataContext(model);
|
|
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));
|
|
|
|
// Act
|
|
var operation = _operationHandler.CreateOperation(context, path);
|
|
|
|
// Assert
|
|
Assert.NotNull(operation);
|
|
Assert.Equal("Get Trips from People", operation.Summary);
|
|
Assert.NotNull(operation.Tags);
|
|
var tag = Assert.Single(operation.Tags);
|
|
Assert.Equal("People.Trip", tag.Name);
|
|
|
|
Assert.NotNull(operation.Parameters);
|
|
Assert.Equal(9, operation.Parameters.Count);
|
|
|
|
Assert.Null(operation.RequestBody);
|
|
|
|
Assert.Equal(2, operation.Responses.Count);
|
|
Assert.Equal(new string[] { "200", "default" }, operation.Responses.Select(e => e.Key));
|
|
}
|
|
}
|
|
}
|