public void The_Managers_CollectionIsCorrect()
            {
                Assert.True(_entityDataModel.EntitySets.ContainsKey("Managers"));

                EntitySet entitySet = _entityDataModel.EntitySets["Managers"];

                Assert.Equal("Managers", entitySet.Name);
                Assert.Equal(Capabilities.None, entitySet.Capabilities);

                EdmComplexType edmComplexType = entitySet.EdmType;

                Assert.Equal(EdmType.GetEdmType(typeof(Employee)), edmComplexType.BaseType);
                Assert.Equal(typeof(Manager), edmComplexType.ClrType);
                Assert.Equal("Sample.Model.Manager", edmComplexType.FullName);
                Assert.Equal("Manager", edmComplexType.Name);
                Assert.Equal(2, edmComplexType.Properties.Count); // Does not include inherited properties

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.False(edmComplexType.Properties[0].IsNavigable);
                Assert.False(edmComplexType.Properties[0].IsNullable);
                Assert.Equal("AnnualBudget", edmComplexType.Properties[0].Name);
                Assert.Same(EdmPrimitiveType.Decimal, edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.True(edmComplexType.Properties[1].IsNavigable);
                Assert.True(edmComplexType.Properties[1].IsNullable);
                Assert.Equal("Employees", edmComplexType.Properties[1].Name);
                Assert.IsType <EdmCollectionType>(edmComplexType.Properties[1].PropertyType);
                Assert.Equal(EdmType.GetEdmType(typeof(Employee)), ((EdmCollectionType)edmComplexType.Properties[1].PropertyType).ContainedType);

                Assert.Null(entitySet.EntityKey);
            }
Пример #2
0
        public void GetEdmType_String_ReturnsPrimitives()
        {
            TestHelper.EnsureEDM();

            var edmType = EdmType.GetEdmType("Sample.Model.AccessLevel");

            Assert.NotNull(edmType);
            Assert.Equal(typeof(AccessLevel), edmType.ClrType);
        }
Пример #3
0
        public void GetEdmType_Type_ReturnsPrimitives()
        {
            Assert.Equal(EdmType.GetEdmType(typeof(byte[])), EdmPrimitiveType.Binary);

            Assert.Equal(EdmType.GetEdmType(typeof(bool)), EdmPrimitiveType.Boolean);
            Assert.Equal(EdmType.GetEdmType(typeof(bool?)), EdmPrimitiveType.NullableBoolean);

            Assert.Equal(EdmType.GetEdmType(typeof(byte)), EdmPrimitiveType.Byte);
            Assert.Equal(EdmType.GetEdmType(typeof(byte?)), EdmPrimitiveType.NullableByte);

            Assert.Equal(EdmType.GetEdmType(typeof(DateTime)), EdmPrimitiveType.Date);
            Assert.Equal(EdmType.GetEdmType(typeof(DateTime?)), EdmPrimitiveType.NullableDate);

            Assert.Equal(EdmType.GetEdmType(typeof(DateTimeOffset)), EdmPrimitiveType.DateTimeOffset);
            Assert.Equal(EdmType.GetEdmType(typeof(DateTimeOffset?)), EdmPrimitiveType.NullableDateTimeOffset);

            Assert.Equal(EdmType.GetEdmType(typeof(decimal)), EdmPrimitiveType.Decimal);
            Assert.Equal(EdmType.GetEdmType(typeof(decimal?)), EdmPrimitiveType.NullableDecimal);

            Assert.Equal(EdmType.GetEdmType(typeof(double)), EdmPrimitiveType.Double);
            Assert.Equal(EdmType.GetEdmType(typeof(double?)), EdmPrimitiveType.NullableDouble);

            Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan)), EdmPrimitiveType.Duration);
            Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan?)), EdmPrimitiveType.NullableDuration);

            Assert.Equal(EdmType.GetEdmType(typeof(Guid)), EdmPrimitiveType.Guid);
            Assert.Equal(EdmType.GetEdmType(typeof(Guid?)), EdmPrimitiveType.NullableGuid);

            Assert.Equal(EdmType.GetEdmType(typeof(short)), EdmPrimitiveType.Int16);
            Assert.Equal(EdmType.GetEdmType(typeof(short?)), EdmPrimitiveType.NullableInt16);

            Assert.Equal(EdmType.GetEdmType(typeof(int)), EdmPrimitiveType.Int32);
            Assert.Equal(EdmType.GetEdmType(typeof(int?)), EdmPrimitiveType.NullableInt32);

            Assert.Equal(EdmType.GetEdmType(typeof(long)), EdmPrimitiveType.Int64);
            Assert.Equal(EdmType.GetEdmType(typeof(long?)), EdmPrimitiveType.NullableInt64);

            Assert.Equal(EdmType.GetEdmType(typeof(sbyte)), EdmPrimitiveType.SByte);
            Assert.Equal(EdmType.GetEdmType(typeof(sbyte?)), EdmPrimitiveType.NullableSByte);

            Assert.Equal(EdmType.GetEdmType(typeof(float)), EdmPrimitiveType.Single);
            Assert.Equal(EdmType.GetEdmType(typeof(float?)), EdmPrimitiveType.NullableSingle);

            ////Assert.Equal(EdmType.GetEdmType(typeof(Stream)), EdmPrimitiveType.Stream);

            Assert.Equal(EdmType.GetEdmType(typeof(char)), EdmPrimitiveType.String);
            Assert.Equal(EdmType.GetEdmType(typeof(char?)), EdmPrimitiveType.String);
            Assert.Equal(EdmType.GetEdmType(typeof(string)), EdmPrimitiveType.String);

            ////Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan)), EdmPrimitiveType.TimeOfDay);
            ////Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan?)), EdmPrimitiveType.NullableTimeOfDay);
        }
            public void The_Employees_CollectionIsCorrect()
            {
                Assert.True(this.entityDataModel.EntitySets.ContainsKey("Employees"));

                var entitySet = this.entityDataModel.EntitySets["Employees"];

                Assert.Equal("Employees", entitySet.Name);
                Assert.Equal(Capabilities.None, entitySet.Capabilities);

                var edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Employee), edmComplexType.ClrType);
                Assert.Equal("NorthwindModel.Employee", edmComplexType.FullName);
                Assert.Equal("Employee", edmComplexType.Name);
                Assert.Equal(8, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.Equal("AccessLevel", edmComplexType.Properties[0].Name);
                Assert.Same(EdmType.GetEdmType(typeof(AccessLevel)), edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.Equal("BirthDate", edmComplexType.Properties[1].Name);
                Assert.Same(EdmPrimitiveType.Date, edmComplexType.Properties[1].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.Equal("EmailAddress", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.Equal("Forename", edmComplexType.Properties[3].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[3].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.Equal("Id", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[5].DeclaringType);
                Assert.Equal("ImageData", edmComplexType.Properties[5].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[5].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[6].DeclaringType);
                Assert.Equal("Surname", edmComplexType.Properties[6].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[6].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[7].DeclaringType);
                Assert.Equal("Title", edmComplexType.Properties[7].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[7].PropertyType);

                Assert.Same(edmComplexType.Properties[4], entitySet.EntityKey);
            }
        public void PrimitivesAreRegisteredByDefault()
        {
            Assert.Equal(EdmType.GetEdmType(typeof(byte[])), EdmPrimitiveType.Binary);

            Assert.Equal(EdmType.GetEdmType(typeof(bool)), EdmPrimitiveType.Boolean);
            Assert.Equal(EdmType.GetEdmType(typeof(bool?)), EdmPrimitiveType.Boolean);

            Assert.Equal(EdmType.GetEdmType(typeof(byte)), EdmPrimitiveType.Byte);
            Assert.Equal(EdmType.GetEdmType(typeof(byte?)), EdmPrimitiveType.Byte);

            Assert.Equal(EdmType.GetEdmType(typeof(DateTime)), EdmPrimitiveType.Date);
            Assert.Equal(EdmType.GetEdmType(typeof(DateTime?)), EdmPrimitiveType.Date);

            Assert.Equal(EdmType.GetEdmType(typeof(DateTimeOffset)), EdmPrimitiveType.DateTimeOffset);
            Assert.Equal(EdmType.GetEdmType(typeof(DateTimeOffset?)), EdmPrimitiveType.DateTimeOffset);

            Assert.Equal(EdmType.GetEdmType(typeof(decimal)), EdmPrimitiveType.Decimal);
            Assert.Equal(EdmType.GetEdmType(typeof(decimal?)), EdmPrimitiveType.Decimal);

            Assert.Equal(EdmType.GetEdmType(typeof(double)), EdmPrimitiveType.Double);
            Assert.Equal(EdmType.GetEdmType(typeof(double?)), EdmPrimitiveType.Double);

            Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan)), EdmPrimitiveType.Duration);
            Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan?)), EdmPrimitiveType.Duration);

            Assert.Equal(EdmType.GetEdmType(typeof(Guid)), EdmPrimitiveType.Guid);
            Assert.Equal(EdmType.GetEdmType(typeof(Guid?)), EdmPrimitiveType.Guid);

            Assert.Equal(EdmType.GetEdmType(typeof(short)), EdmPrimitiveType.Int16);
            Assert.Equal(EdmType.GetEdmType(typeof(short?)), EdmPrimitiveType.Int16);

            Assert.Equal(EdmType.GetEdmType(typeof(int)), EdmPrimitiveType.Int32);
            Assert.Equal(EdmType.GetEdmType(typeof(int?)), EdmPrimitiveType.Int32);

            Assert.Equal(EdmType.GetEdmType(typeof(long)), EdmPrimitiveType.Int64);
            Assert.Equal(EdmType.GetEdmType(typeof(long?)), EdmPrimitiveType.Int64);

            Assert.Equal(EdmType.GetEdmType(typeof(sbyte)), EdmPrimitiveType.SByte);
            Assert.Equal(EdmType.GetEdmType(typeof(sbyte?)), EdmPrimitiveType.SByte);

            Assert.Equal(EdmType.GetEdmType(typeof(float)), EdmPrimitiveType.Single);
            Assert.Equal(EdmType.GetEdmType(typeof(float?)), EdmPrimitiveType.Single);

            Assert.Equal(EdmType.GetEdmType(typeof(char)), EdmPrimitiveType.String);
            Assert.Equal(EdmType.GetEdmType(typeof(char?)), EdmPrimitiveType.String);
            Assert.Equal(EdmType.GetEdmType(typeof(string)), EdmPrimitiveType.String);

            ////Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan)), EdmPrimitiveType.TimeOfDay);
            ////Assert.Equal(EdmType.GetEdmType(typeof(TimeSpan?)), EdmPrimitiveType.TimeOfDay);
        }
