예제 #1
0
        public void InvokeDirectMethods()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.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 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());
        }
예제 #3
0
        public void InvokeSetOfPersister()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer        = new UnionSubclassCustomizer <MyClass>(customizersHolder);
            var classMapper       = new Mock <IUnionSubclassAttributesMapper>();

            customizer.Persister <UnionSubclassEntityPersister>();
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            classMapper.Verify(x => x.Persister <UnionSubclassEntityPersister>());
        }
예제 #4
0
        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 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 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 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());
        }
예제 #8
0
        public void InvokeSetOfSchemaAction()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer        = new ClassCustomizer <MyClass>(customizersHolder);
            var classMapper       = new Mock <IClassMapper>();

            customizer.SchemaAction(SchemaAction.None);
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            classMapper.Verify(x => x.SchemaAction(SchemaAction.None));
        }
        public void InvokeSetOfSchemaAction()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer = new ClassCustomizer<MyClass>(customizersHolder);
            var classMapper = new Mock<IClassAttributesMapper>();

            customizer.SchemaAction(SchemaAction.None);
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            classMapper.Verify(x => x.SchemaAction(SchemaAction.None));
        }
예제 #10
0
        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());
        }
예제 #11
0
        public void InvokeSetOfPersister()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer        = new SubclassCustomizer <MyClass>(customizersHolder);
            var classMapper       = new Mock <ISubclassMapper>();

            customizer.Persister <SingleTableEntityPersister>();
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            classMapper.Verify(x => x.Persister <SingleTableEntityPersister>());
        }
예제 #12
0
        public void InvokingCustomizerOnMapThenInvokeCollectionPropertiesCustomizer()
        {
            var propertyPath             = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder        = new CustomizersHolder();
            var concreteCollectionMapper = new Mock <IMapPropertiesMapper>();

            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());
        }
예제 #13
0
        public void InvokeCustomizerOfDictionaryKeyElementRelation()
        {
            var propertyPath      = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyDictionary));
            var customizersHolder = new CustomizersHolder();
            var elementMapper     = new Mock <IMapKeyMapper>();

            customizersHolder.AddCustomizer(propertyPath, (IMapKeyMapper x) => x.Column("pizza"));
            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Column(It.Is <string>(v => v == "pizza")), Times.Once());
        }
예제 #14
0
        public void MergeShouldMergeUnionSubclassAttributesMapper()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(typeof(MyClass), (IUnionSubclassAttributesMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(typeof(MyClass), (IUnionSubclassAttributesMapper)null);

            called.Should().Be.True();
        }
예제 #15
0
        public void MergeShouldMergeManyToManyMapper()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(propertyPath, (IManyToManyMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(propertyPath, (IManyToManyMapper)null);

            Assert.That(called, Is.True);
        }
예제 #16
0
        public void MergeShouldMergeDynamicComponentAttributesMapper()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(propertyPath, (IDynamicComponentAttributesMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(propertyPath, (IDynamicComponentAttributesMapper)null);

            Assert.That(called, Is.True);
        }
예제 #17
0
        public void MergeShouldMergeComponentAttributesMapper()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(typeof(MyClass), (IComponentAttributesMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(typeof(MyClass), (IComponentAttributesMapper)null);

            Assert.That(called, Is.True);
        }
예제 #18
0
        public void MergeShouldMergeComponentAttributesMapperOnProperty()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(propertyPath, (IComponentAttributesMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(propertyPath, (IComponentAttributesMapper)null);

            called.Should().Be.True();
        }
		public void MergeShouldMergeCollectionPropertiesMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(propertyPath, (ICollectionPropertiesMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(propertyPath, (IBagPropertiesMapper)null);

			called.Should().Be.True();
		}
예제 #20
0
        public void MergeShouldMergeElementMapper()
        {
            var emptyHolder = new CustomizersHolder();
            var holder      = new CustomizersHolder();
            var called      = false;

            holder.AddCustomizer(propertyPath, (IElementMapper x) => called = true);
            emptyHolder.Merge(holder);
            emptyHolder.InvokeCustomizers(propertyPath, (IElementMapper)null);

            called.Should().Be.True();
        }
		public void MergeShouldMergeIdBagPropertiesMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(propertyPath, (IIdBagPropertiesMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(propertyPath, (IIdBagPropertiesMapper)null);

			Assert.That(called, Is.True);
		}
        public void InvokeFilterMapping()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer = new ClassCustomizer<MyClass>(customizersHolder);
            var classMapper = new Mock<IClassAttributesMapper>();
            var filterMapper = new Mock<IFilterMapper>();
            classMapper.Setup(x => x.Filter(It.IsAny<string>(), It.IsAny<Action<IFilterMapper>>())).Callback<string, Action<IFilterMapper>>(
                (name, x) => x.Invoke(filterMapper.Object));

            customizer.Filter("pizza",x => x.Condition("any condition"));
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            filterMapper.Verify(x => x.Condition(It.Is<string>(v => v == "any condition")));
        }
        public void InvokeOnDelete()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionKeyCustomizer<MyClass>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();
            var keyMapper = new Mock<IKeyMapper>();
            collectionMapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(
                x => x.Invoke(keyMapper.Object));

            customizer.OnDelete(OnDeleteAction.Cascade);
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.OnDelete(It.Is<OnDeleteAction>(v => v == OnDeleteAction.Cascade)), Times.Once());
        }
        public void InvokeCache()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionPropertiesCustomizer<MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();
            var cacheMapper = new Mock<ICacheMapper>();
            collectionMapper.Setup(x => x.Cache(It.IsAny<Action<ICacheMapper>>())).Callback<Action<ICacheMapper>>(
                x => x.Invoke(cacheMapper.Object));

            customizer.Cache(x=> x.Region("static"));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            cacheMapper.Verify(x => x.Region(It.Is<string>(v => v == "static")));
        }
        public void InvokePropertyRef()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionKeyCustomizer<MyClass>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();
            var keyMapper = new Mock<IKeyMapper>();
            collectionMapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(
                x => x.Invoke(keyMapper.Object));

            customizer.PropertyRef(x=> x.AProp);
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.PropertyRef(It.Is<MemberInfo>(v => v == ForClass<MyClass>.Property(p=> p.AProp))), Times.Once());
        }
        public void InvokeColumn()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionKeyCustomizer<MyClass>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();
            var keyMapper = new Mock<IKeyMapper>();
            collectionMapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(
                x => x.Invoke(keyMapper.Object));

            customizer.Column("pizza");
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.Column(It.Is<string>(str => str == "pizza")), Times.Once());
        }
