public static IEnumerable<TypeMetadata> GetMetadata(DataControllerDescription description)
 {
     return _metadataMap.GetOrAdd(description, desc =>
     {
         return GenerateMetadata(desc);
     });
 }
 public static IEnumerable <TypeMetadata> GetMetadata(DataControllerDescription description)
 {
     return(_metadataMap.GetOrAdd(description, desc =>
     {
         return GenerateMetadata(desc);
     }));
 }
        public void TaskReturningGetActions()
        {
            DataControllerDescription desc = GetDataControllerDescription(typeof(TaskReturningGetActionsController));

            Assert.Equal(4, desc.EntityTypes.Count());
            Assert.True(desc.EntityTypes.Contains(typeof(City)));
            Assert.True(desc.EntityTypes.Contains(typeof(CityWithInfo)));
            Assert.True(desc.EntityTypes.Contains(typeof(CityWithEditHistory)));
            Assert.True(desc.EntityTypes.Contains(typeof(State)));
        }
        public void AssociatedEntityTypeDiscovery_ImplicitDataContract()
        {
            DataControllerDescription description = GetDataControllerDescription(typeof(IncludedAssociationTestController_ImplicitDataContract));
            List <Type> entityTypes = description.EntityTypes.ToList();

            Assert.Equal(3, entityTypes.Count);
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.Customer)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.Order)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.Order_Detail)));
        }
        internal static DataControllerDescription GetDataControllerDescription(Type controllerType)
        {
            HttpConfiguration        configuration        = new HttpConfiguration();
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor
            {
                Configuration  = configuration,
                ControllerType = controllerType
            };

            return(DataControllerDescription.GetDescription(controllerDescriptor));
        }