Пример #6
0
            public void ParseIsOfFunctionWithTypeOnlyExpression()
            {
                QueryNode queryNode = FilterExpressionParser.Parse("isof(Sample.Model.Order)", EntityDataModel.Current.EntitySets["Orders"].EdmType);

                Assert.NotNull(queryNode);
                Assert.IsType <FunctionCallNode>(queryNode);

                var node = (FunctionCallNode)queryNode;

                Assert.Equal("isof", node.Name);
                Assert.Equal(1, node.Parameters.Count);
                Assert.IsType <ConstantNode <EdmType> >(node.Parameters[0]);
                var nodeParam0 = (ConstantNode <EdmType>)node.Parameters[0];

                Assert.Equal("Sample.Model.Order", nodeParam0.LiteralText);
                Assert.Equal(EdmType.GetEdmType(typeof(Sample.Model.Order)), nodeParam0.Value);
            }
Пример #7
0
        private static IEnumerable <XElement> GetEnumTypes(EntityDataModel entityDataModel)
        {
            // Any enums defined in the model.
            var enumTypes = entityDataModel.EntitySets
                            .SelectMany(kvp => kvp.Value.EdmType.Properties)
                            .Select(p => p.PropertyType)
                            .OfType <EdmEnumType>()
                            .Distinct()
                            .Select(t => new XElement(
                                        edmNs + "EnumType",
                                        new XAttribute("Name", t.Name),
                                        new XAttribute("UnderlyingType", EdmType.GetEdmType(Enum.GetUnderlyingType(t.ClrType)).FullName),
                                        new XAttribute("IsFlags", (t.ClrType.GetCustomAttribute <FlagsAttribute>() != null).ToString()),
                                        t.Members.Select(m => new XElement(
                                                             edmNs + "Member",
                                                             new XAttribute("Name", m.Name),
                                                             new XAttribute("Value", m.Value.ToString(CultureInfo.InvariantCulture))))));

            return(enumTypes);
        }
            public void The_Orders_CollectionIsCorrect()
            {
                Assert.True(this.entityDataModel.EntitySets.ContainsKey("Orders"));

                var entitySet = this.entityDataModel.EntitySets["Orders"];

                Assert.Equal("Orders", entitySet.Name);
                Assert.Equal(Capabilities.Insertable | Capabilities.Updatable, entitySet.Capabilities);

                var edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Order), edmComplexType.ClrType);
                Assert.Equal("NorthwindModel.Order", edmComplexType.FullName);
                Assert.Equal("Order", edmComplexType.Name);
                Assert.Equal(5, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.Equal("Freight", edmComplexType.Properties[0].Name);
                Assert.Same(EdmPrimitiveType.Decimal, edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.Equal("OrderDetails", edmComplexType.Properties[1].Name);
                Assert.IsType <EdmCollectionType>(edmComplexType.Properties[1].PropertyType);
                Assert.Equal(EdmType.GetEdmType(typeof(OrderDetail)), ((EdmCollectionType)edmComplexType.Properties[1].PropertyType).ContainedType);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.Equal("OrderId", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.Int64, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.Equal("ShipCountry", edmComplexType.Properties[3].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[3].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.Equal("TransactionId", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.Guid, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType.Properties[2], entitySet.EntityKey);
            }
            public void The_Managers_CollectionIsCorrect()
            {
                Assert.True(this.entityDataModel.EntitySets.ContainsKey("Managers"));

                var entitySet = this.entityDataModel.EntitySets["Managers"];

                Assert.Equal("Managers", entitySet.Name);
                Assert.Equal(Capabilities.None, entitySet.Capabilities);

                var edmComplexType = entitySet.EdmType;

                Assert.Equal(EdmType.GetEdmType(typeof(Employee)), edmComplexType.BaseType);
                Assert.Equal(typeof(Manager), edmComplexType.ClrType);
                Assert.Equal("NorthwindModel.Manager", edmComplexType.FullName);
                Assert.Equal("Manager", edmComplexType.Name);
                Assert.Equal(1, edmComplexType.Properties.Count); // Does not include inherited properties

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.Equal("AnnualBudget", edmComplexType.Properties[0].Name);
                Assert.Same(EdmPrimitiveType.Decimal, edmComplexType.Properties[0].PropertyType);

                Assert.Null(entitySet.EntityKey);
            }
            public void The_Employees_CollectionIsCorrect()
            {
                Assert.True(_entityDataModel.EntitySets.ContainsKey("Employees"));

                EntitySet entitySet = _entityDataModel.EntitySets["Employees"];

                Assert.Equal("Employees", entitySet.Name);
                Assert.Equal(Capabilities.None, entitySet.Capabilities);

                EdmComplexType edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Employee), edmComplexType.ClrType);
                Assert.Equal("Sample.Model.Employee", edmComplexType.FullName);
                Assert.Equal("Employee", edmComplexType.Name);
                Assert.Equal(11, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.False(edmComplexType.Properties[0].IsNavigable);
                Assert.False(edmComplexType.Properties[0].IsNullable);
                Assert.Equal("AccessLevel", edmComplexType.Properties[0].Name);
                Assert.Same(EdmType.GetEdmType(typeof(AccessLevel)), edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.False(edmComplexType.Properties[1].IsNavigable);
                Assert.False(edmComplexType.Properties[1].IsNullable);
                Assert.Equal("BirthDate", edmComplexType.Properties[1].Name);
                Assert.Same(EdmPrimitiveType.Date, edmComplexType.Properties[1].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.False(edmComplexType.Properties[2].IsNavigable);
                Assert.False(edmComplexType.Properties[2].IsNullable);
                Assert.Equal("EmailAddress", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.False(edmComplexType.Properties[3].IsNavigable);
                Assert.False(edmComplexType.Properties[3].IsNullable);
                Assert.Equal("Forename", edmComplexType.Properties[3].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[3].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.False(edmComplexType.Properties[4].IsNavigable);
                Assert.False(edmComplexType.Properties[4].IsNullable);
                Assert.Equal("Id", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[5].DeclaringType);
                Assert.False(edmComplexType.Properties[5].IsNavigable);
                Assert.True(edmComplexType.Properties[5].IsNullable);
                Assert.Equal("ImageData", edmComplexType.Properties[5].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[5].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[6].DeclaringType);
                Assert.False(edmComplexType.Properties[6].IsNavigable);
                Assert.False(edmComplexType.Properties[6].IsNullable);
                Assert.Equal("JoiningDate", edmComplexType.Properties[6].Name);
                Assert.Same(EdmPrimitiveType.Date, edmComplexType.Properties[6].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[7].DeclaringType);
                Assert.False(edmComplexType.Properties[7].IsNavigable);
                Assert.True(edmComplexType.Properties[7].IsNullable);
                Assert.Equal("LeavingDate", edmComplexType.Properties[7].Name);
                Assert.Same(EdmPrimitiveType.Date, edmComplexType.Properties[1].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[8].DeclaringType);
                Assert.True(edmComplexType.Properties[8].IsNavigable);
                Assert.True(edmComplexType.Properties[8].IsNullable);
                Assert.Equal("Manager", edmComplexType.Properties[8].Name);
                Assert.Equal(EdmType.GetEdmType(typeof(Manager)), (EdmComplexType)edmComplexType.Properties[8].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[9].DeclaringType);
                Assert.False(edmComplexType.Properties[9].IsNavigable);
                Assert.False(edmComplexType.Properties[9].IsNullable);
                Assert.Equal("Surname", edmComplexType.Properties[9].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[9].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[10].DeclaringType);
                Assert.False(edmComplexType.Properties[10].IsNavigable);
                Assert.False(edmComplexType.Properties[10].IsNullable);
                Assert.Equal("Title", edmComplexType.Properties[10].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[10].PropertyType);

                Assert.Same(edmComplexType.Properties[4], entitySet.EntityKey);
            }
Пример #11
0
 public void GetEdmType_Type_ReturnsNullForUnknownType()
 {
     Assert.Null(EdmType.GetEdmType(typeof(Console)));
 }
 public void IsEntitySet_ReturnsFalse_IfEdmTypeIsNotEntitySet()
 => Assert.True(_entityDataModel.IsEntitySet(EdmType.GetEdmType(typeof(Category))));
 public void IsEntitySet_ReturnsTrue_IfEdmTypeIsEntitySet()
 => Assert.True(_entityDataModel.IsEntitySet(EdmType.GetEdmType(typeof(Customer))));
            public void The_Orders_CollectionIsCorrect()
            {
                Assert.True(_entityDataModel.EntitySets.ContainsKey("Orders"));

                EntitySet entitySet = _entityDataModel.EntitySets["Orders"];

                Assert.Equal("Orders", entitySet.Name);
                Assert.Equal(Capabilities.Insertable | Capabilities.Updatable, entitySet.Capabilities);

                EdmComplexType edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Order), edmComplexType.ClrType);
                Assert.Equal("Sample.Model.Order", edmComplexType.FullName);
                Assert.Equal("Order", edmComplexType.Name);
                Assert.Equal(7, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.True(edmComplexType.Properties[0].IsNavigable);
                Assert.False(edmComplexType.Properties[0].IsNullable);
                Assert.Equal("Customer", edmComplexType.Properties[0].Name);
                Assert.Same(EdmType.GetEdmType(typeof(Customer)), edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.False(edmComplexType.Properties[1].IsNavigable);
                Assert.False(edmComplexType.Properties[1].IsNullable);
                Assert.Equal("Date", edmComplexType.Properties[1].Name);
                Assert.Same(EdmPrimitiveType.DateTimeOffset, edmComplexType.Properties[1].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.False(edmComplexType.Properties[2].IsNavigable);
                Assert.False(edmComplexType.Properties[2].IsNullable);
                Assert.Equal("Freight", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.Decimal, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.False(edmComplexType.Properties[3].IsNavigable);
                Assert.True(edmComplexType.Properties[3].IsNullable);
                Assert.Equal("OrderDetails", edmComplexType.Properties[3].Name);
                Assert.IsType <EdmCollectionType>(edmComplexType.Properties[3].PropertyType);
                Assert.Equal(EdmType.GetEdmType(typeof(OrderDetail)), ((EdmCollectionType)edmComplexType.Properties[3].PropertyType).ContainedType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.False(edmComplexType.Properties[4].IsNavigable);
                Assert.False(edmComplexType.Properties[4].IsNullable);
                Assert.Equal("OrderId", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.Int64, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[5].DeclaringType);
                Assert.False(edmComplexType.Properties[5].IsNavigable);
                Assert.False(edmComplexType.Properties[5].IsNullable);
                Assert.Equal("ShipCountry", edmComplexType.Properties[5].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[5].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[6].DeclaringType);
                Assert.False(edmComplexType.Properties[6].IsNavigable);
                Assert.False(edmComplexType.Properties[6].IsNullable);
                Assert.Equal("TransactionId", edmComplexType.Properties[6].Name);
                Assert.Same(EdmPrimitiveType.Guid, edmComplexType.Properties[6].PropertyType);

                Assert.Same(edmComplexType.Properties[4], entitySet.EntityKey);
            }
            public void The_Customers_CollectionIsCorrect()
            {
                Assert.True(_entityDataModel.EntitySets.ContainsKey("Customers"));

                EntitySet entitySet = _entityDataModel.EntitySets["Customers"];

                Assert.Equal("Customers", entitySet.Name);
                Assert.Equal(Capabilities.Updatable, entitySet.Capabilities);

                EdmComplexType edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Customer), edmComplexType.ClrType);
                Assert.Equal("Sample.Model.Customer", edmComplexType.FullName);
                Assert.Equal("Customer", edmComplexType.Name);
                Assert.Equal(10, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.True(edmComplexType.Properties[0].IsNavigable);
                Assert.False(edmComplexType.Properties[0].IsNullable);
                Assert.Equal("AccountManager", edmComplexType.Properties[0].Name);
                Assert.Same(EdmType.GetEdmType(typeof(Employee)), edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.False(edmComplexType.Properties[1].IsNavigable);
                Assert.False(edmComplexType.Properties[1].IsNullable);
                Assert.Equal("Address", edmComplexType.Properties[1].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[1].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.False(edmComplexType.Properties[2].IsNavigable);
                Assert.False(edmComplexType.Properties[2].IsNullable);
                Assert.Equal("City", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.False(edmComplexType.Properties[3].IsNavigable);
                Assert.False(edmComplexType.Properties[3].IsNullable);
                Assert.Equal("CompanyName", edmComplexType.Properties[3].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[3].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.False(edmComplexType.Properties[4].IsNavigable);
                Assert.True(edmComplexType.Properties[4].IsNullable);
                Assert.Equal("ContactName", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[5].DeclaringType);
                Assert.False(edmComplexType.Properties[5].IsNavigable);
                Assert.False(edmComplexType.Properties[5].IsNullable);
                Assert.Equal("Country", edmComplexType.Properties[5].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[5].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[6].DeclaringType);
                Assert.False(edmComplexType.Properties[6].IsNavigable);
                Assert.False(edmComplexType.Properties[6].IsNullable);
                Assert.Equal("LegacyId", edmComplexType.Properties[6].Name);
                Assert.Same(EdmPrimitiveType.Int32, edmComplexType.Properties[6].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[7].DeclaringType);
                Assert.True(edmComplexType.Properties[7].IsNavigable);
                Assert.True(edmComplexType.Properties[7].IsNullable);
                Assert.Equal("Orders", edmComplexType.Properties[7].Name);
                Assert.IsType <EdmCollectionType>(edmComplexType.Properties[7].PropertyType);
                Assert.Equal(EdmType.GetEdmType(typeof(Order)), ((EdmCollectionType)edmComplexType.Properties[7].PropertyType).ContainedType);

                Assert.Same(edmComplexType, edmComplexType.Properties[8].DeclaringType);
                Assert.False(edmComplexType.Properties[8].IsNavigable);
                Assert.True(edmComplexType.Properties[8].IsNullable);
                Assert.Equal("Phone", edmComplexType.Properties[8].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[8].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[9].DeclaringType);
                Assert.False(edmComplexType.Properties[9].IsNavigable);
                Assert.False(edmComplexType.Properties[9].IsNullable);
                Assert.Equal("PostalCode", edmComplexType.Properties[9].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[9].PropertyType);

                Assert.Same(edmComplexType.Properties[3], entitySet.EntityKey);
            }
        internal static ConstantNode ParseConstantNode(Token token)
        {
            switch (token.TokenType)
            {
            case TokenType.Base64Binary:
                byte[] binaryValue = Convert.FromBase64String(token.Value);
                return(ConstantNode.Binary(token.Value, binaryValue));

            case TokenType.Date:
                if (DateTime.TryParseExact(token.Value, ParserSettings.ODataDateFormat, ParserSettings.CultureInfo, DateTimeStyles.AssumeLocal, out DateTime dateTimeValue))
                {
                    return(ConstantNode.Date(token.Value, dateTimeValue));
                }

                throw ODataException.BadRequest(ExceptionMessage.UnableToParseDate, "$filter");

            case TokenType.DateTimeOffset:
                if (DateTimeOffset.TryParse(token.Value, ParserSettings.CultureInfo, ParserSettings.DateTimeStyles, out DateTimeOffset dateTimeOffsetValue))
                {
                    return(ConstantNode.DateTimeOffset(token.Value, dateTimeOffsetValue));
                }

                throw ODataException.BadRequest(ExceptionMessage.UnableToParseDateTimeOffset, "$filter");

            case TokenType.Decimal:
                string decimalText = token.Value.EndsWith("m", StringComparison.OrdinalIgnoreCase)
                        ? token.Value.Substring(0, token.Value.Length - 1)
                        : token.Value;
                decimal decimalValue = decimal.Parse(decimalText, ParserSettings.CultureInfo);
                return(ConstantNode.Decimal(token.Value, decimalValue));

            case TokenType.Double:
                return(ParseDouble(token));

            case TokenType.Duration:
                string durationText = token.Value.Substring(9, token.Value.Length - 10)
                                      .Replace("P", string.Empty)
                                      .Replace("DT", ".")
                                      .Replace("H", ":")
                                      .Replace("M", ":")
                                      .Replace("S", string.Empty);
                var durationTimeSpanValue = TimeSpan.Parse(durationText, ParserSettings.CultureInfo);
                return(ConstantNode.Duration(token.Value, durationTimeSpanValue));

            case TokenType.EdmType:
                EdmType edmType = EdmType.GetEdmType(token.Value);
                return(ConstantNode.EdmTypeNode(token.Value, edmType));

            case TokenType.Enum:
                int         firstQuote        = token.Value.IndexOf('\'');
                string      edmEnumTypeName   = token.Value.Substring(0, firstQuote);
                EdmEnumType edmEnumType       = (EdmEnumType)EdmType.GetEdmType(edmEnumTypeName);
                string      edmEnumMemberName = token.Value.Substring(firstQuote + 1, token.Value.Length - firstQuote - 2);
                object      enumValue         = edmEnumType.GetClrValue(edmEnumMemberName);
                Type        constantNodeType  = typeof(ConstantNode <>).MakeGenericType(edmEnumType.ClrType);

                return((ConstantNode)Activator.CreateInstance(constantNodeType, BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { edmEnumType, token.Value, enumValue }, null));

            case TokenType.False:
                return(ConstantNode.False);

            case TokenType.Guid:
                var guidValue = Guid.ParseExact(token.Value, "D");
                return(ConstantNode.Guid(token.Value, guidValue));

            case TokenType.Integer:
                return(ParseInteger(token));

            case TokenType.Null:
                return(ConstantNode.Null);

            case TokenType.Single:
                string singleText  = token.Value.Substring(0, token.Value.Length - 1);
                float  singleValue = float.Parse(singleText, ParserSettings.CultureInfo);
                return(ConstantNode.Single(token.Value, singleValue));

            case TokenType.String:
                string stringText = token.Value.Trim('\'').Replace("''", "'");
                return(ConstantNode.String(token.Value, stringText));

            case TokenType.TimeOfDay:
                var timeSpanTimeOfDayValue = TimeSpan.Parse(token.Value, ParserSettings.CultureInfo);
                return(ConstantNode.Time(token.Value, timeSpanTimeOfDayValue));

            case TokenType.True:
                return(ConstantNode.True);

            default:
                throw new NotSupportedException(token.TokenType.ToString());
            }
        }
Пример #17
0
        internal static ConstantNode ParseConstantNode(Token token)
        {
            switch (token.TokenType)
            {
            case TokenType.Date:
                var dateTimeValue = DateTime.ParseExact(token.Value, ODataDateFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
                return(ConstantNode.Date(token.Value, dateTimeValue));

            case TokenType.DateTimeOffset:
                var dateTimeOffsetValue = DateTimeOffset.Parse(token.Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
                return(ConstantNode.DateTimeOffset(token.Value, dateTimeOffsetValue));

            case TokenType.Decimal:
                var decimalText  = token.Value.Substring(0, token.Value.Length - 1);
                var decimalValue = decimal.Parse(decimalText, CultureInfo.InvariantCulture);
                return(ConstantNode.Decimal(token.Value, decimalValue));

            case TokenType.Double:
                var doubleText = token.Value.EndsWith("d", StringComparison.OrdinalIgnoreCase)
                        ? token.Value.Substring(0, token.Value.Length - 1)
                        : token.Value;
                var doubleValue = double.Parse(doubleText, CultureInfo.InvariantCulture);
                return(ConstantNode.Double(token.Value, doubleValue));

            case TokenType.Duration:
                var durationText = token.Value.Substring(9, token.Value.Length - 10)
                                   .Replace("P", string.Empty)
                                   .Replace("DT", ".")
                                   .Replace("H", ":")
                                   .Replace("M", ":")
                                   .Replace("S", string.Empty);
                var durationTimeSpanValue = TimeSpan.Parse(durationText, CultureInfo.InvariantCulture);
                return(ConstantNode.Duration(token.Value, durationTimeSpanValue));

            case TokenType.Enum:
                var firstQuote        = token.Value.IndexOf('\'');
                var edmEnumTypeName   = token.Value.Substring(0, firstQuote);
                var edmEnumType       = (EdmEnumType)EdmType.GetEdmType(edmEnumTypeName);
                var edmEnumMemberName = token.Value.Substring(firstQuote + 1, token.Value.Length - firstQuote - 2);
                var enumValue         = edmEnumType.GetClrValue(edmEnumMemberName);

                return(new ConstantNode(edmEnumType, token.Value, enumValue));

            case TokenType.False:
                return(ConstantNode.False);

            case TokenType.Guid:
                var guidValue = Guid.ParseExact(token.Value, "D");
                return(ConstantNode.Guid(token.Value, guidValue));

            case TokenType.Integer:
                var integerText = token.Value;

                if (integerText == "0")
                {
                    return(ConstantNode.Int32Zero);
                }
                else if (integerText == "0l" || integerText == "0L")
                {
                    return(ConstantNode.Int64Zero);
                }

                var is64BitSuffix = integerText.EndsWith("l", StringComparison.OrdinalIgnoreCase);

                if (!is64BitSuffix && int.TryParse(integerText, out int int32Value))
                {
                    return(ConstantNode.Int32(token.Value, int32Value));
                }

                var int64Text  = !is64BitSuffix ? integerText : integerText.Substring(0, integerText.Length - 1);
                var int64Value = long.Parse(int64Text, CultureInfo.InvariantCulture);
                return(ConstantNode.Int64(token.Value, int64Value));

            case TokenType.Null:
                return(ConstantNode.Null);

            case TokenType.Single:
                var singleText  = token.Value.Substring(0, token.Value.Length - 1);
                var singleValue = float.Parse(singleText, CultureInfo.InvariantCulture);
                return(ConstantNode.Single(token.Value, singleValue));

            case TokenType.String:
                var stringText = token.Value.Trim('\'').Replace("''", "'");
                return(ConstantNode.String(token.Value, stringText));

            case TokenType.TimeOfDay:
                var timeSpanTimeOfDayValue = TimeSpan.Parse(token.Value, CultureInfo.InvariantCulture);
                return(ConstantNode.Time(token.Value, timeSpanTimeOfDayValue));

            case TokenType.True:
                return(ConstantNode.True);

            default:
                throw new NotSupportedException(token.TokenType.ToString());
            }
        }
Пример #18
0
 public void GetEdmType_String_ReturnsNullForUnknownType()
 {
     Assert.Null(EdmType.GetEdmType("System.Console"));
 }
            public void The_Products_CollectionIsCorrect()
            {
                Assert.True(this.entityDataModel.EntitySets.ContainsKey("Products"));

                var entitySet = this.entityDataModel.EntitySets["Products"];

                Assert.Equal("Products", entitySet.Name);
                Assert.Equal(Capabilities.Insertable | Capabilities.Updatable, entitySet.Capabilities);

                var edmComplexType = entitySet.EdmType;

                Assert.Null(edmComplexType.BaseType);
                Assert.Equal(typeof(Product), edmComplexType.ClrType);
                Assert.Equal("NorthwindModel.Product", edmComplexType.FullName);
                Assert.Equal("Product", edmComplexType.Name);
                Assert.Equal(9, edmComplexType.Properties.Count);

                Assert.Same(edmComplexType, edmComplexType.Properties[0].DeclaringType);
                Assert.Equal("Category", edmComplexType.Properties[0].Name);
                Assert.Same(EdmType.GetEdmType(typeof(Category)), edmComplexType.Properties[0].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[1].DeclaringType);
                Assert.Equal("Colour", edmComplexType.Properties[1].Name);
                Assert.Same(EdmType.GetEdmType(typeof(Colour)), edmComplexType.Properties[1].PropertyType);

                var edmEnumType = (EdmEnumType)EdmType.GetEdmType(typeof(Colour));

                Assert.Equal(typeof(Colour), edmEnumType.ClrType);
                Assert.Equal("NorthwindModel.Colour", edmEnumType.FullName);
                Assert.Equal("Colour", edmEnumType.Name);
                Assert.Equal(3, edmEnumType.Members.Count);
                Assert.Equal("Green", edmEnumType.Members[0].Name);
                Assert.Equal(1, edmEnumType.Members[0].Value);
                Assert.Equal("Blue", edmEnumType.Members[1].Name);
                Assert.Equal(2, edmEnumType.Members[1].Value);
                Assert.Equal("Red", edmEnumType.Members[2].Name);
                Assert.Equal(3, edmEnumType.Members[2].Value);

                Assert.Same(edmComplexType, edmComplexType.Properties[2].DeclaringType);
                Assert.Equal("Deleted", edmComplexType.Properties[2].Name);
                Assert.Same(EdmPrimitiveType.Boolean, edmComplexType.Properties[2].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[3].DeclaringType);
                Assert.Equal("Description", edmComplexType.Properties[3].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[3].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[4].DeclaringType);
                Assert.Equal("Name", edmComplexType.Properties[4].Name);
                Assert.Same(EdmPrimitiveType.String, edmComplexType.Properties[4].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[5].DeclaringType);
                Assert.Equal("Price", edmComplexType.Properties[5].Name);
                Assert.Same(EdmPrimitiveType.Decimal, edmComplexType.Properties[5].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[6].DeclaringType);
                Assert.Equal("ProductId", edmComplexType.Properties[6].Name);
                Assert.Same(EdmPrimitiveType.Int32, edmComplexType.Properties[6].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[7].DeclaringType);
                Assert.Equal("Rating", edmComplexType.Properties[7].Name);
                Assert.Same(EdmPrimitiveType.Int32, edmComplexType.Properties[7].PropertyType);

                Assert.Same(edmComplexType, edmComplexType.Properties[8].DeclaringType);
                Assert.Equal("ReleaseDate", edmComplexType.Properties[8].Name);
                Assert.Same(EdmPrimitiveType.Date, edmComplexType.Properties[8].PropertyType);

                Assert.Same(edmComplexType.Properties[6], entitySet.EntityKey);
            }
 public void TheEdmPrimitiveTypeIsSet()
 => Assert.Equal(EdmType.GetEdmType(typeof(AccessLevel)), _node.EdmType);