Skip to content

Commit 531cdaa

Browse files
committed
- adds unit test for complex property segment
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent da21d61 commit 531cdaa

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataComplexPropertySegment.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public ODataComplexPropertySegment(IEdmStructuralProperty property)
2020
Property = property ?? throw Error.ArgumentNull(nameof(property));
2121
}
2222

23-
/// <inheritdoc />
24-
25-
public override IEdmEntityType EntityType => null;
2623
/// <inheritdoc />
2724
public override ODataSegmentKind Kind => ODataSegmentKind.ComplexProperty;
2825

src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.ODataTypeCastSegment(Microsoft.
9595
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment
9696
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ODataComplexPropertySegment(Microsoft.OData.Edm.IEdmStructuralProperty property) -> void
9797
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Property.get -> Microsoft.OData.Edm.IEdmStructuralProperty
98-
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
9998
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
10099
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Identifier.get -> string
101100
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ComplexType.get -> Microsoft.OData.Edm.IEdmComplexType
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataTypeCastSegmentTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ namespace Microsoft.OpenApi.OData.Edm.Tests
1111
{
1212
public class ODataTypeCastSegmentTests
1313
{
14-
private IEdmEntityType _person { get; }
14+
private readonly EdmEntityType _person;
1515

1616
public ODataTypeCastSegmentTests()
1717
{
18-
var person = new EdmEntityType("NS", "Person");
19-
person.AddKeys(person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(false)));
20-
_person = person;
18+
_person = new EdmEntityType("NS", "Person");
19+
_person.AddKeys(_person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(false)));
2120
}
2221

2322
[Fact]

0 commit comments

Comments
 (0)