예제 #27
0
        public void InvokeFilterMapping()
        {
            var customizersHolder = new CustomizersHolder();
            var customizer        = new ClassCustomizer <MyClass>(customizersHolder);
            var classMapper       = new Mock <IClassMapper>();
            var filterMapper      = new Mock <IFilterMapper>();

            classMapper.Setup(x => x.Filter(It.IsAny <string>(), It.IsAny <Action <IFilterMapper> >())).Callback <string, Action <IFilterMapper> >(
                (name, x) => x.Invoke(filterMapper.Object));

            customizer.Filter("pizza", x => x.Condition("any condition"));
            customizersHolder.InvokeCustomizers(typeof(MyClass), classMapper.Object);

            filterMapper.Verify(x => x.Condition(It.Is <string>(v => v == "any condition")));
        }
        public void InvokeIndex()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new ListPropertiesCustomizer<MyClass, int>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<IListPropertiesMapper>();
            var listIndexMapper = new Mock<IListIndexMapper>();
            collectionMapper.Setup(x => x.Index(It.IsAny<Action<IListIndexMapper>>())).Callback<Action<IListIndexMapper>>(
                x => x.Invoke(listIndexMapper.Object));

            customizer.Index(x => x.Base(1));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            listIndexMapper.Verify(x => x.Base(It.Is<int>(v => v == 1)));
        }
        public void InvokeColumnCustomizer()
        {
            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>();
            var columnMapper = new Mock<IColumnMapper>();
            elementMapper.Setup(x => x.Column(It.IsAny<Action<IColumnMapper>>())).Callback<Action<IColumnMapper>>(
                x => x.Invoke(columnMapper.Object));

            customizer.Column(c => c.SqlType("VARCHAR(100)"));
            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            columnMapper.Verify(x => x.SqlType(It.Is<string>(v => v == "VARCHAR(100)")));
        }
예제 #30
0
        public void InvokeIndex()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new ListPropertiesCustomizer <MyClass, int>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <IListPropertiesMapper>();
            var listIndexMapper   = new Mock <IListIndexMapper>();

            collectionMapper.Setup(x => x.Index(It.IsAny <Action <IListIndexMapper> >())).Callback <Action <IListIndexMapper> >(
                x => x.Invoke(listIndexMapper.Object));

            customizer.Index(x => x.Base(1));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            listIndexMapper.Verify(x => x.Base(It.Is <int>(v => v == 1)));
        }
