Exemple #1
0
        public void WhenNoMasterManyToManyCollectionWithBidirectionalSpecifiedThenApplyTableAlphabeticEntityWithPropertiesNames()
        {
            // does not have a specified Master-Slave
            var orm = new Mock <IDomainInspector>();

            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(Person)), It.Is <Type>(t => t == typeof(Book)))).Returns(true);
            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(Book)), It.Is <Type>(t => t == typeof(Person)))).Returns(true);
            orm.Setup(x => x.GetBidirectionalMember(It.Is <Type>(t => t == typeof(Person)), It.Is <MemberInfo>(m => m == ForClass <Person> .Property(c => c.OwnedBooks)), It.Is <Type>(t => t == typeof(Book)))).Returns(ForClass <Book> .Property(c => c.OwnedBy));
            orm.Setup(x => x.GetBidirectionalMember(It.Is <Type>(t => t == typeof(Book)), It.Is <MemberInfo>(m => m == ForClass <Book> .Property(c => c.OwnedBy)), It.Is <Type>(t => t == typeof(Person)))).Returns(ForClass <Person> .Property(c => c.OwnedBooks));
            orm.Setup(x => x.GetBidirectionalMember(It.Is <Type>(t => t == typeof(Person)), It.Is <MemberInfo>(m => m == ForClass <Person> .Property(c => c.FavoritesBooks)), It.Is <Type>(t => t == typeof(Book)))).Returns(ForClass <Book> .Property(c => c.FavoriteBy));
            orm.Setup(x => x.GetBidirectionalMember(It.Is <Type>(t => t == typeof(Book)), It.Is <MemberInfo>(m => m == ForClass <Book> .Property(c => c.FavoriteBy)), It.Is <Type>(t => t == typeof(Person)))).Returns(ForClass <Person> .Property(c => c.FavoritesBooks));

            var pattern          = new ManyToManyInCollectionTableApplier(orm.Object);
            var path             = new PropertyPath(null, ForClass <Person> .Property(x => x.OwnedBooks));
            var collectionMapper = new Mock <ICollectionPropertiesMapper>();

            pattern.Apply(path, collectionMapper.Object);

            collectionMapper.Verify(x => x.Table(It.Is <string>(tableName => tableName == "BookOwnedByPersonOwnedBooks")));

            var bipath             = new PropertyPath(null, ForClass <Book> .Property(x => x.OwnedBy));
            var bicollectionMapper = new Mock <ICollectionPropertiesMapper>();

            pattern.Match(path).Should().Be.True();
            pattern.Apply(bipath, bicollectionMapper.Object);

            bicollectionMapper.Verify(x => x.Table(It.Is <string>(tableName => tableName == "BookOwnedByPersonOwnedBooks")));
        }
Exemple #2
0
        public void WhenManyToManyCollectionWithOutMasterThenApplyTableAlphabetical()
        {
            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 ManyToManyInCollectionTableApplier(orm.Object);
            var path             = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyBidirects));
            var collectionMapper = new Mock <ICollectionPropertiesMapper>();

            pattern.Match(path).Should().Be.True();
            pattern.Apply(path, collectionMapper.Object);

            collectionMapper.Verify(x => x.Table(It.Is <string>(tableName => tableName == "MyBidirectToMyClass")));

            var bipath             = new PropertyPath(null, ForClass <MyBidirect> .Property(x => x.MyClasses));
            var bicollectionMapper = new Mock <ICollectionPropertiesMapper>();

            pattern.Match(path).Should().Be.True();
            pattern.Apply(bipath, bicollectionMapper.Object);

            bicollectionMapper.Verify(x => x.Table(It.Is <string>(tableName => tableName == "MyBidirectToMyClass")));
        }
Exemple #3
0
        public void WhenManyToManyCollectionInsideComponentThenApplyFromEntityToEntity()
        {
            var orm = new Mock <IDomainInspector>();

            orm.Setup(x => x.IsManyToMany(It.Is <Type>(t => t == typeof(MyComponent)), It.Is <Type>(t => t == typeof(MyBidirect)))).Returns(true);
            orm.Setup(x => x.IsMasterManyToMany(It.Is <Type>(t => t == typeof(MyComponent)), It.Is <Type>(t => t == typeof(MyBidirect)))).Returns(true);

            var pattern = new ManyToManyInCollectionTableApplier(orm.Object);

            var pathEntity       = new PropertyPath(null, ForClass <MyClass> .Property(x => x.MyComponent));
            var path             = new PropertyPath(pathEntity, ForClass <MyComponent> .Property(x => x.MyBidirects));
            var collectionMapper = new Mock <ICollectionPropertiesMapper>();

            pattern.Match(path).Should().Be.True();
            pattern.Apply(path, collectionMapper.Object);

            collectionMapper.Verify(x => x.Table(It.Is <string>(tableName => tableName == "MyClassToMyBidirect")));
        }