Inheritance: FluentNHibernate.MappingModel.ColumnBasedMappingBase
コード例 #1
0
        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;
        }
コード例 #2
0
        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");
        }
コード例 #5
0
        public PropertyInspector(PropertyMapping mapping)
            : base(mapping.Columns)
        {
            this.mapping = mapping;

            propertyMappings.Map(x => x.LazyLoad, x => x.Lazy);
            propertyMappings.Map(x => x.Nullable, "NotNull");
        }
コード例 #6
0
        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");
        }
コード例 #8
0
        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();
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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();
        }
コード例 #23
0
 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);
                    }
                }
            }
        }
コード例 #26
0
        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();
        }
コード例 #28
0
        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;
        }
コード例 #29
0
        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;
        }
コード例 #30
0
        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;
        }
コード例 #31
0
 public void AddOrReplaceProperty(PropertyMapping mapping)
 {
     properties.RemoveAll(x => x.Name == mapping.Name);
     properties.Add(mapping);
 }
コード例 #32
0
 protected PropertyMapping property_with_column(string column)
 {
     var property = new PropertyMapping();
     property.AddDefaultColumn(new ColumnMapping { Name = "propertyColumn" });
     return property;
 }
コード例 #33
0
 public override void Visit(PropertyMapping propertyMapping)
 {
     propertyMapping.AcceptVisitor(this);
 }
コード例 #34
0
 public virtual void ProcessProperty(PropertyMapping propertyMapping)
 {
 }
コード例 #35
0
 public virtual void Visit(PropertyMapping propertyMapping)
 {
 }
コード例 #36
0
 public void AddOrReplaceProperty(PropertyMapping mapping)
 {
     AddOrReplaceMapping(mapping, MappingType.Property, x => x.Name == mapping.Name);
 }
コード例 #37
0
 public void AddProperty(PropertyMapping mapping)
 {
     properties.Add(mapping);
 }
コード例 #38
0
 public void AddProperty(PropertyMapping property)
 {
     mappedMembers.AddProperty(property);
 }