private bool HasExplicitTypeConvention(Member property) { // todo: clean this up! // What it's doing is finding if there are any IUserType conventions // that would be applied to this property, if there are then we should // definitely automap it. The nasty part is that right now we don't have // a model, so we're having to create a fake one so the convention will // apply to it. var conventions = conventionFinder .Find<IPropertyConvention>() .Where(c => { if (!typeof(IUserTypeConvention).IsAssignableFrom(c.GetType())) return false; var criteria = new ConcreteAcceptanceCriteria<IPropertyInspector>(); var acceptance = c as IConventionAcceptance<IPropertyInspector>; if (acceptance != null) acceptance.Accept(criteria); var propertyMapping = new PropertyMapping { Member = property }; propertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(property.PropertyType)); return criteria.Matches(new PropertyInspector(propertyMapping)); }); return conventions.FirstOrDefault() != null; }
public void CanAddProperty() { var property = new PropertyMapping { Name = "Property1" }; compositeElementMapping.AddProperty(property); compositeElementMapping.Properties.ShouldContain(property); }
public void CanAddProperty() { var property = new PropertyMapping { Name = "Property1" }; _classMapping.AddProperty(property); _classMapping.Properties.ShouldContain(property); }
public void Should_not_write_the_default_access_type() { var property = new PropertyMapping(); _writer.VerifyXml(property) .DoesntHaveAttribute("access"); }
public PropertyInspector(PropertyMapping mapping) : base(mapping.Columns) { this.mapping = mapping; propertyMappings.Map(x => x.LazyLoad, x => x.Lazy); propertyMappings.Map(x => x.Nullable, "NotNull"); }
public void CanAddProperty() { var property = new PropertyMapping(); property.Set(x => x.Name, Layer.Defaults, "Property1"); mapping.AddProperty(property); mapping.Properties.ShouldContain(property); }
public void Should_write_the_specified_access_type() { var property = new PropertyMapping(); property.MemberAccess = MemberAccess.Create(AccessStrategy.Field, NamingStrategy.CamelCase); _writer.VerifyXml(property) .HasAttribute("access", "field.camelcase"); }
public void ShouldWriteColumns() { var mapping = new PropertyMapping(); mapping.AddColumn(new ColumnMapping { Name = "Column1" }); writer.VerifyXml(mapping) .Element("column").Exists(); }
public void ExpectNotEqualShouldValidateToFalseIfNotGivenMatchingModel() { acceptance.Expect(x => x.Access != Access.Field); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Access, Layer.Defaults, "field"); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); }
public void IsNotAnySucceedsIfNoValuesMatch() { acceptance.Expect(x => x.Access.IsNotAny(Access.Property, Access.Field)); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Access, Layer.Defaults, Access.CamelCaseField().ToString()); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void ExpectNotEqualShouldValidateToFalseIfNotGivenMatchingModel() { acceptance.Expect(x => x.Insert != true); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); }
public void DefaultColumnShouldInheritColumnAttributes() { var mapping = new PropertyMapping(); new PropertyBuilder(mapping, typeof(PropertyTarget), Prop(x => x.Name)) .Not.Nullable(); mapping.Columns.Defaults.First().NotNull.ShouldBeTrue(); mapping.Columns.First().NotNull.ShouldBeTrue(); }
public void ShouldHaveDefaultColumnIfNoneSpecified() { var mapping = new PropertyMapping(); new PropertyBuilder(mapping, typeof(PropertyTarget), Prop(x => x.Name)); mapping.Columns.Defaults.Count().ShouldEqual(1); mapping.Columns.UserDefined.Count().ShouldEqual(0); mapping.Columns.Count().ShouldEqual(1); }
public void ExpectOnPropertyShouldValidateToTrueIfGivenMatchingModel() { acceptance.Expect(x => x.Insert, Is.Set); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void ShouldHaveNoDefaultsIfUserSpecifiedColumn() { var mapping = new PropertyMapping(); new PropertyBuilder(mapping, typeof(PropertyTarget), Prop(x => x.Name)) .Column("explicit"); mapping.Columns.Defaults.Count().ShouldEqual(0); mapping.Columns.UserDefined.Count().ShouldEqual(1); mapping.Columns.Count().ShouldEqual(1); }
public void MultipleExpectsShouldValidateToFalseIfOnlyOneMatches() { acceptance.Expect(x => x.Insert, Is.Set); acceptance.Expect(x => x.Update, Is.Set); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); }
public void CollectionContainsWithLambdaShouldBeTrueWhenItemsMatching() { acceptance .Expect(x => x.Columns.Contains(c => c.Name == "Column1")); var mapping = new PropertyMapping(); mapping.AddColumn(new ColumnMapping { Name = "Column1" }); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeTrue(); }
public void CollectionIsEmptyShouldBeFalseWithItemsWhenUsingExpression() { acceptance .Expect(x => x.Columns.IsEmpty()); var mapping = new PropertyMapping(); mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1")); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeFalse(); }
public void CollectionIsNotEmptyShouldBeTrueWithItemsWhenUsingExpression() { acceptance .Expect(x => x.Columns.IsNotEmpty()); var mapping = new PropertyMapping(); mapping.AddColumn(new ColumnMapping { Name = "Column1" }); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeTrue(); }
public void CollectionContainsWithStringShouldBeFalseWhenNoItemsMatching() { acceptance .Expect(x => x.Columns.Contains("boo")); var mapping = new PropertyMapping(); mapping.AddColumn(new ColumnMapping { Name = "Column1" }); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeFalse(); }
public void ExpectShouldEvaluateSubPropertyWithEvaluation() { acceptance.Expect(x => x.Type.Name == typeof(Record).Name); var propertyMapping = new PropertyMapping { Member = ReflectionHelper.GetMember<Record>(x => x.Age), }; propertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(Record))); acceptance.Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void AnyShouldValidateToTrueIfOneMatches() { acceptance .Any(c => c.Expect(x => x.Name, Is.Set), c => c.Expect(x => x.Type, Is.Set), c => c.Expect(x => x.Insert, Is.Set)); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1"); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public bool Equals(PropertyMapping other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(base.Equals(other) && Equals(other.ContainingEntityType, ContainingEntityType) && Equals(other.Member, Member)); }
public void CanPassSubCriteriaToAny() { var subCriteria1 = new ConcreteAcceptanceCriteria<IPropertyInspector>(); subCriteria1.Expect(x => x.Name, Is.Set); var subCriteria2 = new ConcreteAcceptanceCriteria<IPropertyInspector>(); subCriteria2.Expect(x => x.Type, Is.Set); acceptance.Any(subCriteria1, subCriteria2); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1"); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void Map(ClassMapping classMap) { foreach(var property in classMap.Type.GetProperties()) { if (!classMap.HasMappedProperty(property)) { if (property.PropertyType.Namespace == "System") { var propMapping = new PropertyMapping {Name = property.Name}; propMapping.BindToMember(property); classMap.AddProperty(propMapping); } } } }
private PropertyMapping GetPropertyMapping(Type type, Member property) { var mapping = new PropertyMapping { ContainingEntityType = type, Member = property }; mapping.AddDefaultColumn(new ColumnMapping { Name = property.Name }); if (!mapping.IsSpecified("Name")) mapping.Name = mapping.Member.Name; if (!mapping.IsSpecified("Type")) mapping.SetDefaultValue("Type", GetDefaultType(property)); return mapping; }
public void IsNotAnyFailsIfAnyOfTheSuppliedValuesMatch() { acceptance.Expect(x => x.Access.IsNotAny(Access.Property, Access.Field)); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Access, Layer.Defaults, Access.Field.ToString()); var propertyMapping2 = new PropertyMapping(); propertyMapping2.Set(x => x.Access, Layer.Defaults, Access.Property.ToString()); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); acceptance .Matches(new PropertyInspector(propertyMapping2)) .ShouldBeFalse(); }
private PropertyMapping GetPropertyMapping(Type type, Member property) { var mapping = new PropertyMapping { ContainingEntityType = type, Member = property }; var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, property.Name); mapping.AddColumn(Layer.Defaults, columnMapping); mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name); mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType(property)); SetDefaultAccess(property, mapping); return mapping; }
private PropertyMapping GetPropertyMapping(Type type, Member property, ComponentMapping component) { var mapping = new PropertyMapping { ContainingEntityType = type, Member = property }; var columnName = property.Name; if (component != null) columnName = cfg.GetComponentColumnPrefix(component.Member) + columnName; mapping.AddDefaultColumn(new ColumnMapping { Name = columnName }); if (!mapping.IsSpecified("Name")) mapping.Name = mapping.Member.Name; if (!mapping.IsSpecified("Type")) mapping.SetDefaultValue("Type", GetDefaultType(property)); return mapping; }
private PropertyMapping GetPropertyMapping(Type type, PropertyInfo property, ComponentMapping component) { var mapping = new PropertyMapping { ContainingEntityType = type, PropertyInfo = property }; var columnName = property.Name; if (component != null) columnName = expressions.GetComponentColumnPrefix(component.PropertyInfo) + columnName; mapping.AddDefaultColumn(new ColumnMapping { Name = columnName }); if (!mapping.IsSpecified(x => x.Name)) mapping.Name = mapping.PropertyInfo.Name; if (!mapping.IsSpecified(x => x.Type)) mapping.SetDefaultValue(x => x.Type, new TypeReference(mapping.PropertyInfo.PropertyType)); return mapping; }
public void AddOrReplaceProperty(PropertyMapping mapping) { properties.RemoveAll(x => x.Name == mapping.Name); properties.Add(mapping); }
protected PropertyMapping property_with_column(string column) { var property = new PropertyMapping(); property.AddDefaultColumn(new ColumnMapping { Name = "propertyColumn" }); return property; }
public override void Visit(PropertyMapping propertyMapping) { propertyMapping.AcceptVisitor(this); }
public virtual void ProcessProperty(PropertyMapping propertyMapping) { }
public virtual void Visit(PropertyMapping propertyMapping) { }
public void AddOrReplaceProperty(PropertyMapping mapping) { AddOrReplaceMapping(mapping, MappingType.Property, x => x.Name == mapping.Name); }
public void AddProperty(PropertyMapping mapping) { properties.Add(mapping); }
public void AddProperty(PropertyMapping property) { mappedMembers.AddProperty(property); }