Beispiel #1
0
        public static TestModel Initialize()
        {
            EdmModel model = new EdmModel();
            var result = new TestModel(model);
            var productType = new EdmEntityType("TestModel", "Product");
            result.ProductType = productType;
            EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(idProperty);
            productType.AddKeys(idProperty);
            productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);
            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
            result.Container = defaultContainer;
            result.ProductsSet = defaultContainer.AddEntitySet("Products", productType);
            model.AddElement(defaultContainer);

            var derivedProductType = new EdmEntityType("TestModel", "DerivedProduct", productType);
            result.DerivedProductType = derivedProductType;

            EdmEntityType multipleKeyType = new EdmEntityType("TestModel", "MultipleKeyType");
            result.MultipleKeyType = multipleKeyType;
            EdmStructuralProperty keyAProperty = new EdmStructuralProperty(multipleKeyType, "KeyA", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty keyBProperty = new EdmStructuralProperty(multipleKeyType, "KeyB", EdmCoreModel.Instance.GetInt32(false));
            multipleKeyType.AddProperty(keyAProperty);
            multipleKeyType.AddProperty(keyBProperty);
            multipleKeyType.AddKeys(keyAProperty, keyBProperty);
            model.AddElement(multipleKeyType);
            result.MultipleKeysSet = defaultContainer.AddEntitySet("MultipleKeySet", multipleKeyType);

            EdmEntityType productTypeWithNavProps = new EdmEntityType("TestModel", "ProductWithNavProps", productType);
            result.ProductWithNavPropsType = productTypeWithNavProps;
            productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
                {
                    Name = "RelatedProducts",
                    Target = productType,
                    TargetMultiplicity = EdmMultiplicity.Many
                });

            productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "RelatedDerivedProduct",
                Target = derivedProductType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            model.AddElement(productTypeWithNavProps);

            EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, true /*isBound*/, null /*entitySetPath*/);
            model.AddElement(action);
            defaultContainer.AddActionImport("SimpleAction", action);
            
            EdmAction action1 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null);
            action1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddActionImport("SimpleFunctionWithOverload", action1);
            
            EdmAction action2 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null);
            action2.AddParameter("p1", EdmCoreModel.Instance.GetString(false));
            defaultContainer.AddActionImport("SimpleFunctionWithOverload", action2);

            result.OneProductValue = BuildDefaultProductValue(productType);
            result.OneDerivedProductValue = BuildDefaultProductValue(derivedProductType);
            result.OneMultipleKeyValue = BuildDefaultMultipleKeyValue(model);
            result.OneProductWithNavPropsValue = BuildDefaultProductValue(productTypeWithNavProps);

            return result;
        }
 protected ODataUriBuilderTestsBase()
 {
     this.defaultBaseUri         = new Uri("http://odata.org/base/");
     this.model                  = TestModel.BuildDefaultTestModel();
     this.defaultProductInstance = TestModel.BuildDefaultProductValue(TestModel.GetEntityType(this.model, "TestModel.Product"));
 }