Ejemplo n.º 1
0
        public void ShouldApplyPluralsWithUnderscoreUpperCase()
        {
            var inflector = new EnglishInflector();
            var applier   = new ManyToManyPluralizedTableApplier((new Mock <IDomainInspector>()).Object, inflector);

            applier.GetTableNameForRelation(new Relation(typeof(Person), typeof(Role)), new Relation(typeof(Role), typeof(Person))).Should().Be("PEOPLE_ROLES");
        }
Ejemplo n.º 2
0
        public void WhenManyToManyCollectionOnPropertyWithMasterThenApplyTableWithMasterToSlaveWithPropertyAndPluralSlave()
        {
            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.IsMasterManyToMany(It.Is <Type>(t => t == typeof(Person)), It.Is <Type>(t => t == typeof(Book)))).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.Favorites)), 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.Favorites));
            var inflector = new Mock <IInflector>();

            inflector.Setup(x => x.Pluralize("Person")).Returns("People");
            inflector.Setup(x => x.Pluralize("Book")).Returns("Books");

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

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

            collectionMapper.Verify(x => x.Table("PeopleFavoritesBooks"));
        }
Ejemplo n.º 3
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 inflector = new Mock <IInflector>();

            var pattern          = new ManyToManyPluralizedTableApplier(orm.Object, inflector.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);

            inflector.Verify(x => x.Pluralize("MyBidirect"));
            inflector.Verify(x => x.Pluralize("MyClass"));
        }