Exemple #6
0
        private static IDictionary <string, TypeMetadata> GenerateMetadata(DataControllerDescription description)
        {
            // TODO: Complex types are NYI in DataControllerDescription
            // foreach (Type complexType in description.ComplexTypes)
            // {
            //     metadata.Add(new TypeMetadata(complexType));
            // }

            return(description.EntityTypes
                   .Select(TypeMetadata.FromType)
                   .ToList()
                   .ToDictionary(e => e.Name, e => e));
        }
 private static IEnumerable<TypeMetadata> GenerateMetadata(DataControllerDescription description)
 {
     List<TypeMetadata> metadata = new List<TypeMetadata>();
     foreach (Type entityType in description.EntityTypes)
     {
         metadata.Add(new TypeMetadata(entityType));
     }
     // TODO: Complex types are NYI in DataControllerDescription
     // foreach (Type complexType in description.ComplexTypes)
     // {
     //     metadata.Add(new TypeMetadata(complexType));
     // }
     return metadata;
 }
        private static JToken GenerateMetadata(Type dataControllerType)
        {
            DataControllerDescription desc = DataControllerDescriptionTest.GetDataControllerDescription(dataControllerType);
            var metadata = DataControllerMetadataGenerator.GetMetadata(desc);

            JObject metadataValue = new JObject();

            foreach (var m in metadata)
            {
                metadataValue.Add(m.EncodedTypeName, m.ToJToken());
            }

            return(metadataValue);
        }
        private static IEnumerable <TypeMetadata> GenerateMetadata(DataControllerDescription description)
        {
            List <TypeMetadata> metadata = new List <TypeMetadata>();

            foreach (Type entityType in description.EntityTypes)
            {
                metadata.Add(new TypeMetadata(entityType));
            }
            // TODO: Complex types are NYI in DataControllerDescription
            // foreach (Type complexType in description.ComplexTypes)
            // {
            //     metadata.Add(new TypeMetadata(complexType));
            // }
            return(metadata);
        }
        public void AssociatedEntityTypeDiscovery_ExplicitDataContract()
        {
            DataControllerDescription description = GetDataControllerDescription(typeof(IncludedAssociationTestController_ExplicitDataContract));
            List <Type> entityTypes = description.EntityTypes.ToList();

            Assert.Equal(8, entityTypes.Count);
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Order)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Order_Detail)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Customer)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Employee)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Product)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Category)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Supplier)));
            Assert.True(entityTypes.Contains(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Shipper)));
        }
        public void EFMetadataProvider_AttributeInference()
        {
            HttpConfiguration        configuration        = new HttpConfiguration();
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor
            {
                Configuration  = configuration,
                ControllerType = typeof(NorthwindEFTestController),
            };
            DataControllerDescription    description = GetDataControllerDescription(typeof(NorthwindEFTestController));
            PropertyDescriptorCollection properties  = TypeDescriptor.GetProperties(typeof(Microsoft.Web.Http.Data.Test.Models.EF.Product));

            // verify key attribute
            Assert.NotNull(properties["ProductID"].Attributes[typeof(KeyAttribute)]);
            Assert.Null(properties["ProductName"].Attributes[typeof(KeyAttribute)]);

            // verify StringLengthAttribute
            StringLengthAttribute sla = (StringLengthAttribute)properties["ProductName"].Attributes[typeof(StringLengthAttribute)];

            Assert.NotNull(sla);
            Assert.Equal(40, sla.MaximumLength);

            // verify RequiredAttribute
            RequiredAttribute ra = (RequiredAttribute)properties["ProductName"].Attributes[typeof(RequiredAttribute)];

            Assert.NotNull(ra);
            Assert.False(ra.AllowEmptyStrings);

            // verify association attribute
            AssociationAttribute aa = (AssociationAttribute)properties["Category"].Attributes[typeof(AssociationAttribute)];

            Assert.NotNull(aa);
            Assert.Equal("Category_Product", aa.Name);
            Assert.True(aa.IsForeignKey);
            Assert.Equal("CategoryID", aa.ThisKey);
            Assert.Equal("CategoryID", aa.OtherKey);

            // verify metadata from "buddy class"
            PropertyDescriptor pd = properties["QuantityPerUnit"];

            sla = (StringLengthAttribute)pd.Attributes[typeof(StringLengthAttribute)];
            Assert.NotNull(sla);
            Assert.Equal(777, sla.MaximumLength);
            EditableAttribute ea = (EditableAttribute)pd.Attributes[typeof(EditableAttribute)];

            Assert.False(ea.AllowEdit);
            Assert.True(ea.AllowInitialValue);
        }
        public static IHtmlString Metadata <TDataController>(this HtmlHelper htmlHelper) where TDataController : DataController
        {
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor
            {
                Configuration  = GlobalConfiguration.Configuration, // This helper can't be run until after global app init.
                ControllerType = typeof(TDataController)
            };

            DataControllerDescription description = DataControllerDescription.GetDescription(controllerDescriptor);
            IEnumerable <DataControllerMetadataGenerator.TypeMetadata> metadata =
                DataControllerMetadataGenerator.GetMetadata(description);

            JToken metadataValue = new JObject(metadata.Select(
                                                   m => new JProperty(m.EncodedTypeName, m.ToJToken())));

            return(htmlHelper.Raw(metadataValue));
        }
Exemple #13
0
        public void Submit_ResolveActions_UnsupportedAction()
        {
            Product product = new Product {
                ProductID = 1, ProductName = "Choco Wafers"
            };

            ChangeSetEntry[] changeSet = new ChangeSetEntry[] {
                new ChangeSetEntry {
                    Id = 1, Entity = product, Operation = ChangeOperation.Delete
                }
            };

            HttpConfiguration         configuration        = new HttpConfiguration();
            HttpControllerDescriptor  controllerDescriptor = new HttpControllerDescriptor(configuration, "NorthwindEFTestController", typeof(NorthwindEFTestController));
            DataControllerDescription description          = DataControllerDescription.GetDescription(controllerDescriptor);

            Assert.Throws <InvalidOperationException>(
                () => DataController.ResolveActions(description, changeSet),
                String.Format(Resource.DataController_InvalidAction, "Delete", "Product"));
        }
Exemple #14
0
 public static IDictionary <string, TypeMetadata> GetMetadata(DataControllerDescription description)
 {
     //return GenerateMetadata(description);
     return(MetadataMap.GetOrAdd(description, GenerateMetadata));
 }
Exemple #15
0
 public static IDictionary <string, TypeMetadata> GetMetadata(HttpControllerDescriptor controllerDescriptor)
 {
     return(GetMetadata(DataControllerDescription.GetDescription(controllerDescriptor)));
 }