-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for both ConstantNode and SingleResourceCastNode
- Loading branch information
1 parent
53d9268
commit 1820efe
Showing
3 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
test/Microsoft.AspNetCore.OData.Tests/Query/Expressions/EdmModelBuilder.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,96 @@ | ||
using Microsoft.FullyQualified.NS; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.ModelBuilder; | ||
|
||
namespace Microsoft.AspNetCore.OData.Tests.Query.Expressions | ||
{ | ||
internal static class EdmModelBuilder | ||
{ | ||
private static readonly IEdmModel Model = BuildAndGetEdmModel(); | ||
|
||
public static IEdmModel TestModel | ||
{ | ||
get { return Model; } | ||
} | ||
|
||
public static IEdmEntityType GetEntityType(string entityQualifiedName) | ||
{ | ||
return TestModel.FindDeclaredType(entityQualifiedName) as IEdmEntityType; | ||
} | ||
|
||
public static IEdmComplexType GetEdmComplexType(string complexTypeQualifiedName) | ||
{ | ||
return TestModel.FindDeclaredType(complexTypeQualifiedName) as IEdmComplexType; | ||
} | ||
|
||
public static IEdmEntityTypeReference GetEntityTypeReference(IEdmEntityType entityType) | ||
{ | ||
return new EdmEntityTypeReference(entityType, false); | ||
} | ||
|
||
public static IEdmComplexTypeReference GetComplexTypeReference(IEdmComplexType complexType) | ||
{ | ||
// Create a complex type reference using the EdmCoreModel | ||
return new EdmComplexTypeReference(complexType, isNullable: false); | ||
} | ||
|
||
public static IEdmProperty GetPersonLocationProperty() | ||
{ | ||
return GetEntityType("Microsoft.FullyQualified.NS.Person").FindProperty("Location"); | ||
} | ||
|
||
/// <summary> | ||
/// Get the entity set from the model | ||
/// </summary> | ||
/// <returns>People Set</returns> | ||
public static IEdmEntitySet GetPeopleSet() | ||
{ | ||
return TestModel.EntityContainer.FindEntitySet("People"); | ||
} | ||
|
||
public static IEdmModel BuildAndGetEdmModel() | ||
{ | ||
var builder = new ODataConventionModelBuilder(); | ||
builder.Namespace = "Microsoft.FullyQualified.NS"; | ||
builder.EntitySet<Person>("People"); | ||
builder.ComplexType<MyAddress>(); | ||
builder.ComplexType<WorkAddress>(); | ||
builder.EntitySet<Employee>("Employees"); | ||
|
||
return builder.GetEdmModel(); | ||
} | ||
} | ||
} | ||
|
||
namespace Microsoft.FullyQualified.NS | ||
{ | ||
public class Person | ||
{ | ||
public int Id { get; set; } | ||
public string FullName { get; set; } | ||
public MyAddress Location { get; set; } | ||
} | ||
|
||
public class Employee : Person | ||
{ | ||
public string EmployeeNumber { get; set; } | ||
} | ||
|
||
public class MyAddress | ||
{ | ||
public string Street { get; set; } | ||
public AddressType AddressType { get; set; } | ||
} | ||
|
||
public class WorkAddress : MyAddress | ||
{ | ||
public string OfficeNumber { get; set; } | ||
} | ||
|
||
public enum AddressType | ||
{ | ||
Home, | ||
Work, | ||
Other | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
test/Microsoft.AspNetCore.OData.Tests/Query/Expressions/FakeEdmNodesHelper.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,74 @@ | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.UriParser; | ||
|
||
namespace Microsoft.AspNetCore.OData.Tests.Query.Expressions | ||
{ | ||
public class FakeSingleEntityNode : SingleEntityNode | ||
{ | ||
private readonly IEdmEntityTypeReference typeReference; | ||
private readonly IEdmEntitySetBase set; | ||
|
||
public FakeSingleEntityNode(IEdmEntityTypeReference type, IEdmEntitySetBase set) | ||
{ | ||
this.typeReference = type; | ||
this.set = set; | ||
} | ||
|
||
public override IEdmTypeReference TypeReference | ||
{ | ||
get { return this.typeReference; } | ||
} | ||
|
||
public override IEdmNavigationSource NavigationSource | ||
{ | ||
get { return this.set; } | ||
} | ||
|
||
public override IEdmStructuredTypeReference StructuredTypeReference | ||
{ | ||
get { return this.typeReference; } | ||
} | ||
|
||
public override IEdmEntityTypeReference EntityTypeReference | ||
{ | ||
get { return this.typeReference; } | ||
} | ||
|
||
public static FakeSingleEntityNode CreateFakeNodeForPerson() | ||
{ | ||
var personType = EdmModelBuilder.GetEntityType("Microsoft.FullyQualified.NS.Person"); | ||
return new FakeSingleEntityNode(EdmModelBuilder.GetEntityTypeReference(personType), EdmModelBuilder.GetPeopleSet()); | ||
} | ||
} | ||
|
||
public class FakeCollectionResourceNode : CollectionResourceNode | ||
{ | ||
private readonly IEdmStructuredTypeReference _typeReference; | ||
private readonly IEdmNavigationSource _source; | ||
private readonly IEdmTypeReference _itemType; | ||
private readonly IEdmCollectionTypeReference _collectionType; | ||
|
||
public FakeCollectionResourceNode(IEdmStructuredTypeReference type, IEdmNavigationSource source, IEdmTypeReference itemType, IEdmCollectionTypeReference collectionType) | ||
{ | ||
_typeReference = type; | ||
_source = source; | ||
_itemType = itemType; | ||
_collectionType = collectionType; | ||
} | ||
|
||
public override IEdmStructuredTypeReference ItemStructuredType => _typeReference; | ||
|
||
public override IEdmNavigationSource NavigationSource => _source; | ||
|
||
public override IEdmTypeReference ItemType => _itemType; | ||
|
||
public override IEdmCollectionTypeReference CollectionType => _collectionType; | ||
|
||
public static FakeCollectionResourceNode CreateFakeNodeForPerson() | ||
{ | ||
var singleEntityNode = FakeSingleEntityNode.CreateFakeNodeForPerson(); | ||
return new FakeCollectionResourceNode( | ||
singleEntityNode.EntityTypeReference, singleEntityNode.NavigationSource, singleEntityNode.EntityTypeReference, singleEntityNode.EntityTypeReference.AsCollection()); | ||
} | ||
} | ||
} |
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