public void ShouldWriteBag()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(new BagMapping());

            writer.VerifyXml(mapping)
                .Element("bag").Exists();
        }
Beispiel #2
0
        public void ShouldWriteBag()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(CollectionMapping.Bag());

            writer.VerifyXml(mapping)
            .Element("bag").Exists();
        }
        public void ShouldWriteList()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(new ListMapping());

            writer.VerifyXml(mapping)
            .Element("list").Exists();
        }
        public void ShouldWriteMap()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(new MapMapping());

            writer.VerifyXml(mapping)
            .Element("map").Exists();
        }
        public void CanAddBag()
        {
            var bag = new BagMapping
            {
                Name         = "bag1",
                Key          = new KeyMapping(),
                Relationship = new OneToManyMapping {
                    Class = new TypeReference("class1")
                }
            };

            _classMapping.AddCollection(bag);

            _classMapping.Collections.ShouldContain(bag);
        }
Beispiel #6
0
        ClassMapping IMappingProvider.GetClassMapping()
        {
            var mapping = new ClassMapping(attributes.CloneInner());

            mapping.Type = typeof(T);
            mapping.Name = typeof(T).AssemblyQualifiedName;

            foreach (var property in properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            if (version != null)
            {
                mapping.Version = version.GetVersionMapping();
            }

            foreach (var oneToOne in oneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

            foreach (var collection in collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var reference in references)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            foreach (var subclass in subclasses.Values)
            {
                mapping.AddSubclass(subclass.GetSubclassMapping());
            }

            foreach (var join in joins)
            {
                mapping.AddJoin(join);
            }

            if (discriminator != null)
            {
                mapping.Discriminator = ((IDiscriminatorMappingProvider)discriminator).GetDiscriminatorMapping();
            }

            if (Cache.IsDirty)
            {
                mapping.Cache = ((ICacheMappingProvider)Cache).GetCacheMapping();
            }

            if (id != null)
            {
                mapping.Id = id.GetIdentityMapping();
            }

            if (compositeId != null)
            {
                mapping.Id = compositeId.GetCompositeIdMapping();
            }

            if (naturalId != null)
            {
                mapping.NaturalId = naturalId.GetNaturalIdMapping();
            }

            if (!mapping.IsSpecified("TableName"))
            {
                mapping.SetDefaultValue(x => x.TableName, GetDefaultTableName());
            }

            foreach (var filter in filters)
            {
                mapping.AddFilter(filter.GetFilterMapping());
            }

            foreach (var storedProcedure in storedProcedures)
            {
                mapping.AddStoredProcedure(storedProcedure.GetStoredProcedureMapping());
            }

            mapping.Tuplizer = tuplizerMapping;

            return(mapping);
        }
        public void ShouldWriteSet()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(new SetMapping());

            writer.VerifyXml(mapping)
                .Element("set").Exists();
        }
Beispiel #8
0
 public void CollectionsCollectionHasSameCountAsMapping()
 {
     mapping.AddCollection(new BagMapping());
     inspector.Collections.Count().ShouldEqual(1);
 }
Beispiel #9
0
        ClassMapping IMappingProvider.GetClassMapping()
        {
            var mapping = new ClassMapping(attributes.Clone());

            mapping.Set(x => x.Type, Layer.Defaults, typeof(T));
            mapping.Set(x => x.Name, Layer.Defaults, typeof(T).AssemblyQualifiedName);

            foreach (var property in providers.Properties)
            {
                mapping.AddProperty(property.GetPropertyMapping());
            }

            foreach (var component in providers.Components)
            {
                mapping.AddComponent(component.GetComponentMapping());
            }

            if (providers.Version != null)
            {
                mapping.Set(x => x.Version, Layer.Defaults, providers.Version.GetVersionMapping());
            }

            foreach (var oneToOne in providers.OneToOnes)
            {
                mapping.AddOneToOne(oneToOne.GetOneToOneMapping());
            }

            foreach (var collection in providers.Collections)
            {
                mapping.AddCollection(collection.GetCollectionMapping());
            }

            foreach (var reference in providers.References)
            {
                mapping.AddReference(reference.GetManyToOneMapping());
            }

            foreach (var any in providers.Anys)
            {
                mapping.AddAny(any.GetAnyMapping());
            }

            foreach (var subclass in providers.Subclasses.Values)
            {
                mapping.AddSubclass(subclass.GetSubclassMapping());
            }

            foreach (var join in providers.Joins)
            {
                mapping.AddJoin(join.GetJoinMapping());
            }

            if (providers.Discriminator != null)
            {
                mapping.Set(x => x.Discriminator, Layer.Defaults, providers.Discriminator.GetDiscriminatorMapping());
            }

            if (Cache.IsDirty)
            {
                mapping.Set(x => x.Cache, Layer.Defaults, ((ICacheMappingProvider)Cache).GetCacheMapping());
            }

            if (providers.Id != null)
            {
                mapping.Set(x => x.Id, Layer.Defaults, providers.Id.GetIdentityMapping());
            }

            if (providers.CompositeId != null)
            {
                mapping.Set(x => x.Id, Layer.Defaults, providers.CompositeId.GetCompositeIdMapping());
            }

            if (providers.NaturalId != null)
            {
                mapping.Set(x => x.NaturalId, Layer.Defaults, providers.NaturalId.GetNaturalIdMapping());
            }

            mapping.Set(x => x.TableName, Layer.Defaults, GetDefaultTableName());

            foreach (var filter in providers.Filters)
            {
                mapping.AddFilter(filter.GetFilterMapping());
            }

            foreach (var storedProcedure in providers.StoredProcedures)
            {
                mapping.AddStoredProcedure(storedProcedure.GetStoredProcedureMapping());
            }

            mapping.Set(x => x.Tuplizer, Layer.Defaults, providers.TuplizerMapping);

            return(mapping);
        }
        public void ShouldWriteList()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(CollectionMapping.List());

            writer.VerifyXml(mapping)
                .Element("list").Exists();
        }
