This commit is contained in:
Sam Xu 2019-06-25 13:04:59 -07:00
parent 08ded1e66d
commit f6470b0df7
16 changed files with 125 additions and 43 deletions

View file

@ -6,7 +6,6 @@
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem

View file

@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// The Enum kind for Capabiliites annotation

View file

@ -70,7 +70,7 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
/// </summary>
public bool? Deletable { get; private set; }
public void Initialize(IEdmRecordExpression record)
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));

View file

@ -3,10 +3,8 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
@ -62,6 +60,10 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
false;
}
/// <summary>
/// Init the <see cref="CountRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
@ -75,10 +77,5 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
// NonCountableNavigationProperties
NonCountableNavigationProperties = record.GetCollectionPropertyPath("NonCountableNavigationProperties");
}
internal bool GetRecord<T>(IEdmEntitySet calendars)
{
throw new NotImplementedException();
}
}
}

View file

@ -4,7 +4,6 @@
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
@ -20,13 +19,11 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core
public string ExternalValue { get; set; }
/// <summary>
/// Init the <see cref="ComplexExampleValue"/>
/// Init the <see cref="ExternalExampleValue"/>
/// </summary>
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Load ExampleValue
base.Initialize(record);

View file

@ -5,7 +5,6 @@
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
@ -25,8 +24,6 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Load ExampleValue
base.Initialize(record);

View file

@ -5,7 +5,6 @@
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
@ -20,13 +19,11 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Core
public ODataResourceValue Value { get; private set; }
/// <summary>
/// Init the <see cref="EntityExampleValue"/>
/// Init the <see cref="ResourceExampleValue"/>
/// </summary>
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Load ExampleValue
base.Initialize(record);

View file

@ -9,7 +9,6 @@ using System.Xml.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
using Xunit;

View file

@ -62,16 +62,15 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.1.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.OpenApi.OData.Reader\Microsoft.OpenApi.OData.Reader.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Vocabulary\Core\" />
</ItemGroup>
</Project>

View file

@ -6,7 +6,6 @@
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Capabilities;
using Xunit;
namespace Microsoft.OpenApi.OData.Reader.Capabilities.Tests

View file

@ -5,7 +5,6 @@
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OpenApi.OData.Capabilities;
using Xunit;
namespace Microsoft.OpenApi.OData.Reader.Capabilities.Tests

View file

@ -6,7 +6,6 @@
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
using Xunit;

View file

@ -6,7 +6,6 @@
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OpenApi.OData.Capabilities;
using Xunit;
namespace Microsoft.OpenApi.OData.Reader.Capabilities.Tests

View file

@ -14,16 +14,6 @@ namespace Microsoft.OpenApi.OData.Reader.Vocabulary.Capabilities.Tests
{
public class SortRestrictionsTypeTests
{
[Fact]
public void KindPropertyReturnsSortRestrictionsEnumMember()
{
// Arrange & Act
SortRestrictionsType sort = new SortRestrictionsType();
// Assert
// Assert.Equal(CapabilitesTermKind.SortRestrictions, sort.Kind);
}
[Fact]
public void UnknownAnnotatableTargetReturnsDefaultSortRestrictionsValues()
{

View file

@ -6,7 +6,6 @@
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OpenApi.OData.Capabilities;
using Xunit;
namespace Microsoft.OpenApi.OData.Reader.Capabilities.Tests

View file

@ -0,0 +1,112 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Linq;
using System.Xml.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Core;
using Xunit;
namespace Microsoft.OpenApi.OData.Reader.Vocabulary.Core.Tests
{
public class PrimitiveExampleValueTests
{
[Fact]
public void DefaultPropertyAsNull()
{
// Arrange
PrimitiveExampleValue value = new PrimitiveExampleValue();
// Act & Assert
Assert.Null(value.Description);
Assert.Null(value.Value);
}
[Fact]
public void InitializeWithNullThrows()
{
// Arrange & Act
PrimitiveExampleValue value = new PrimitiveExampleValue();
// Assert
Assert.Throws<ArgumentNullException>("record", () => value.Initialize(record: null));
}
[Fact]
public void InitializeWithNullThrows1()
{
// Arrange & Act
PrimitiveExampleValue value = new PrimitiveExampleValue();
IEdmRecordExpression record = new EdmRecordExpression();
// Assert
// Assert.Throws<ArgumentNullException>("record", () => value.Initialize(record: null));
}
[Theory]
[InlineData(@"String""=""Hello World""")]
public void TargetOnEntityTypeReturnsCorrectTopSupportedValue1(string data)
{
// Arrange
string annotation = $@"<Annotation Term=""Org.OData.Core.V1.Example"">
<Record Type=""Org.OData.Core.V1.PrimitiveExampleValue"">
<PropertyValue Property=""Description"" String=""Primitive example value"" />
<PropertyValue Property=""Value"" {data} />
</Record>";
IEdmModel model = GetEdmModel(annotation);
Assert.NotNull(model); // guard
IEdmEntityType customer = model.SchemaElements.OfType<IEdmEntityType>().First(c => c.Name == "Customer");
Assert.NotNull(customer); // guard
IEdmProperty dataProperty = customer.FindProperty("Data");
Assert.NotNull(dataProperty);
// Act
PrimitiveExampleValue value = model.GetRecord<PrimitiveExampleValue>(dataProperty, "Org.OData.Core.V1.Example");
// Assert
Assert.NotNull(value);
Assert.Equal("Primitive example value", value.Description);
Assert.NotNull(value.Value);
}
private IEdmModel GetEdmModel(string annotation)
{
const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
<edmx:DataServices>
<Schema Namespace=""NS"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EntityType Name=""Customer"">
<Key>
<PropertyRef Name=""ID"" />
</Key>
<Property Name=""ID"" Type=""Edm.Int32"" Nullable=""false"" />
<Property Name=""Data"" Type=""Edm.PrimitiveType"" Nullable=""false"" >
{0}
</Property>
</EntityType>
<EntityContainer Name =""Default"">
<Singleton Name=""Me"" Type=""NS.Customer"" />
</EntityContainer>
<Annotations Target=""NS.Customer/ID"">
{0}
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>";
string modelText = string.Format(template, annotation);
IEdmModel model;
bool result = CsdlReader.TryParse(XElement.Parse(modelText).CreateReader(), out model, out _);
Assert.True(result);
return model;
}
}
}