Skip to content

Port EdmLib functional tests (ClrTypeMapping, EdmToClrConversion, Edmx, Parsers, versionings tests) #3256

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AssemblyInfo/AssemblyInfoCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[assembly: AssemblyTrademark("Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the U.S. and/or other countries.")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("Microsoft.Test.Taupo.Astoria, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100197c25d0a04f73cb271e8181dba1c0c713df8deebb25864541a66670500f34896d280484b45fe1ff6c29f2ee7aa175d8bcbd0c83cc23901a894a86996030f6292ce6eda6e6f3e6c74b3c5a3ded4903c951e6747e6102969503360f7781bf8bf015058eb89b7621798ccc85aaca036ff1bc1556bb7f62de15908484886aa8bbae")]
[assembly: InternalsVisibleTo("Microsoft.OData.Edm.E2E.Tests, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100c1b376caa4bac2fba60ec13e0eb61b0a71b3dffb0903ccd5d7cf114c1145a17f1e9dfb3c2636e4990312a80b36f5605bf37a4c53a833568f2da628f2b738a882e7e91bc11b629ed2a94b0c522afa971bf607d2c53f3c6c6dd9e1bd20e4d41b07f776d3638823dab3fe36ea3f01259fc03f8ec5153d6391fd23665f0d1dd129b6")]
#if (DEBUG || _DEBUG)
[assembly: AssemblyConfiguration("Debug")]
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ protected IEnumerable<string> GetSerializerResult(IEdmModel edmModel, EdmVersion
xmlWriters[i].Close();
}

var strings = new List<string>();
foreach (var sb in stringBuilders)
{
strings.Add(sb.ToString());
}

return strings;
return stringBuilders.Select(sb => sb.ToString());
}

protected IEnumerable<string> GetSerializerResult(IEdmModel edmModel)
Expand Down Expand Up @@ -98,6 +92,50 @@ protected static XElement ExtractElementByName(IEnumerable<XElement> inputSchema
return containers;
}

public static XNamespace GetCsdlFullNamespace(EdmVersion csdlVersion)
{
return EdmStringConstants.EdmOasisNamespace;
}

public static IEnumerable<string> GetBaseTypes(XElement csdl, string entityFullTypeName)
{
var entityTypeName = entityFullTypeName.Split('.').Last();
var entityTypeNamespace = entityFullTypeName.Substring(0, entityFullTypeName.Length - ('.' + entityTypeName).Length);

var baseTypes = new List<string>();
if (csdl.Attribute("Namespace").Value != entityTypeNamespace)
{
return baseTypes;
}

var types = csdl.Elements(XName.Get("EntityType", csdl.Name.NamespaceName)).Where(n => n.Attribute("Name").Value == entityTypeName);
return types
.Where(type => type.Attribute("BaseType") != null)
.SelectMany(type => GetBaseTypes(csdl, type.Attribute("BaseType").Value).Concat(new[] { type.Attribute("BaseType").Value }));
}

public static IEnumerable<string> GetDirectlyDerivedTypes(XElement csdl, string structuralTypeElementName, string fullTypeName)
{
var entityTypeName = fullTypeName.Split('.').Last();
var entityTypeNamespace = fullTypeName.Substring(0, fullTypeName.Length - ('.' + entityTypeName).Length);

var types = csdl.Elements(XName.Get(structuralTypeElementName, csdl.Name.NamespaceName))
.Where(n => null != n.Attribute("BaseType") && fullTypeName == n.Attribute("BaseType").Value);

return types.Where(type => type.Attribute("Name") != null).Select(type => csdl.Attribute("Namespace").Value + "." + type.Attribute("Name").Value);
}

public static IEnumerable<string> GetDirectlyDerivedTypes(IEnumerable<XElement> csdlElements, string structuralTypeElementName, string fullTypeName)
{
return csdlElements.SelectMany(csdlElement => GetDirectlyDerivedTypes(csdlElement, structuralTypeElementName, fullTypeName));
}

public static IEnumerable<string> GetDerivedTypes(IEnumerable<XElement> csdlElements, string structuralTypeElementName, string fullTypeName)
{
var derivedTypes = GetDirectlyDerivedTypes(csdlElements, structuralTypeElementName, fullTypeName);
return derivedTypes.Concat(derivedTypes.SelectMany(dt => GetDerivedTypes(csdlElements, structuralTypeElementName, dt)));
}

public class EdmLibTestErrors : List<EdmError>
{
public void Add(int? lineNumber, int? linePostion, EdmErrorCode edmErrorCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public static EdmModel Clone(this IEdmModel model)
/// <returns>A collection of child XML elements with the given EDM namespace based name.</returns>
public static IEnumerable<XElement> EdmElements(this XElement parentElement, string elementName)
{
Assert.Empty(elementName);
Assert.NotEmpty(elementName);
Assert.NotNull(parentElement);
return parentElement.Elements(XName.Get(elementName, EdmOasisNamespace));
}
Expand All @@ -851,7 +851,7 @@ public static IEnumerable<XElement> EdmElements(this XElement parentElement, str
/// <returns>The value of the attribute as a string. Throws an exception if attribute not found.</returns>
public static string GetAttributeValue(this XElement element, string attributeName)
{
Assert.Empty(attributeName);
Assert.NotEmpty(attributeName);
Assert.NotNull(attributeName);

var attribute = element.Attribute(attributeName);
Expand All @@ -869,7 +869,7 @@ public static string GetAttributeValue(this XElement element, string attributeNa
/// <returns>Whether or not the attribute was found.</returns>
public static bool TryGetAttributeValue(this XElement element, string attributeName, out string? attributeValue)
{
Assert.Empty(attributeName);
Assert.NotEmpty(attributeName);
Assert.NotNull(attributeName);

var attribute = element.Attribute(attributeName);
Expand Down
Loading