Exemplo n.º 1
0
        public static void Register(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            Type kvpType = typeof(KeyValuePair<string, string>);
            var kvpEdmType = builder.AddComplexType(kvpType);
            kvpEdmType.AddProperty(kvpType.GetProperty("Key"));
            kvpEdmType.AddProperty(kvpType.GetProperty("Value"));

            config.MapHttpAttributeRoutes();

            config.Routes.IgnoreRoute("Documentation", "api/documentation");

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
        }
Exemplo n.º 2
0
        public void GetEdmModel_PropertyWithDatabaseAttribute_CannotConfigAnnotationOnPropertyOnComplexType()
        {
            // Arrange
            MockType type =
                new MockType("Complex")
                .Property(typeof(int), "ID", new DatabaseGeneratedAttribute(DatabaseGeneratedOption.Computed))
                .Property(typeof(int?), "Count");

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.AddComplexType(type);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmComplexType        entity     = model.AssertHasComplexType(type);
            IEdmStructuralProperty idProperty = entity.AssertHasPrimitiveProperty(model, "ID",
                                                                                  EdmPrimitiveTypeKind.Int32, isNullable: false);

            var idAnnotation = model.GetAnnotationValue <EdmStringConstant>(
                idProperty,
                StoreGeneratedPatternAnnotation.AnnotationsNamespace,
                StoreGeneratedPatternAnnotation.AnnotationName);

            Assert.Null(idAnnotation);

            IEdmStructuralProperty countProperty = entity.AssertHasPrimitiveProperty(model, "Count",
                                                                                     EdmPrimitiveTypeKind.Int32, isNullable: true);

            var countAnnotation = model.GetAnnotationValue <EdmStringConstant>(
                countProperty,
                StoreGeneratedPatternAnnotation.AnnotationsNamespace,
                StoreGeneratedPatternAnnotation.AnnotationName);

            Assert.Null(countAnnotation);
        }
        public void GetEdmModel_PropertyWithDatabaseAttribute_CannotConfigAnnotationOnPropertyOnComplexType()
        {
            // Arrange
            MockType type =
                new MockType("Complex")
                .Property(typeof(int), "ID", new DatabaseGeneratedAttribute(DatabaseGeneratedOption.Computed))
                .Property(typeof(int?), "Count");

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.AddComplexType(type);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            IEdmComplexType entity = model.AssertHasComplexType(type);
            IEdmStructuralProperty idProperty = entity.AssertHasPrimitiveProperty(model, "ID",
                EdmPrimitiveTypeKind.Int32, isNullable: false);

            var idAnnotation = model.GetAnnotationValue<EdmStringConstant>(
                idProperty,
                StoreGeneratedPatternAnnotation.AnnotationsNamespace,
                StoreGeneratedPatternAnnotation.AnnotationName);
            Assert.Null(idAnnotation);

            IEdmStructuralProperty countProperty = entity.AssertHasPrimitiveProperty(model, "Count",
                EdmPrimitiveTypeKind.Int32, isNullable: true);

            var countAnnotation = model.GetAnnotationValue<EdmStringConstant>(
                countProperty,
                StoreGeneratedPatternAnnotation.AnnotationsNamespace,
                StoreGeneratedPatternAnnotation.AnnotationName);
            Assert.Null(countAnnotation);
        }