Inheritance: ClassMappingBase
        private SubclassMapping CreateSubclass(ClassMapping mapping)
        {
            if (mapping.Discriminator == null)
                return new SubclassMapping(SubclassType.JoinedSubclass);

            return new SubclassMapping(SubclassType.Subclass);
        }
        public override void ProcessClass(ClassMapping mapping)
        {
            var subclasses = FindClosestSubclasses(mapping.Type, mapping.EntityName);

            foreach (var provider in subclasses)
                mapping.AddSubclass(provider.GetSubclassMapping(GetSubclassType(mapping)));

            base.ProcessClass(mapping);
        }
        public void CanMapManyToManyProperty()
        {
            var Member = ReflectionHelper.GetProperty<ManyToMany1>(x => x.Many1).ToMember();
            var autoMap = new ClassMapping();

            var mapper = new AutoMapManyToMany(new AutoMappingExpressions());
            mapper.Map(autoMap, Member);

            autoMap.Collections.ShouldHaveCount(1);
        }
 public override void ProcessClass(ClassMapping classMapping)
 {
     if (!Enabled) return;
     if (classMapping.Id == null)
         throw new ValidationException(
             string.Format("The entity '{0}' doesn't have an Id mapped.", classMapping.Type.Name),
             "Use the Id method to map your identity property. For example: Id(x => x.Id)",
             classMapping.Type
         );
 }
        public void CanMapManyToManyProperty()
        {
            var Member = ReflectionHelper.GetMember<ManyToMany1>(x => x.Many1);
            var autoMap = new ClassMapping();

            var mapper = new HasManyToManyStep(new DefaultAutomappingConfiguration());
            mapper.Map(autoMap, Member);

            autoMap.Collections.ShouldHaveCount(1);
        }
        public void IdentityStepShouldProvideAnAccessValueThatIsADefaultOnly()
        {
            IdentityStep step = new IdentityStep(new DefaultAutomappingConfiguration());

            var classMapping = new ClassMapping() {Type = typeof(ClassWithIdFieldAndGetter)};
            step.Map(classMapping, ReflectionHelper.GetMember<ClassWithIdFieldAndGetter>(x => x.Id));

            var idMapping = (IdMapping) classMapping.Id;
            idMapping.HasValue("Access").ShouldBeTrue();
            idMapping.IsSpecified(x => x.Access).ShouldBeFalse();
        }
        public void ShouldMapHashSetAsSet()
        {
            var classMapping = new ClassMapping()
            {
                Type = typeof(PropertyTarget)
            };

            mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("HashSet").ToMember());

            classMapping.Collections
                .First().ShouldBeOfType(typeof(SetMapping));
        }
        public void ShouldMapListAsBag()
        {
            var classMapping = new ClassMapping()
            {
                Type = typeof(PropertyTarget)
            };

            mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("List"));

            classMapping.Collections
                .First().ShouldBeOfType(typeof(BagMapping));
        }
        private SubclassType GetSubclassType(ClassMapping mapping)
        {
            if (mapping.IsUnionSubclass)
            {
                return SubclassType.UnionSubclass;
            }

            if (mapping.Discriminator == null)
                return SubclassType.JoinedSubclass;

            return SubclassType.Subclass;
        }
        public void SetUp()
        {
            PersistenceModel model = new PersistenceModel();
            model.Conventions.Add(new BackfieldAccessConvention());

            model.Add(new CompositeIdModelMapping());
            model.Add(new ManyToManyModelMapping());
            model.Add(new ManyToOneModelMapping());
            model.Add(new OneToOneModelMapping());
            model.Add(new ParentModelMapping());

            var classMappings = model.BuildMappings().SelectMany(x => x.Classes).ToDictionary(x => x.Type);
            compositeId = classMappings[typeof(CompositeIdModel)];
            manyToMany = classMappings[typeof(ManyToManyModel)];
            manyToOne = classMappings[typeof(ManyToOneModel)];
            oneToOne = classMappings[typeof(OneToOneModel)];
            parent = classMappings[typeof(ParentModel)];
        }
 private void CheckFirstFilterWithCondition(ClassMapping mapping)
 {
     CheckFirstFilterWithoutCondition(mapping);
     if (mapping.Filters.First().Condition != "Name = :name") Assert.Fail("Wrong filter condition added");
 }
 private void CheckFirstFilterWithoutCondition(ClassMapping mapping)
 {
     if (mapping.Filters.Count() == 0) Assert.Fail("No filter added");
     if (mapping.Filters.First().Name != "test") Assert.Fail("Wrong filter name added");
 }
 public void MutableShouldBeTrueByDefaultOnClassMapping()
 {
     var mapping = new ClassMapping();
     mapping.Mutable.ShouldBeTrue();
 }