public void ToColumnNameWithCustomSeparator() { var level0 = new PropertyPath(null, ForClass<InheritedEntity>.Property(p => p.Component)); var level1 = new PropertyPath(level0, ForClass<MyComponent>.Property(p => p.Component1)); var path = new PropertyPath(level1, ForClass<MyComponent1>.Property(p => p.Something)); path.ToColumnName("_").Should().Be("Component_Component1_Something"); }
public void EqualsLevel2() { var myClassComponent1Path = new PropertyPath(null, myClassComponent1); var myClassComponent2Path = new PropertyPath(null, myClassComponent2); new PropertyPath(myClassComponent1Path, myComponentComponent).Should().Be(new PropertyPath(myClassComponent1Path, myComponentComponent)); new PropertyPath(myClassComponent2Path, myComponentComponent).Should().Not.Be(new PropertyPath(myClassComponent1Path, myComponentComponent)); }
public void WhenCustomSeparatorIsNullThenConcat() { var level0 = new PropertyPath(null, ForClass<InheritedEntity>.Property(p => p.Component)); var level1 = new PropertyPath(level0, ForClass<MyComponent>.Property(p => p.Component1)); var path = new PropertyPath(level1, ForClass<MyComponent1>.Property(p => p.Something)); path.ToColumnName(null).Should().Be("ComponentComponent1Something"); }
public void GetRootFromDeepLevelShouldReturnRootProperty() { var myClassComponent1Path = new PropertyPath(null, myClassComponent1); var myClassComponent1ComponentPath = new PropertyPath(myClassComponent1Path, myComponentComponent); var myClassComponent1ComponentNamePath = new PropertyPath(myClassComponent1ComponentPath, myComponentInComponentName); myClassComponent1ComponentNamePath.GetRootMember().Should().Be(myClassComponent1); }
public void WhenManyToManyBidirectionalThenApplyColumnNameByEntityClass() { var orm = new Mock<IDomainInspector>(); orm.Setup(x => x.IsManyToMany(It.Is<Type>(t => t == typeof(MyClass)), It.Is<Type>(t => t == typeof(MyBidirect)))).Returns(true); orm.Setup(x => x.IsManyToMany(It.Is<Type>(t => t == typeof(MyBidirect)), It.Is<Type>(t => t == typeof(MyClass)))).Returns(true); var pattern = new ManyToManyKeyIdColumnApplier(orm.Object); var path = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyBidirects)); var collectionMapper = new Mock<ICollectionPropertiesMapper>(); var keyMapper = new Mock<IKeyMapper>(); collectionMapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(x => x.Invoke(keyMapper.Object)); pattern.Apply(path, collectionMapper.Object); keyMapper.Verify(x => x.Column(It.Is<string>(columnName => columnName == "MyClassId"))); var bipath = new PropertyPath(null, ForClass<MyBidirect>.Property(x => x.MyClasses)); var bicollectionMapper = new Mock<ICollectionPropertiesMapper>(); var bikeyMapper = new Mock<IKeyMapper>(); bicollectionMapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(x => x.Invoke(bikeyMapper.Object)); pattern.Apply(bipath, bicollectionMapper.Object); bikeyMapper.Verify(x => x.Column(It.Is<string>(columnName => columnName == "MyBidirectId"))); }
public void WhenNoGenericCollectionThenNoMatch() { var orm = new Mock<IDomainInspector>(); var pattern = new OneToManyKeyColumnApplier(orm.Object); var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Something)); pattern.Match(path).Should().Be.False(); }
public void InvokeDirectMethods() { var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection)); var customizersHolder = new CustomizersHolder(); var customizer = new CollectionElementCustomizer(propertyPath, customizersHolder); var elementMapper = new Mock<IElementMapper>(); customizer.Length(10); customizer.Precision(5); customizer.Scale(2); customizer.NotNullable(true); customizer.Unique(true); customizer.Column("pizza"); customizer.Type(NHibernateUtil.StringClob); customizer.Type<MyUserType>(); var parameters = new {something= 10}; customizer.Type<MyUserType>(parameters); customizer.Type(typeof(MyUserType), parameters); customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object); elementMapper.Verify(x => x.Length(It.Is<int>(v => v == 10)), Times.Once()); elementMapper.Verify(x => x.Precision(It.Is<short>(v => v == 5)), Times.Once()); elementMapper.Verify(x => x.Scale(It.Is<short>(v => v == 2)), Times.Once()); elementMapper.Verify(x => x.Unique(It.Is<bool>(v => v)), Times.Once()); elementMapper.Verify(x => x.NotNullable(It.Is<bool>(v => v)), Times.Once()); elementMapper.Verify(x => x.Column(It.Is<string>(v => v == "pizza")), Times.Once()); elementMapper.Verify(x => x.Type(It.Is<IType>(v => v.GetType() == NHibernateUtil.StringClob.GetType())), Times.Once()); elementMapper.Verify(x => x.Type<MyUserType>(), Times.Once()); elementMapper.Verify(x => x.Type<MyUserType>(It.Is<object>(v=> v == parameters)), Times.Once()); elementMapper.Verify(x => x.Type(It.Is<Type>(v=> v == typeof(MyUserType)), It.Is<object>(v => v == parameters)), Times.Once()); }
public void WhenCollectionOfElementsThenNoMatch() { var orm = GetDomainInspectorMock(); var pattern = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object); var property = new PropertyPath(null, ForClass<MyClass>.Property(mc => mc.Elements)); pattern.Match(property).Should().Be.False(); }
public void HashCodeLevel2() { var myClassComponent1Path = new PropertyPath(null, myClassComponent1); var myClassComponent2Path = new PropertyPath(null, myClassComponent2); new PropertyPath(myClassComponent1Path, myComponentComponent).GetHashCode().Should().Be(new PropertyPath(myClassComponent1Path, myComponentComponent).GetHashCode()); new PropertyPath(myClassComponent2Path, myComponentComponent).GetHashCode().Should().Not.Be(new PropertyPath(myClassComponent1Path, myComponentComponent).GetHashCode()); }
public void MatchAnyValidPropertyPath() { var applier = new ListIndexAsPropertyPosColumnNameApplier(); applier.Match(null).Should().Be.False(); var ppath = new PropertyPath(null, ForClass<MyClass>.Property(mc => mc.Numbers)); applier.Match(ppath).Should().Be.True(); }
public void WhenNoRelationWithComponentThenMatch() { var orm = new Mock<IDomainInspector>(); var pattern = new CollectionOfElementsKeyColumnApplier(orm.Object); var pathCollection = new PropertyPath(null, ForClass<MyComponent>.Property(p => p.Strings)); pattern.Match(pathCollection).Should().Be.True(); }
public void WhenPreviousLevelIsCollectionThenDoesNotMatch() { var lelev0 = new PropertyPath(null, ForClass<MyClassWithComponent>.Property(x => x.Component1)); var lelev1 = new PropertyPath(lelev0, ForClass<MyComponent>.Property(x => x.Collection)); var lelev2 = new PropertyPath(lelev1, ForClass<MyClass>.Property(x => x.Fake1)); var pattern = new ComponentMemberDeepPathPattern(); pattern.Match(lelev2).Should().Be.False(); }
public void WhenSingleUsageThenNoMatch() { var orm = GetDomainInspectorMockForBaseTests(); var applier = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object); var property = new PropertyPath(null, ForClass<MySingleUsage>.Property(x => x.CurrentPositions)); applier.Match(property).Should().Be.False(); }
public void WhenRelationIsOneToManyForMapKeyThenNoMatch() { var orm = new Mock<IDomainInspector>(); var pattern = new CollectionOfElementsKeyColumnApplier(orm.Object); orm.Setup(x => x.IsManyToMany(It.Is<Type>(t => t == typeof(MyClass)), It.Is<Type>(t => t == typeof(MyRelated)))).Returns(true); var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.MapRelationOnKey)); pattern.Match(path).Should().Be.False(); }
public void WhenSingleUsageThenNoMatch() { var basePath = new PropertyPath(null, typeof(MyClassSingleUsage).GetProperty("Component")); var prop1OfComponent = typeof(MyComponent).GetProperty("Prop1"); var prop2OfComponent = typeof(MyComponent).GetProperty("Prop2"); var pattern = new ComponentMultiUsagePattern(); pattern.Match(new PropertyPath(basePath, prop1OfComponent)).Should().Be.False(); pattern.Match(new PropertyPath(basePath, prop2OfComponent)).Should().Be.False(); }
public void WhenComponentsCollectionThenMatch() { var orm = new Mock<IDomainInspector>(); var pattern = new CollectionOfComponentsKeyColumnApplier(orm.Object); orm.Setup(x => x.IsComponent(typeof(MyComponent))).Returns(true); var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Components)); pattern.Match(path).Should().Be.True(); }
public void WhenMultipleUsageBehindAComponentThenMatch() { var orm = GetDomainInspectorMockForBaseTests(); var applier = new UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm.Object); var componentProperty = new PropertyPath(null, ForClass<Contact>.Property(x => x.Component1)); var property = new PropertyPath(componentProperty, ForClass<MyComponent>.Property(x => x.PastPositions)); applier.Match(property).Should().Be.True(); }
public PropertyPath(PropertyPath previousPath, MemberInfo localMember) { if (localMember == null) { throw new ArgumentNullException("localMember"); } this.previousPath = previousPath; this.localMember = localMember; hashCode = localMember.GetHashCode() ^ (previousPath != null ? previousPath.GetHashCode() : 41); }
public void WhenInEntityThenApplyPropertyName() { var applier = new ManyToOneColumnApplier(); var path = new PropertyPath(null, ForClass<MyClass>.Property(x => x.OtherClass)); var mayToOneMapper = new Mock<IManyToOneMapper>(); applier.Match(path).Should().Be.True(); applier.Apply(path, mayToOneMapper.Object); mayToOneMapper.Verify(x => x.Column(It.Is<string>(columnName => columnName == "OtherClassId"))); }
public void InvokeCustomizerOfCollectionElementRelation() { var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection)); var customizersHolder = new CustomizersHolder(); var elementMapper = new Mock<IElementMapper>(); customizersHolder.AddCustomizer(propertyPath, (IElementMapper x) => x.Length(10)); customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object); elementMapper.Verify(x => x.Length(It.Is<int>(v => v == 10)), Times.Once()); }
public void WhenRelationIsNotOneToManyThenNoMatch() { var orm = new Mock<IDomainInspector>(); var pattern = new OneToManyKeyColumnApplier(orm.Object); orm.Setup(x => x.IsOneToMany(It.Is<Type>(t => t == typeof(MyClass)), It.Is<Type>(t => t == typeof(MyRelated)))).Returns(false); var pathCollection = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Relateds)); var pathMap = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Map)); pattern.Match(pathCollection).Should().Be.False(); pattern.Match(pathMap).Should().Be.False(); }
public void InvokeCustomizerOfCollectionOneToManyRelation() { var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection)); var customizersHolder = new CustomizersHolder(); var elementMapper = new Mock<IOneToManyMapper>(); customizersHolder.AddCustomizer(propertyPath, (IOneToManyMapper x) => x.NotFound(NotFoundMode.Ignore)); customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object); elementMapper.Verify(x => x.NotFound(It.Is<NotFoundMode>(v => v == NotFoundMode.Ignore)), Times.Once()); }
public void WhenLevel1ThenMatch() { var level0 = new PropertyPath(null, ForClass<MyClassWithComponent>.Property(x => x.Component1)); var level1 = new PropertyPath(level0, ForClass<MyComponent>.Property(x => x.MyNested)); var level2 = new PropertyPath(level1, ForClass<MyClass>.Property(x => x.Fake1)); var pattern = new ComponentPropertyColumnNameApplier(); var mapper = new Mock<IPropertyMapper>(); pattern.Apply(level2, mapper.Object); mapper.Verify(x => x.Column(It.Is<string>(columnName => columnName == "Component1MyNestedFake1"))); }
public void InvokeCustomizerOfDictionaryKeyManyToManyRelation() { var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyDictionary)); var customizersHolder = new CustomizersHolder(); var elementMapper = new Mock<IMapKeyManyToManyMapper>(); customizersHolder.AddCustomizer(propertyPath, (IMapKeyManyToManyMapper x) => x.Column("pizza")); customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object); elementMapper.Verify(x => x.Column(It.Is<string>(v => v == "pizza")), Times.Once()); }
public void InvokingCustomizerOnBagThenInvokeCollectionPropertiesCustomizer() { var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection)); var customizersHolder = new CustomizersHolder(); var concreteCollectionMapper = new Mock<IBagPropertiesMapper>(); customizersHolder.AddCustomizer(propertyPath, (ICollectionPropertiesMapper x) => x.BatchSize(10)); customizersHolder.InvokeCustomizers(propertyPath, concreteCollectionMapper.Object); concreteCollectionMapper.Verify(x => x.BatchSize(It.Is<int>(v => v == 10)), Times.Once()); }
public void GetContainerEntityWhenPropertyIsInComponentThenReturnEntity() { var orm = new Mock<IDomainInspector>(); orm.Setup(x => x.IsEntity(typeof(MainEntity))).Returns(true); orm.Setup(x => x.IsRootEntity(typeof(MainEntity))).Returns(true); orm.Setup(x => x.IsEntity(typeof(InheritedEntity))).Returns(true); var level0 = new PropertyPath(null, ForClass<InheritedEntity>.Property(p => p.Component)); var path = new PropertyPath(level0, ForClass<MyComponent>.Property(p => p.Something)); path.GetContainerEntity(orm.Object).Should().Be(typeof (InheritedEntity)); }
public void WhenDictionaryIsInPlainEntityThenApplyClassNamePropertyName() { var orm = new Mock<IDomainInspector>(); var pattern = new CollectionOfElementsTableApplier(orm.Object); var mapper = new Mock<ICollectionPropertiesMapper>(); var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.MapOfStrings)); pattern.Match(path).Should().Be.True(); pattern.Apply(path, mapper.Object); mapper.Verify(km => km.Table(It.Is<string>(s => s == "MyClassMapOfStrings"))); }
public void WhenDoubleUsageThenMatch() { var basePath1 = new PropertyPath(null, typeof (MyClassDoubleUsage).GetProperty("Component1")); var basePath2 = new PropertyPath(null, typeof(MyClassDoubleUsage).GetProperty("Component2")); var prop1OfComponent = typeof(MyComponent).GetProperty("Prop1"); var prop2OfComponent = typeof(MyComponent).GetProperty("Prop2"); var pattern = new ComponentMultiUsagePattern(); pattern.Match(new PropertyPath(basePath1, prop1OfComponent)).Should().Be.True(); pattern.Match(new PropertyPath(basePath1, prop2OfComponent)).Should().Be.True(); pattern.Match(new PropertyPath(basePath2, prop1OfComponent)).Should().Be.True(); pattern.Match(new PropertyPath(basePath2, prop2OfComponent)).Should().Be.True(); }
public bool Equals(PropertyPath other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return hashCode == other.GetHashCode(); }
public void ApplyPropertyPathWithPosPostfix() { var applier = new ListIndexAsPropertyPosColumnNameApplier(); var mapper = new Mock<IListPropertiesMapper>(); var idxMapper = new Mock<IListIndexMapper>(); mapper.Setup(x => x.Index(It.IsAny<Action<IListIndexMapper>>())).Callback<Action<IListIndexMapper>>( x => x.Invoke(idxMapper.Object)); var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Numbers)); applier.Apply(path, mapper.Object); idxMapper.Verify(km => km.Column(It.Is<string>(s => s == "NumbersPos"))); }
public void AddCustomizer(PropertyPath member, Action <IMapPropertiesMapper> propertyCustomizer) { AddCustomizer(mapCustomizers, member, propertyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <IComponentAttributesMapper> propertyCustomizer) { AddCustomizer(componentPropertyCustomizers, member, propertyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <ICollectionPropertiesMapper> propertyCustomizer) { AddCustomizer(collectionCustomizers, member, propertyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <IOneToOneMapper> propertyCustomizer) { AddCustomizer(oneToOneCustomizers, member, propertyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <IElementMapper> collectionRelationElementCustomizer) { AddCustomizer(collectionRelationElementCustomizers, member, collectionRelationElementCustomizer); }
public void InvokeCustomizers(PropertyPath member, IOneToOneMapper mapper) { InvokeCustomizers(oneToOneCustomizers, member, mapper); }
public void AddCustomizer(PropertyPath member, Action <IBagPropertiesMapper> propertyCustomizer) { AddCustomizer(bagCustomizers, member, propertyCustomizer); }
public void InvokeCustomizers(PropertyPath member, IMapPropertiesMapper mapper) { InvokeCustomizers(collectionCustomizers, member, mapper); InvokeCustomizers(mapCustomizers, member, mapper); }
public void InvokeCustomizers(PropertyPath member, IAnyMapper mapper) { InvokeCustomizers(anyCustomizers, member, mapper); }
public void InvokeCustomizers(PropertyPath member, IMapKeyMapper mapper) { InvokeCustomizers(mapKeyElementCustomizers, member, mapper); }
public void InvokeCustomizers(PropertyPath member, IOneToManyMapper mapper) { InvokeCustomizers(collectionRelationOneToManyCustomizers, member, mapper); }
public void InvokeCustomizers(PropertyPath member, IElementMapper mapper) { InvokeCustomizers(collectionRelationElementCustomizers, member, mapper); }
public void AddCustomizer(PropertyPath member, Action <IListPropertiesMapper> propertyCustomizer) { AddCustomizer(listCustomizers, member, propertyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <IMapKeyMapper> mapKeyElementCustomizer) { AddCustomizer(mapKeyElementCustomizers, member, mapKeyElementCustomizer); }
public static string ToColumnName(this PropertyPath propertyPath, string pathSeparator) { return(propertyPath.ToString().Replace(".", pathSeparator)); }
public void AddCustomizer(PropertyPath member, Action <IOneToManyMapper> collectionRelationOneToManyCustomizer) { AddCustomizer(collectionRelationOneToManyCustomizers, member, collectionRelationOneToManyCustomizer); }
public void AddCustomizer(PropertyPath member, Action <IPropertyMapper> propertyCustomizer) { AddCustomizer(propertyCustomizers, member, propertyCustomizer); }
public void InvokeCustomizers(PropertyPath member, IComponentAttributesMapper mapper) { InvokeCustomizers(componentPropertyCustomizers, member, mapper); }