public void ToManyToManyForeignKeyNameTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityNameRelationshipName); config .UseConventionForPrimaryKeyColumnNames(PrimaryKeyColumnNamingConvention.EntityName_IdPropertyName) .UseConventionForConstraintNames(ConstraintNamingConvention.Lowercase); // Foreign Key Name => Default config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.Default); string result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.IsTrue(string.IsNullOrEmpty(result)); // Foreign Key Name => FK_FKTable_PKTable config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable); result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.AreEqual("fk__category_product__category", result); // Foreign Key Name => FK_FKTable_PKTable_PKColumn config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable_FKColumn); result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.AreEqual("fk__category_product__category__id", result); // Foreign Key Name => FKTable_PKTable_FK config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_FK); result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.AreEqual("category_product__category__fk", result); // Foreign Key Name => FKTable_PKTable_PKColumn_FK config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_FKColumn_FK); result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.AreEqual("category_product__category__id__fk", result); // Foreign Key Name => Custom config.UseCustomConventionForForeignKeyNames((s, t, f, i) => { Assert.AreEqual(typeof(Product), s); Assert.AreEqual(typeof(Category), t); Assert.AreEqual(typeof(Category), f); Assert.AreEqual(typeof(ProductsOrder).GetMember("ID").Single(), i); return "CustomForeignKeyName"; }); result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(ProductsOrder).GetMember("ID").Single()); Assert.AreEqual("CustomForeignKeyName", result); }
public void ToComponentTableNameNoCustomMethodTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Component Table Name => Custom convention config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.Custom); string result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); }
public void ToComponentTableNameTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Component Table Name => ComponentName config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.ComponentName); string result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("orderItem", result); // Component Table Name => EntityName & ComponentName config.UseConventionForTableNames(TablesNamingConvention.PascalCase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityName_ComponentName); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("ProductsOrder_OrderItem", result); // Component Table Name => EntityName & Relationship Name config.UseConventionForTableNames(TablesNamingConvention.Lowercase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityName_RelationshipName); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("products_order_items", result); // Component Table Name => EntityName & Relationship Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityNameComponentName); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("productsOrderOrderItem", result); // Component Table Name => EntityName & Relationship Name config.UseConventionForTableNames(TablesNamingConvention.Uppercase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityNameRelationshipName); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("PRODUCTS_ORDER_ITEMS", result); // Component Table Name => EntityName & Relationship Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.RelationshipName); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("items", result); // Component Table Name => EntityName & Relationship Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseCustomConventionForComponentTableNames((e, c, p) => { Assert.AreEqual(typeof(ProductsOrder), e); Assert.AreEqual(typeof(OrderItem), c); Assert.AreEqual(typeof(ProductsOrder).GetMember("Items").Single(), p); return "CustomComponentTableName"; }); result = namingEngine.ToComponentTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("CustomComponentTableName", result); }
public void ToComponentForeignKeyNameTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); config.UseConventionForComponentTableNames(ComponentsTableNamingConvention.EntityNameComponentName); config.UseConventionForPrimaryKeyColumnNames(PrimaryKeyColumnNamingConvention.Default); config.UseConventionForConstraintNames(ConstraintNamingConvention.Uppercase); // Foreign Key Name => Default config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.Default); string result = namingEngine.ToComponentForeignKeyName(typeof(Telephone), typeof(Customer), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.IsTrue(string.IsNullOrEmpty(result)); // Foreign Key Name => FK_FKTable_PKTable config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable); result = namingEngine.ToComponentForeignKeyName(typeof(Telephone), typeof(Customer), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.AreEqual("FK__CUSTOMER_TELEPHONE__CUSTOMER", result); // Foreign Key Name => FK_FKTable_PKTable_PKColumn config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FK_FKTable_PKTable_FKColumn); result = namingEngine.ToComponentForeignKeyName(typeof(Telephone), typeof(Customer), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.AreEqual("FK__CUSTOMER_TELEPHONE__CUSTOMER__ID", result); // Foreign Key Name => FKTable_PKTable_FK config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_FK); result = namingEngine.ToComponentForeignKeyName(typeof(Telephone), typeof(Customer), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.AreEqual("CUSTOMER_TELEPHONE__CUSTOMER__FK", result); // Foreign Key Name => FKTable_PKTable_PKColumn_FK config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.FKTable_PKTable_FKColumn_FK); result = namingEngine.ToComponentForeignKeyName(typeof(Telephone), typeof(Customer), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.AreEqual("CUSTOMER_TELEPHONE__CUSTOMER__ID__FK", result); // Foreign Key Name => FKTable_PKTable_PKColumn_FK config.UseCustomConventionForForeignKeyNames((s, t, f, i) => { Assert.AreEqual(typeof(Customer), s); Assert.AreEqual(typeof(Telephone), t); Assert.AreEqual(typeof(Customer).GetMember("Telephones").Single(), f); Assert.AreEqual(typeof(Customer).GetMember("ID").Single(), i); return "CustomForeignKeyName"; }); result = namingEngine.ToComponentForeignKeyName(typeof(Customer), typeof(Telephone), typeof(Customer).GetMember("Telephones").Single(), typeof(Customer).GetMember("ID").Single()); Assert.AreEqual("CustomForeignKeyName", result); }