Ejemplo n.º 1
0
        public void AmbiguousTypeTest()
        {
            EdmModel model = new EdmModel();

            IEdmSchemaType type1 = new StubEdmComplexType("Foo", "Bar");
            IEdmSchemaType type2 = new StubEdmComplexType("Foo", "Bar");
            IEdmSchemaType type3 = new StubEdmComplexType("Foo", "Bar");

            model.AddElement(type1);
            Assert.AreEqual(type1, model.FindType("Foo.Bar"), "Correct item.");

            model.AddElement(type2);
            model.AddElement(type3);

            IEdmSchemaType ambiguous = model.FindType("Foo.Bar");
            Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");

            Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, ambiguous.SchemaElementKind, "Correct schema element kind.");
            Assert.AreEqual("Foo", ambiguous.Namespace, "Correct Namespace");
            Assert.AreEqual("Bar", ambiguous.Name, "Correct Name");
            Assert.AreEqual(EdmTypeKind.None, ambiguous.TypeKind, "Correct type kind.");
        }
        public void ValidateOpenComplexTypeSupported()
        {
            var ct = new StubEdmComplexType("NS1", "CT1")
            {
                IsOpen = true
            };
            ct.Add(new EdmStructuralProperty(ct, "p1", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int16, true)));

            var model = new EdmModel();
            model.AddElement(ct);

            IEnumerable<EdmError> errors;

            foreach (var v in new[] { Microsoft.OData.Edm.Library.EdmConstants.EdmVersionLatest })
            {
                model.SetEdmVersion(v);
                model.Validate(out errors);
                Assert.AreEqual(0, errors.Count(), "No error should be returned");
            }
        }
Ejemplo n.º 3
0
        public void TestElementInterfaceCriticalComplexTypeBaseType()
        {
            var expectedErrors = new EdmLibTestErrors()
            {
                { null, null, EdmErrorCode.InterfaceCriticalPropertyValueMustNotBeNull },
                { null, null, EdmErrorCode.InterfaceCriticalPropertyValueMustNotBeNull },
            };

            var baseComplexType = new StubEdmComplexType(null, null);
            var property = new StubEdmStructuralProperty("")
            {
                DeclaringType = baseComplexType
            };
            baseComplexType.Add(property);
            this.ValidateElement(baseComplexType, expectedErrors);

            var derivedComplexType = new EdmComplexType("", "", baseComplexType, false);
            expectedErrors = new EdmLibTestErrors();
            this.ValidateElement(derivedComplexType, expectedErrors);
        }
        public static IEdmModel ModelWithEntityTypeWithComplexBaseType()
        {
            EdmModel model = new EdmModel();

            var entity1 = new StubEdmEntityType("Foo", "Bar");
            var id1 = new EdmStructuralProperty(entity1, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None);
            entity1.Add(id1);
            entity1.SetKey(id1);

            StubEdmComplexType complex1 = new StubEdmComplexType("Foo", "Baz");
            complex1.Add(new EdmStructuralProperty(complex1, "Data", EdmCoreModel.Instance.GetString(true)));
            entity1.BaseType = complex1;

            model.AddElement(entity1);
            model.AddElement(complex1);

            return model;
        }