1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.ModelConfiguration.Conventions.UnitTests
{
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.ModelConfiguration.Edm;
using System.Data.Entity.ModelConfiguration.Edm.Common;
using System.Linq;
using Xunit;
public sealed class DeclaredPropertyOrderingConventionTests
{
public class SimpleEntityBase
{
public string InheritedPropertyA { get; set; }
public string InheritedPropertyB { get; set; }
}
public class SimpleEntity : SimpleEntityBase
{
private string PrivateProperty { get; set; }
public string PropertyA { get; set; }
public string PropertyB { get; set; }
public string Key { get; set; }
}
[Fact]
public void Apply_should_move_declared_keys_head_of_declared_properties_list()
{
var entityType = new EntityType();
var type = typeof(SimpleEntity);
entityType.Annotations.SetClrType(type);
var property1 = EdmProperty.Primitive("PrivateProperty", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property1);
var property2 = EdmProperty.Primitive("InheritedPropertyB", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property2);
var property3 = EdmProperty.Primitive("InheritedPropertyA", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property3);
var property4 = EdmProperty.Primitive("PropertyB", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property4);
var property5 = EdmProperty.Primitive("PropertyA", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property5);
var property6 = EdmProperty.Primitive("Key", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
entityType.AddMember(property6);
entityType.AddKeyMember(property6);
new DeclaredPropertyOrderingConvention().Apply(entityType, new EdmModel(DataSpace.CSpace));
Assert.True(
entityType.DeclaredProperties.Select(e => e.Name)
.SequenceEqual(
new[]
{
"Key",
"PrivateProperty",
"PropertyA",
"PropertyB",
"InheritedPropertyA",
"InheritedPropertyB"
}));
}
}
}
|