Beispiel #11
0
        ClassMapping IMappingProvider.GetClassMapping()
        {
            var mapping = new ClassMapping(attributes.Clone());

            mapping.Set(x => x.Type, Layer.Defaults, typeof(T));
            mapping.Set(x => x.Name, Layer.Defaults, typeof(T).AssemblyQualifiedName);

            if (providers.Version != null)
            {
                mapping.Set(x => x.Version, Layer.Defaults, providers.Version.GetVersionMapping());
            }

            foreach (var provider in providers.OrderedProviders)
            {
                var x = provider.Item2;
                switch (provider.Item1)
                {
                case MappingProviderStore.ProviderType.Property:
                    mapping.AddProperty(((IPropertyMappingProvider)x).GetPropertyMapping());
                    break;

                case MappingProviderStore.ProviderType.Component:
                    mapping.AddComponent(((IComponentMappingProvider)x).GetComponentMapping());
                    break;

                case MappingProviderStore.ProviderType.OneToOne:
                    mapping.AddOneToOne(((IOneToOneMappingProvider)x).GetOneToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Subclass:
                    mapping.AddSubclass(((ISubclassMappingProvider)x).GetSubclassMapping());
                    break;

                case MappingProviderStore.ProviderType.Collection:
                    mapping.AddCollection(((ICollectionMappingProvider)x).GetCollectionMapping());
                    break;

                case MappingProviderStore.ProviderType.ManyToOne:
                    mapping.AddReference(((IManyToOneMappingProvider)x).GetManyToOneMapping());
                    break;

                case MappingProviderStore.ProviderType.Any:
                    mapping.AddAny(((IAnyMappingProvider)x).GetAnyMapping());
                    break;

                case MappingProviderStore.ProviderType.Filter:
                    mapping.AddFilter(((IFilterMappingProvider)x).GetFilterMapping());
                    break;

                case MappingProviderStore.ProviderType.StoredProcedure:
                    mapping.AddStoredProcedure(((IStoredProcedureMappingProvider)x).GetStoredProcedureMapping());
                    break;

                case MappingProviderStore.ProviderType.Join:
                    mapping.AddJoin(((IJoinMappingProvider)x).GetJoinMapping());
                    break;

                case MappingProviderStore.ProviderType.Identity:
                    mapping.Set(y => y.Id, Layer.Defaults, ((IIdentityMappingProvider)x).GetIdentityMapping());
                    break;

                case MappingProviderStore.ProviderType.CompositeId:
                    mapping.Set(y => y.Id, Layer.Defaults, ((ICompositeIdMappingProvider)x).GetCompositeIdMapping());
                    break;

                case MappingProviderStore.ProviderType.NaturalId:
                    mapping.Set(y => y.NaturalId, Layer.Defaults, ((INaturalIdMappingProvider)x).GetNaturalIdMapping());
                    break;

                case MappingProviderStore.ProviderType.Version:
                    mapping.Set(y => y.Version, Layer.Defaults, ((IVersionMappingProvider)x).GetVersionMapping());
                    break;

                case MappingProviderStore.ProviderType.Discriminator:
                    mapping.Set(y => y.Discriminator, Layer.Defaults, ((IDiscriminatorMappingProvider)x).GetDiscriminatorMapping());
                    break;

                case MappingProviderStore.ProviderType.Tupilizer:
                    mapping.Set(y => y.Tuplizer, Layer.Defaults, (TuplizerMapping)x);
                    break;

                default:
                    throw new Exception("Internal Error");
                }
            }

            if (Cache.IsDirty)
            {
                mapping.Set(x => x.Cache, Layer.Defaults, ((ICacheMappingProvider)Cache).GetCacheMapping());
            }

            mapping.Set(x => x.TableName, Layer.Defaults, GetDefaultTableName());

            mapping.Set(x => x.Tuplizer, Layer.Defaults, providers.TuplizerMapping);

            return(mapping);
        }