public void CanSetIdToBeStandardIdMapping() { var idMapping = new IdMapping(); mapping.Set(x => x.Id, Layer.Defaults, idMapping); mapping.Id.ShouldEqual(idMapping); }
public ClassMapping Map(Type classType, List <AutoMapType> types) { var classMap = new ClassMapping(); classMap.Set(x => x.Type, Layer.Defaults, classType); classMap.Set(x => x.Name, Layer.Defaults, classType.AssemblyQualifiedName); classMap.Set(x => x.TableName, Layer.Defaults, GetDefaultTableName(classType)); mappingTypes = types; return((ClassMapping)MergeMap(classType, classMap, new List <Member>())); }
public ClassMapping Map(Type classType, List<AutoMapType> types) { var classMap = new ClassMapping(); classMap.Set(x => x.Type, Layer.Defaults, classType); classMap.Set(x => x.Name, Layer.Defaults, classType.AssemblyQualifiedName); classMap.Set(x => x.TableName, Layer.Defaults, GetDefaultTableName(classType)); mappingTypes = types; return (ClassMapping)MergeMap(classType, classMap, new List<Member>()); }
public void Should_not_pass_null_id_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Id, Layer.Defaults, null); var visitor = A.Fake<IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Id)).MustNotHaveHappened(); }
public void Should_not_pass_null_id_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Id, Layer.Defaults, null); var visitor = MockRepository.GenerateMock<IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Id)).Repeat.Never(); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_not_pass_null_id_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Id, Layer.Defaults, null); var visitor = A.Fake <IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Id)).MustNotHaveHappened(); }
public void Should_pass_the_discriminator_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Discriminator, Layer.Defaults, new DiscriminatorMapping()); var visitor = A.Fake <IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Discriminator)).MustHaveHappened(); }
public void Should_pass_the_discriminator_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Discriminator, Layer.Defaults, new DiscriminatorMapping()); var visitor = MockRepository.GenerateMock <IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Discriminator)); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_not_pass_null_id_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Id, Layer.Defaults, null); var visitor = MockRepository.GenerateMock <IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Id)).Repeat.Never(); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public static void ManyToManySetInverse <TControllingEntity, TInverseEntity>( this ClassMapping <TInverseEntity> classmapping, Expression <Func <TControllingEntity, IEnumerable <TInverseEntity> > > controllingProperty, Expression <Func <TInverseEntity, IEnumerable <TControllingEntity> > > inverseProperty, Action <ISetPropertiesMapper <TInverseEntity, TControllingEntity> > collectionMapping = null, Action <ICollectionElementRelation <TControllingEntity> > mapping = null, string columnformat = "{0}_id", string tableformat = "{0}{1}" ) where TControllingEntity : class where TInverseEntity : class { var controllingPropertyName = controllingProperty.DecodeMemberInfo().Name.ToLowerInvariant(); var controllingColumnName = string.Format(columnformat, typeof(TControllingEntity).Name).ToLowerInvariant(); var inverseColumnName = string.Format(columnformat, controllingPropertyName).ToLowerInvariant(); var tableName = string.Format(tableformat, typeof(TControllingEntity).Name, controllingPropertyName).ToLowerInvariant(); classmapping.Set( inverseProperty, cm => { cm.Table(tableName); cm.Inverse(true); cm.Key(km => km.Column(inverseColumnName)); if (collectionMapping != null) { collectionMapping(cm); } } , t => { t.ManyToMany(c => c.Column(controllingColumnName)); if (mapping != null) { mapping(t); } } ); }
public void ShouldWriteDiscriminator() { var mapping = new ClassMapping(); mapping.Set(x => x.Discriminator, Layer.Defaults, new DiscriminatorMapping()); writer.VerifyXml(mapping) .Element("discriminator").Exists(); }
public void ShouldMapByteArrayAsNotNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember()); mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue(); }
public void ShouldMapByteArrayWithUnsavedValueOfNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember()); mapping.Version.UnsavedValue.ShouldEqual(null); }
public void ShouldMapInheritedByteArray() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(SubTarget)); mapper.Map(mapping, typeof(SubTarget).GetProperty("Version").ToMember()); Assert.That(mapping.Version, Is.Not.Null); }
public void ShouldWriteNaturalId() { var mapping = new ClassMapping(); mapping.Set(x => x.NaturalId, Layer.Defaults, new NaturalIdMapping()); writer.VerifyXml(mapping) .Element("natural-id").Exists(); }
public void ShouldWriteCompositeId() { var mapping = new ClassMapping(); mapping.Set(x => x.Id, Layer.Defaults, new CompositeIdMapping()); writer.VerifyXml(mapping) .Element("composite-id").Exists(); }
public void ShouldWriteCache() { var mapping = new ClassMapping(); mapping.Set(x => x.Cache, Layer.Defaults, new CacheMapping()); writer.VerifyXml(mapping) .Element("cache").Exists(); }
public void ShouldWriteVersion() { var mapping = new ClassMapping(); mapping.Set(x => x.Version, Layer.Defaults, new VersionMapping()); writer.VerifyXml(mapping) .Element("version").Exists(); }
public void ShouldMapByteArrayAsBinaryBlob() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember()); mapping.Version.Type.ShouldEqual(new TypeReference("BinaryBlob")); }
public void ShouldMapByteArrayAsBinaryBlob() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember <BaseEntityClass>(x => x.Version)); mapping.Version.Type.ShouldEqual(new TypeReference("BinaryBlob")); }
public void ShouldMapByteArrayAsNotNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember <BaseEntityClass>(x => x.Version)); mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue(); }
public void ShouldMapByteArrayWithUnsavedValueOfNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember <BaseEntityClass>(x => x.Version)); mapping.Version.UnsavedValue.ShouldEqual(null); }
public void ShouldSetContainingEntityType() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember()); mapping.Version.ContainingEntityType.ShouldEqual(typeof(Target)); }
public void ShouldMapHashSetAsSet() { var classMapping = new ClassMapping(); classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget)); mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("HashSet").ToMember()); classMapping.Collections .First().Collection.ShouldEqual(Collection.Set); }
public void Should_pass_stored_procedure_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddStoredProcedure(new StoredProcedureMapping()); var visitor = A.Fake <IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.StoredProcedures.First())).MustHaveHappened(); }
public void Should_choose_UnionSubclass_when_the_class_mapping_IsUnionSubclass_is_true() { fooMapping = ((IMappingProvider) new BaseMap()).GetClassMapping(); fooMapping.Set(x => x.IsUnionSubclass, Layer.Defaults, true); providers.Add(new StringFooMap()); var sut = CreateSut(); sut.ProcessClass(fooMapping); fooMapping.Subclasses.First().SubclassType.ShouldEqual(SubclassType.UnionSubclass); }
public void Should_pass_subclasses_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddSubclass(new SubclassMapping(SubclassType.JoinedSubclass)); var visitor = MockRepository.GenerateMock <IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Subclasses.First())); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_pass_stored_procedure_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddStoredProcedure(new StoredProcedureMapping()); var visitor = MockRepository.GenerateMock <IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.StoredProcedures.First())); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_pass_subclasses_to_the_visitor() { // FakeItEasy ;for some reason; calls ToString method on SubClassMapping // which ended in NullPointerException if AttributeStore didn't contain Type attribute. var attributeStore = new AttributeStore(); attributeStore.Set("Type", 0, typeof(object)); var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddSubclass(new SubclassMapping(SubclassType.JoinedSubclass, attributeStore)); var visitor = A.Fake <IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Subclasses.First())).MustHaveHappened(); }
public void Table(string tableName) { mapping.Set(x => x.TableName, Layer.Conventions, tableName); }
public void ShouldMapByteArrayWithUnsavedValueOfNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version)); mapping.Version.UnsavedValue.ShouldEqual(null); }
public void ShouldMapByteArrayAsNotNull() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version)); mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue(); }
public void ShouldMapByteArrayAsBinaryBlob() { var mapping = new ClassMapping(); mapping.Set(x => x.Type, Layer.Defaults, typeof(Target)); mapper.Map(mapping, ReflectionHelper.GetMember<BaseEntityClass>(x => x.Version)); mapping.Version.Type.ShouldEqual(new TypeReference("BinaryBlob")); }
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 Should_pass_subclasses_to_the_visitor() { // FakeItEasy ;for some reason; calls ToString method on SubClassMapping // which ended in NullPointerException if AttributeStore didn't contain Type attribute. var attributeStore = new AttributeStore(); attributeStore.Set("Type", 0, typeof(object)); var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddSubclass(new SubclassMapping(SubclassType.JoinedSubclass, attributeStore)); var visitor = A.Fake<IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Subclasses.First())).MustHaveHappened(); }
public void Should_pass_the_discriminator_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Discriminator, Layer.Defaults, new DiscriminatorMapping()); var visitor = A.Fake<IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.Discriminator)).MustHaveHappened(); }
public void Should_pass_stored_procedure_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddStoredProcedure(new StoredProcedureMapping()); var visitor = A.Fake<IMappingModelVisitor>(); classMap.AcceptVisitor(visitor); A.CallTo(() => visitor.Visit(classMap.StoredProcedures.First())).MustHaveHappened(); }
public void Should_pass_stored_procedure_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddStoredProcedure(new StoredProcedureMapping()); var visitor = MockRepository.GenerateMock<IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.StoredProcedures.First())); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_pass_subclasses_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.AddSubclass(new SubclassMapping(SubclassType.JoinedSubclass)); var visitor = MockRepository.GenerateMock<IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Subclasses.First())); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
public void Should_pass_the_discriminator_to_the_visitor() { var classMap = new ClassMapping(); classMap.Set(x => x.Name, Layer.Defaults, "class1"); classMap.Set(x => x.Discriminator, Layer.Defaults, new DiscriminatorMapping()); var visitor = MockRepository.GenerateMock<IMappingModelVisitor>(); visitor.Expect(x => x.Visit(classMap.Discriminator)); classMap.AcceptVisitor(visitor); visitor.VerifyAllExpectations(); }
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); }