-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotation term for OData.Community.UrlEscape.V1.UrlEscapeFuncti…
…on. (#1307) * Add annotation term for OData.Community.UrlEscape.V1.UrlEscapeFunction. - Move the UrlEscapeFuntion into new Community vocabularies; AlternateKeys will be moved later. * Update per CR comments. * CR updates from Mike's comments.
- Loading branch information
1 parent
b739e24
commit 469f209
Showing
10 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Microsoft.OData.Edm/Vocabularies/CommunityVocabularies.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0"> | ||
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml"> | ||
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1" /> | ||
</edmx:Reference> | ||
<edmx:DataServices> | ||
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Org.OData.Community.V1" Alias="Community"> | ||
<Term AppliesTo="Function" Type="Core.Tag" Name="UrlEscapeFunction"> | ||
<Annotation Term="Core.Description" String="Annotates a function to be substituted for a colon-escaped segment in a Url path"/> | ||
</Term> | ||
</Schema> | ||
</edmx:DataServices> | ||
</edmx:Edmx> |
17 changes: 17 additions & 0 deletions
17
src/Microsoft.OData.Edm/Vocabularies/CommunityVocabularyConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="CommunityVocabularyConstants.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
namespace Microsoft.OData.Edm.Vocabularies.Community.V1 | ||
{ | ||
/// <summary> | ||
/// Constant values for Community Vocabularies | ||
/// </summary> | ||
internal static class CommunityVocabularyConstants | ||
{ | ||
/// <summary>OData.Community.V1.UrlEscapeFunction </summary> | ||
internal const string UrlEscapeFunction = "Org.OData.Community.V1.UrlEscapeFunction"; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Microsoft.OData.Edm/Vocabularies/CommunityVocabularyModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="CommunityVocabularyModel.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml; | ||
using Microsoft.OData.Edm.Csdl; | ||
using Microsoft.OData.Edm.Validation; | ||
|
||
namespace Microsoft.OData.Edm.Vocabularies.Community.V1 | ||
{ | ||
/// <summary> | ||
/// Representing Community Vocabulary Model. | ||
/// </summary> | ||
public static class CommunityVocabularyModel | ||
{ | ||
/// <summary> | ||
/// The EDM model with Community vocabularies. | ||
/// </summary> | ||
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmModel is immutable")] | ||
public static readonly IEdmModel Instance = CommunityVocabularyReader.GetEdmModel(); | ||
|
||
/// <summary> | ||
/// The Url escape function term. | ||
/// </summary> | ||
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmTerm is immutable")] | ||
public static readonly IEdmTerm UrlEscapeFunctionTerm = Instance.FindDeclaredTerm(CommunityVocabularyConstants.UrlEscapeFunction); | ||
} | ||
|
||
internal static class CommunityVocabularyReader | ||
{ | ||
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmModel is immutable")] | ||
|
||
internal static IEdmModel GetEdmModel() | ||
{ | ||
Assembly assembly = typeof(CommunityVocabularyModel).GetAssembly(); | ||
|
||
// Resource name has leading namespace and folder in .NetStandard dll. | ||
string[] allResources = assembly.GetManifestResourceNames(); | ||
string communityVocabularies = allResources.Where(x => x.Contains("CommunityVocabularies.xml")).FirstOrDefault(); | ||
Debug.Assert(communityVocabularies != null, "CommunityVocabularies.xml: not found."); | ||
|
||
IEdmModel instance; | ||
using (Stream stream = assembly.GetManifestResourceStream(communityVocabularies)) | ||
{ | ||
IEnumerable<EdmError> errors; | ||
Debug.Assert(stream != null, "CommunityVocabularies.xml: stream!=null"); | ||
CsdlReader.TryParse(XmlReader.Create(stream), out instance, out errors); | ||
} | ||
|
||
return instance; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/FunctionalTests/Microsoft.OData.Edm.Tests/Vocabularies/CommunityVocabularyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//--------------------------------------------------------------------- | ||
// <copyright file="CommunityVocabularyTests.cs" company="Microsoft"> | ||
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
// </copyright> | ||
//--------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml; | ||
using System.Text; | ||
using Microsoft.OData.Edm.Csdl; | ||
using Microsoft.OData.Edm.Validation; | ||
using Microsoft.OData.Edm.Vocabularies; | ||
using Microsoft.OData.Edm.Vocabularies.Community.V1; | ||
using Xunit; | ||
|
||
namespace Microsoft.OData.Edm.Tests.Vocabularies | ||
{ | ||
public class CommunityVocabularyTests | ||
{ | ||
private readonly IEdmModel model = CommunityVocabularyModel.Instance; | ||
|
||
[Fact] | ||
public void TestCommunityVocabularyModel() | ||
{ | ||
const string expectedUrlEscape = @"<?xml version=""1.0"" encoding=""utf-16""?> | ||
<Schema Namespace=""Org.OData.Community.V1"" Alias=""Community"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> | ||
<Term Name=""UrlEscapeFunction"" Type=""Core.Tag"" AppliesTo=""Function""> | ||
<Annotation Term=""Core.Description"" String=""Annotates a function to be substituted for a colon-escaped segment in a Url path"" /> | ||
</Term> | ||
</Schema>"; | ||
|
||
StringWriter sw = new StringWriter(); | ||
IEnumerable<EdmError> errors; | ||
using (var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 })) | ||
{ | ||
Assert.True(model.TryWriteSchema(xw, out errors)); | ||
} | ||
|
||
|
||
Assert.False(errors.Any(), "No Errors"); | ||
|
||
string output = sw.ToString(); | ||
Assert.True(expectedUrlEscape == output, "expected Community schema not matching"); | ||
} | ||
|
||
[Fact] | ||
public void TestUrlEscapeFunctionAnnotationTerm() | ||
{ | ||
var urlEscapeFunctionTerm = model.FindDeclaredTerm(CommunityVocabularyConstants.UrlEscapeFunction); | ||
Assert.NotNull(urlEscapeFunctionTerm); | ||
Assert.Equal(CommunityVocabularyModel.UrlEscapeFunctionTerm, urlEscapeFunctionTerm); | ||
Assert.Equal("Org.OData.Community.V1", urlEscapeFunctionTerm.Namespace); | ||
Assert.Equal("UrlEscapeFunction", urlEscapeFunctionTerm.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters