public PropertyMedata_with_Person() { var query = new QueryFluentMetadata(); firstName = query.GetMetadataFor(typeof(Person), "FirstName"); lastName = query.GetMetadataFor(typeof(Person), "LastName"); }
public PropertyMedata_with_WebUser() { var query = new QueryFluentMetadata(); username = query.GetMetadataFor(typeof(WebUser), "Username"); id = query.GetMetadataFor(typeof(WebUser), "Id"); }
public DerivedDerivedClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(DerivedDerivedClass), "Id"); title = query.GetMetadataFor(typeof(DerivedDerivedClass), "Title"); }
public PropertyMedata_with_WebUserIndexModel() { var query = new QueryFluentMetadata(); username = query.GetMetadataFor(typeof(WebUserIndexModel), "Username"); id = query.GetMetadataFor(typeof(WebUserIndexModel), "Id"); autorName = query.GetMetadataFor(typeof(WebUserIndexModel), "AutorName"); }
public override IEnumerable <ModelMetadata> GetMetadataForProperties(object container, Type containerType) { Metadata classMetadata = query.GetMetadataFor(containerType); foreach (var metadata in classMetadata.Properties) { yield return(new FluentModelMetadata(metadata, this, GetProperyAccessor(container, metadata))); } }
internal void MapProperties(Type instanceType, StructuralTypeConfiguration configuration) { var metaDatas = query.GetMetadataFor(instanceType).Properties; foreach (var data in metaDatas) { if (data.ModelName == null) { continue; } if (!data.StringLength.HasValue && !data.Required.HasValue) { continue; } var methodInfo = methodMapping.GetPropertyMappingMethod(configuration.GetType(), instanceType, data.ModelType); if (methodInfo == null) { continue; } var lambda = generator.CreateExpressionForProperty(instanceType, data.ModelName); if (lambda != null) { var propertyConfiguration = (PropertyConfiguration)methodInfo.Invoke(configuration, new[] { lambda }); factory.Create(propertyConfiguration).Convert(data, propertyConfiguration); } } }
internal void MapProperties <T>(StructuralTypeConfiguration <T> configuration) where T : class { var metaDatas = QueryFluentMetadata.GetMetadataFor(typeof(T)).Properties; foreach (var data in metaDatas) { if (data.ModelName == null) { continue; } if (!data.GetMaximumLength().HasValue&& !data.Required.HasValue) { continue; } var methodInfo = PropertyMethodMapping.GetPropertyMappingMethod( configuration.GetType(), typeof(T), data.ModelType); if (methodInfo == null) { continue; } var lambda = ExpressionGenerator.CreateExpressionForProperty(typeof(T), data.ModelName); if (lambda != null) { var propertyConfiguration = (PrimitivePropertyConfiguration)methodInfo.Invoke(configuration, new[] { lambda }); factory.Create(propertyConfiguration).Convert(data, propertyConfiguration); } } }
public PropertyMedata_with_WebUser() { username = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Username"); id = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Id"); lastLogin = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "LastLogin"); passWordHash = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "PasswordHash"); role = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Role"); bounceCount = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "BounceCount"); }
public PropertyMedata_with_WebUserIndexGetModel() { username = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Username"); id = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Id"); email = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "EMail"); autorName = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "AutorName"); role = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Role"); secondaryRoles = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "SecondaryRoles"); passwordHash = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "PasswordHash"); }
public void Apply(IPropertyInstance instance) { var meta = query.GetMetadataFor(instance.EntityType, instance.Property.Name); if (meta.Required.HasValue) { ApplyRequired(meta.Required.Value, instance); } if (meta.StringLength.HasValue) { ApplyStringLength(meta.StringLength.Value, instance); } }
public When_FluentMetadataBuilder_builds_metadata_copying_from_other_metadata_that_does_not_apply() { FluentMetadataBuilder.Reset(); try { FluentMetadataBuilder.BuildMetadataDefinitions(GetUnbuildableMetadataDefinitions()); someViewModelRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel)).Rules; someViewModelMyPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyProperty").Rules; } catch (Exception ex) { exception = ex; } }
/// <summary> /// Gets a <see cref="T:System.Web.Mvc.ModelMetadata"/> object for each property of a model. /// </summary> /// <param name="container">The container.</param> /// <param name="containerType">The type of the container.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for each property of a model. /// </returns> public override IEnumerable <ModelMetadata> GetMetadataForProperties(object container, Type containerType) { var publicProps = containerType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var propertyMetadata in QueryFluentMetadata.GetMetadataFor(containerType).Properties) { var props = publicProps.Where(p => p.Name == propertyMetadata.ModelName).ToArray(); var prop = props.Length > 1 ? props.GetHiding() : props.SingleOrDefault(); if (prop != null) { yield return(new FluentModelMetadata(propertyMetadata, this, () => prop.GetValue(container, null))); } } }
public When_copying_metadata_from_an_AutoMapped_Type() { FluentMetadataBuilder.Reset(); Mapper.Reset(); Mapper.Initialize(cfg => { cfg.ShouldMapProperty = pi => true; //in order to test NonPublic member mapping as well cfg.CreateMap <Source, Destination>() .ForMember(d => d.Renamed, o => o.MapFrom(s => s.Named)) .ForMember(d => d.IntProperty, o => o.ResolveUsing <FakeResolver, string>(s => s.StringField)); }); Mapper.AssertConfigurationIsValid(); FluentMetadataBuilder.ForAssemblyOfType <Source>(); destinationMetadata = QueryFluentMetadata.GetMetadataFor(typeof(Destination)); }
public When_FluentMetadataBuilder_builds_metadata_copying_from_other_metadata() { FluentMetadataBuilder.Reset(); var typesToBuildInLaterBatch = new[] { typeof(SomeTypeInAnotherAssemblyMetadata) }; try { FluentMetadataBuilder.BuildMetadataDefinitions( GetUnbuildableMetadataDefinitions() .Except(typesToBuildInLaterBatch)); FluentMetadataBuilder.BuildMetadataDefinitions(typesToBuildInLaterBatch); someViewModelRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel)).Rules; someViewModelMyPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyProperty").Rules; someViewModelMyStringPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyStringProperty").Rules; } catch (Exception ex) { exception = ex; } }
public void Content_Title_Is_Required() { var metaData = query.GetMetadataFor(typeof(Content), "Title"); Assert.True(metaData.Required.Value); }
public ClassMetadata_with_WebUser() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(WebUser)); }
public ClassMetadata_with_WebUserIndexModel() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(WebUserIndexModel)); }
public DerivedDerivedClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(DerivedDerivedClass), "Id"); title = query.GetMetadataFor(typeof(DerivedDerivedClass), "Title"); }
public ClassMetadata_with_Person() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(Person)); }
public PropertyMedata_with_Person() { var query = new QueryFluentMetadata(); firstName = query.GetMetadataFor(typeof (Person), "FirstName"); lastName = query.GetMetadataFor(typeof (Person), "LastName"); }
/// <summary> /// Gets metadata for the specified property. /// </summary> /// <param name="modelAccessor">The model accessor.</param> /// <param name="containerType">The type of the container.</param> /// <param name="propertyName">The property to get the metadata model for.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for the property. /// </returns> public override ModelMetadata GetMetadataForProperty(Func <object> modelAccessor, Type containerType, string propertyName) => new FluentModelMetadata(QueryFluentMetadata.GetMetadataFor(containerType, propertyName), this, modelAccessor);
public BaseClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(BaseClass), "Id"); }
public ClassMetadata_with_WebUserIndexModel() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexModel)); }
public ClassMetadata_with_Person() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof (Person)); }
public ClassMetadata_with_Person() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(Person)); }
public BaseClass_Tests() { id = QueryFluentMetadata.GetMetadataFor(typeof(BaseClass), "Id"); }
public PropertyMedata_with_Person() { firstName = QueryFluentMetadata.GetMetadataFor(typeof(Person), "FirstName"); lastName = QueryFluentMetadata.GetMetadataFor(typeof(Person), "LastName"); }
public BaseClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(BaseClass), "Id"); }
public ClassMetadata_with_WebUser() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(WebUser)); }
public DerivedDerivedClass_Tests() { id = QueryFluentMetadata.GetMetadataFor(typeof(DerivedDerivedClass), "Id"); title = QueryFluentMetadata.GetMetadataFor(typeof(DerivedDerivedClass), "Title"); }
/// <summary> /// Gets metadata for the specified model accessor and model type. /// </summary> /// <param name="modelAccessor">The model accessor.</param> /// <param name="modelType">The type of the model.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for the specified model accessor and model type. /// </returns> public override ModelMetadata GetMetadataForType(Func <object> modelAccessor, Type modelType) => new FluentModelMetadata(QueryFluentMetadata.GetMetadataFor(modelType), this, modelAccessor);
public PropertyMedata_with_WebUser() { var query = new QueryFluentMetadata(); username = query.GetMetadataFor(typeof(WebUser), "Username"); id = query.GetMetadataFor(typeof(WebUser), "Id"); }