-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add annotation term for Org.OData.Community.UrlEscape.V1.UrlEscapeFunction. #1307
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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"; | ||
} | ||
} |
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; | ||
} | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe add test cases:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes these tests will be added, as part of EDM model validation test along with bound function, in the task for upper layer and as a separate PR. This PR here is just to add the CommunityVocabulary. #Resolved |
||
{ | ||
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either make this public or make the class internal. Unless we think there is a client scenario that requires it, I would make the class internal -- we can always make it public later. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
In reply to: 231620168 [](ancestors = 231620168)