예제 #31
0
        public void InvokeFilter()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionPropertiesCustomizer <MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();
            var filterMapper      = new Mock <IFilterMapper>();

            collectionMapper.Setup(x => x.Filter(It.IsAny <string>(), It.IsAny <Action <IFilterMapper> >())).Callback <string, Action <IFilterMapper> >(
                (fn, x) => x.Invoke(filterMapper.Object));

            customizer.Filter("myfilter", x => x.Condition("condition"));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            filterMapper.Verify(x => x.Condition(It.Is <string>(v => v == "condition")));
        }
예제 #32
0
        public void InvokePropertyRef()
        {
            var propertyPath      = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionKeyCustomizer <MyClass>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();
            var keyMapper         = new Mock <IKeyMapper>();

            collectionMapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));

            customizer.PropertyRef(x => x.AProp);
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.PropertyRef(It.Is <MemberInfo>(v => v == ForClass <MyClass> .Property(p => p.AProp))), Times.Once());
        }
예제 #33
0
        public void InvokeColumn()
        {
            var propertyPath      = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionKeyCustomizer <MyClass>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();
            var keyMapper         = new Mock <IKeyMapper>();

            collectionMapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));

            customizer.Column("pizza");
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.Column(It.Is <string>(str => str == "pizza")), Times.Once());
        }
예제 #34
0
        public void InvokeCache()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionPropertiesCustomizer <MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();
            var cacheMapper       = new Mock <ICacheMapper>();

            collectionMapper.Setup(x => x.Cache(It.IsAny <Action <ICacheMapper> >())).Callback <Action <ICacheMapper> >(
                x => x.Invoke(cacheMapper.Object));

            customizer.Cache(x => x.Region("static"));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            cacheMapper.Verify(x => x.Region(It.Is <string>(v => v == "static")));
        }
예제 #35
0
        public void InvokeColumnCustomizer()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new ManyToManyCustomizer(propertyPath, customizersHolder);
            var elementMapper     = new Mock <IManyToManyMapper>();
            var columnMapper      = new Mock <IColumnMapper>();

            elementMapper.Setup(x => x.Column(It.IsAny <Action <IColumnMapper> >())).Callback <Action <IColumnMapper> >(
                x => x.Invoke(columnMapper.Object));

            customizer.Column(c => c.SqlType("VARCHAR(100)"));
            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            columnMapper.Verify(x => x.SqlType(It.Is <string>(v => v == "VARCHAR(100)")));
        }
예제 #36
0
        public void InvokeOnDelete()
        {
            var propertyPath      = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionKeyCustomizer <MyClass>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();
            var keyMapper         = new Mock <IKeyMapper>();

            collectionMapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));

            customizer.OnDelete(OnDeleteAction.Cascade);
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            keyMapper.Verify(x => x.OnDelete(It.Is <OnDeleteAction>(v => v == OnDeleteAction.Cascade)), Times.Once());
        }
예제 #37
0
        public void InvokeDirectMethods()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new OneToManyCustomizer(propertyPath, customizersHolder);
            var elementMapper     = new Mock <IOneToManyMapper>();

            customizer.Class(typeof(Related));
            customizer.EntityName("something");
            customizer.NotFound(NotFoundMode.Ignore);

            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Class(It.Is <Type>(v => v == typeof(Related))), Times.Once());
            elementMapper.Verify(x => x.EntityName(It.Is <string>(v => v == "something")), Times.Once());
            elementMapper.Verify(x => x.NotFound(It.Is <NotFoundMode>(v => v == NotFoundMode.Ignore)), Times.Once());
        }
        public void InvokeDirectMethods()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new OneToManyCustomizer(propertyPath, customizersHolder);
            var elementMapper = new Mock<IOneToManyMapper>();

            customizer.Class(typeof (Related));
            customizer.EntityName("something");
            customizer.NotFound(NotFoundMode.Ignore);

            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Class(It.Is<Type>(v => v == typeof (Related))), Times.Once());
            elementMapper.Verify(x => x.EntityName(It.Is<string>(v => v == "something")), Times.Once());
            elementMapper.Verify(x => x.NotFound(It.Is<NotFoundMode>(v => v == NotFoundMode.Ignore)), Times.Once());
        }
