|
| 1 | +// ------------------------------------------------------------ |
| 2 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. |
| 4 | +// ------------------------------------------------------------ |
| 5 | + |
| 6 | +using System; |
| 7 | +using Microsoft.OData.Edm; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.OpenApi.OData.Edm.Tests; |
| 11 | +public class ODataComplexPropertySegmentTests |
| 12 | +{ |
| 13 | + private readonly EdmEntityType _person; |
| 14 | + private readonly EdmStructuralProperty _addressProperty; |
| 15 | + private readonly EdmComplexType _addressComplexType; |
| 16 | + |
| 17 | + public ODataComplexPropertySegmentTests() |
| 18 | + { |
| 19 | + _person = new EdmEntityType("NS", "Person"); |
| 20 | + _addressComplexType = new EdmComplexType("NS", "Address"); |
| 21 | + _addressComplexType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(false)); |
| 22 | + _person.AddKeys(_person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(false))); |
| 23 | + _addressProperty = _person.AddStructuralProperty("HomeAddress", new EdmComplexTypeReference(_addressComplexType, false)); |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void TypeCastSegmentConstructorThrowsArgumentNull() |
| 28 | + { |
| 29 | + Assert.Throws<ArgumentNullException>("property", () => new ODataComplexPropertySegment(null)); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void ComplexTypeReturnsPropertyComplexType() |
| 34 | + { |
| 35 | + // Arrange & Act |
| 36 | + var segment = new ODataComplexPropertySegment(_addressProperty); |
| 37 | + |
| 38 | + // Assert |
| 39 | + Assert.Throws<NotImplementedException>(() => segment.EntityType); |
| 40 | + Assert.Same(_addressComplexType, segment.ComplexType); |
| 41 | + } |
| 42 | + |
| 43 | + [Fact] |
| 44 | + public void KindPropertyReturnsComplexPropertyEnumMember() |
| 45 | + { |
| 46 | + // Arrange & Act |
| 47 | + var segment = new ODataComplexPropertySegment(_addressProperty); |
| 48 | + |
| 49 | + // Assert |
| 50 | + Assert.Equal(ODataSegmentKind.ComplexProperty, segment.Kind); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void GetPathItemNameReturnsCorrectPropertyName() |
| 55 | + { |
| 56 | + // Arrange & Act |
| 57 | + var segment = new ODataComplexPropertySegment(_addressProperty); |
| 58 | + |
| 59 | + // Assert |
| 60 | + Assert.Equal("HomeAddress", segment.GetPathItemName(new OpenApiConvertSettings())); |
| 61 | + } |
| 62 | +} |
0 commit comments