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();
 }
Пример #2
0
        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();
        }
Пример #3
0
        public void WhenRelationIsOneToManyThenMatch()
        {
            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(true);
            var path = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Relateds));

            pattern.Match(path).Should().Be.True();
        }
        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();
        }
Пример #5
0
        public void WhenAnyToManyThenNoMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyEntity>();
            orm.TablePerClass <MyRelatedRoot1>();
            orm.TablePerClass <MyRelatedRoot2>();

            var applier = new OneToManyKeyColumnApplier(orm);

            applier.Match(new PropertyPath(null, ForClass <MyRelatedRoot1> .Property(x => x.Items))).Should().Be.False();
            applier.Match(new PropertyPath(null, ForClass <MyRelatedRoot2> .Property(x => x.Items))).Should().Be.False();
        }
        public void WhenRelationIsOneToManyForMapValueThenApplyClassNameId()
        {
            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(true);

            var mapper = new Mock<ICollectionPropertiesMapper>();
            var keyMapper = new Mock<IKeyMapper>();
            mapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(
                x => x.Invoke(keyMapper.Object));
            var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Map));

            pattern.Apply(path, mapper.Object);
            keyMapper.Verify(km => km.Column(It.Is<string>(s => s == "MyClassId")));
        }
        public void WhenParentChildThenApplyPropertyNameIdOfChild()
        {
            var orm = new Mock<IDomainInspector>();
            var pattern = new OneToManyKeyColumnApplier(orm.Object);
            orm.Setup(x => x.IsOneToMany(It.Is<Type>(t => t == typeof(Parent)), It.Is<Type>(t => t == typeof(Child)))).Returns(true);

            var mapper = new Mock<ICollectionPropertiesMapper>();
            var keyMapper = new Mock<IKeyMapper>();
            mapper.Setup(x => x.Key(It.IsAny<Action<IKeyMapper>>())).Callback<Action<IKeyMapper>>(
                x => x.Invoke(keyMapper.Object));
            var path = new PropertyPath(null, ForClass<Parent>.Property(p => p.Children));

            pattern.Apply(path, mapper.Object);
            keyMapper.Verify(km => km.Column(It.Is<string>(s => s == "MyParentId")));
        }
Пример #8
0
        public void WhenParentChildThenApplyPropertyNameIdOfChildInSeconfRelation()
        {
            Mock <IDomainInspector> orm = GetOrmMock();
            var pattern = new OneToManyKeyColumnApplier(orm.Object);

            var mapper    = new Mock <ICollectionPropertiesMapper>();
            var keyMapper = new Mock <IKeyMapper>();

            mapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));
            var path = new PropertyPath(null, ForClass <Team> .Property(p => p.MatchesOnRoad));

            pattern.Apply(path, mapper.Object);
            keyMapper.Verify(km => km.Column(It.Is <string>(s => s == "RoadTeamId")));
        }
Пример #9
0
        public void WhenParentChildThenApplyPropertyNameIdOfChild()
        {
            var orm     = new Mock <IDomainInspector>();
            var pattern = new OneToManyKeyColumnApplier(orm.Object);

            orm.Setup(x => x.IsOneToMany(It.Is <Type>(t => t == typeof(Parent)), It.Is <Type>(t => t == typeof(Child)))).Returns(true);

            var mapper    = new Mock <ICollectionPropertiesMapper>();
            var keyMapper = new Mock <IKeyMapper>();

            mapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));
            var path = new PropertyPath(null, ForClass <Parent> .Property(p => p.Children));

            pattern.Apply(path, mapper.Object);
            keyMapper.Verify(km => km.Column(It.Is <string>(s => s == "MyParentId")));
        }
Пример #10
0
        public void WhenRelationIsOneToManyForMapValueThenApplyClassNameId()
        {
            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(true);

            var mapper    = new Mock <ICollectionPropertiesMapper>();
            var keyMapper = new Mock <IKeyMapper>();

            mapper.Setup(x => x.Key(It.IsAny <Action <IKeyMapper> >())).Callback <Action <IKeyMapper> >(
                x => x.Invoke(keyMapper.Object));
            var path = new PropertyPath(null, ForClass <MyClass> .Property(p => p.Map));

            pattern.Apply(path, mapper.Object);
            keyMapper.Verify(km => km.Column(It.Is <string>(s => s == "MyClassId")));
        }
        public void WhenRelationIsOneToManyForMapValueThenMatch()
        {
            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(true);
            var path = new PropertyPath(null, ForClass<MyClass>.Property(p => p.Map));

            pattern.Match(path).Should().Be.True();
        }