예제 #39
0
        public void InvokeDirectMethods()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new CollectionPropertiesCustomizer <MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper  = new Mock <ISetPropertiesMapper>();

            customizer.Inverse(true);
            customizer.Mutable(true);
            customizer.Where("aa");
            customizer.BatchSize(10);
            customizer.Lazy(CollectionLazy.Extra);
            customizer.OrderBy(x => x.Name);
            customizer.Sort();
            customizer.Sort <object>();
            customizer.Cascade(Cascade.DeleteOrphans);
            customizer.Type <FakeUserCollectionType>();
            customizer.Type(typeof(FakeUserCollectionType));
            customizer.Table("table");
            customizer.Catalog("catalog");
            customizer.Schema("schema");
            customizer.OptimisticLock(true);
            customizer.Access(Accessor.NoSetter);
            customizer.Access(typeof(object));             // <== only to check the call

            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            collectionMapper.Verify(x => x.Inverse(It.Is <bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Mutable(It.Is <bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Where(It.Is <string>(v => v == "aa")), Times.Once());
            collectionMapper.Verify(x => x.BatchSize(It.Is <int>(v => v == 10)), Times.Once());
            collectionMapper.Verify(x => x.Lazy(It.Is <CollectionLazy>(v => v == CollectionLazy.Extra)), Times.Once());
            collectionMapper.Verify(x => x.OrderBy(It.Is <MemberInfo>(v => v == ConfOrm.ForClass <MyEle> .Property(p => p.Name))), Times.Once());
            collectionMapper.Verify(x => x.Sort(), Times.Once());
            collectionMapper.Verify(x => x.Sort <object>(), Times.Once());
            collectionMapper.Verify(x => x.Cascade(It.Is <Cascade>(v => v == Cascade.DeleteOrphans)), Times.Once());
            collectionMapper.Verify(x => x.Type <FakeUserCollectionType>(), Times.Once());
            collectionMapper.Verify(x => x.Type(It.Is <Type>(v => v == typeof(FakeUserCollectionType))), Times.Once());
            collectionMapper.Verify(x => x.Table(It.Is <string>(v => v == "table")), Times.Once());
            collectionMapper.Verify(x => x.Catalog(It.Is <string>(v => v == "catalog")), Times.Once());
            collectionMapper.Verify(x => x.Schema(It.Is <string>(v => v == "schema")), Times.Once());
            collectionMapper.Verify(x => x.OptimisticLock(It.Is <bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Access(It.Is <Accessor>(v => v == Accessor.NoSetter)), Times.Once());
            collectionMapper.Verify(x => x.Access(It.IsAny <Type>()), Times.Once());
        }
        public void InvokeDirectMethods()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionPropertiesCustomizer<MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();

            customizer.Inverse(true);
            customizer.Mutable(true);
            customizer.Where("aa");
            customizer.BatchSize(10);
            customizer.Lazy(CollectionLazy.Extra);
            customizer.OrderBy(x=>x.Name);
            customizer.Sort();
            customizer.Sort<object>();
            customizer.Cascade(Cascade.DeleteOrphans);
            customizer.Type<FakeUserCollectionType>();
            customizer.Type(typeof(FakeUserCollectionType));
            customizer.Table("table");
            customizer.Catalog("catalog");
            customizer.Schema("schema");
            customizer.OptimisticLock(true);
            customizer.Access(Accessor.NoSetter);
            customizer.Access(typeof(object)); // <== only to check the call

            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            collectionMapper.Verify(x => x.Inverse(It.Is<bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Mutable(It.Is<bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Where(It.Is<string>(v => v == "aa")), Times.Once());
            collectionMapper.Verify(x => x.BatchSize(It.Is<int>(v => v == 10)), Times.Once());
            collectionMapper.Verify(x => x.Lazy(It.Is<CollectionLazy>(v => v == CollectionLazy.Extra)), Times.Once());
            collectionMapper.Verify(x => x.OrderBy(It.Is<MemberInfo>(v => v == ForClass<MyEle>.Property(p=>p.Name))), Times.Once());
            collectionMapper.Verify(x => x.Sort(), Times.Once());
            collectionMapper.Verify(x => x.Sort<object>(), Times.Once());
            collectionMapper.Verify(x => x.Cascade(It.Is<Cascade>(v => v == Cascade.DeleteOrphans)), Times.Once());
            collectionMapper.Verify(x => x.Type<FakeUserCollectionType>(), Times.Once());
            collectionMapper.Verify(x => x.Type(It.Is<Type>(v => v == typeof(FakeUserCollectionType))), Times.Once());
            collectionMapper.Verify(x => x.Table(It.Is<string>(v => v == "table")), Times.Once());
            collectionMapper.Verify(x => x.Catalog(It.Is<string>(v => v == "catalog")), Times.Once());
            collectionMapper.Verify(x => x.Schema(It.Is<string>(v => v == "schema")), Times.Once());
            collectionMapper.Verify(x => x.OptimisticLock(It.Is<bool>(v => v)), Times.Once());
            collectionMapper.Verify(x => x.Access(It.Is<Accessor>(v => v == Accessor.NoSetter)), Times.Once());
            collectionMapper.Verify(x => x.Access(It.IsAny<Type>()), Times.Once());
        }
        public void InvokeDirectMethods()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.Dictionary));
            var customizersHolder = new CustomizersHolder();
            var customizer = new MapKeyCustomizer(propertyPath, customizersHolder);
            var elementMapper = new Mock<IMapKeyMapper>();

            customizer.Type(typeof(MyUserType));
            customizer.Type<MyUserType>();
            customizer.Type(NHibernateUtil.String);
            customizer.Length(10);
            customizer.Column("pizza");

            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Type(It.Is<Type>(v => v == typeof(MyUserType))), Times.Once());
            elementMapper.Verify(x => x.Type<MyUserType>(), Times.Once());
            elementMapper.Verify(x => x.Type(It.Is<IType>(v => v.GetType() == NHibernateUtil.String.GetType())), Times.Once());
            elementMapper.Verify(x => x.Length(It.Is<int>(v => v == 10)), Times.Once());
            elementMapper.Verify(x => x.Column(It.Is<string>(v => v == "pizza")), Times.Once());
        }
예제 #42
0
        public void InvokeDirectMethods()
        {
            var propertyPath      = new PropertyPath(null, ConfOrm.ForClass <MyClass> .Property(x => x.Dictionary));
            var customizersHolder = new CustomizersHolder();
            var customizer        = new MapKeyCustomizer(propertyPath, customizersHolder);
            var elementMapper     = new Mock <IMapKeyMapper>();

            customizer.Type(typeof(MyUserType));
            customizer.Type <MyUserType>();
            customizer.Type(NHibernateUtil.String);
            customizer.Length(10);
            customizer.Column("pizza");

            customizersHolder.InvokeCustomizers(propertyPath, elementMapper.Object);

            elementMapper.Verify(x => x.Type(It.Is <Type>(v => v == typeof(MyUserType))), Times.Once());
            elementMapper.Verify(x => x.Type <MyUserType>(), Times.Once());
            elementMapper.Verify(x => x.Type(It.Is <IType>(v => v.GetType() == NHibernateUtil.String.GetType())), Times.Once());
            elementMapper.Verify(x => x.Length(It.Is <int>(v => v == 10)), Times.Once());
            elementMapper.Verify(x => x.Column(It.Is <string>(v => v == "pizza")), Times.Once());
        }
        public void InvokingCustomizerOnListThenInvokeCollectionPropertiesCustomizer()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var concreteCollectionMapper = new Mock<IListPropertiesMapper>();

            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 MergeShouldMergeMapKeyManyToManyMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(propertyPath, (IMapKeyManyToManyMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(propertyPath, (IMapKeyManyToManyMapper)null);

			called.Should().Be.True();
		}
		public void MergeShouldMergeDynamicComponentAttributesMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(propertyPath, (IDynamicComponentAttributesMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(propertyPath, (IDynamicComponentAttributesMapper)null);

			called.Should().Be.True();
		}
		public void MergeShouldMergeComponentAttributesMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(typeof(MyClass), (IComponentAttributesMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(typeof(MyClass), (IComponentAttributesMapper)null);

			called.Should().Be.True();
		}
		public void MergeShouldMergeUnionSubclassAttributesMapper()
		{
			var emptyHolder = new CustomizersHolder();
			var holder = new CustomizersHolder();
			var called = false;

			holder.AddCustomizer(typeof(MyClass), (IUnionSubclassAttributesMapper x) => called = true);
			emptyHolder.Merge(holder);
			emptyHolder.InvokeCustomizers(typeof(MyClass), (IUnionSubclassAttributesMapper)null);

			Assert.That(called, Is.True);
		}
        public void InvokeFilter()
        {
            var propertyPath = new PropertyPath(null, ForClass<MyClass>.Property(x => x.MyCollection));
            var customizersHolder = new CustomizersHolder();
            var customizer = new CollectionPropertiesCustomizer<MyClass, MyEle>(propertyPath, customizersHolder);
            var collectionMapper = new Mock<ISetPropertiesMapper>();
            var filterMapper = new Mock<IFilterMapper>();
            collectionMapper.Setup(x => x.Filter(It.IsAny<string>(), It.IsAny<Action<IFilterMapper>>())).Callback<string, Action<IFilterMapper>>(
                (fn, x) => x.Invoke(filterMapper.Object));

            customizer.Filter("myfilter", x => x.Condition("condition"));
            customizersHolder.InvokeCustomizers(propertyPath, collectionMapper.Object);

            filterMapper.Verify(x => x.Condition(It.Is<string>(v => v == "condition")));
        }