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 ToManyToManyForeignKeyNameNoCustomMethodTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Component Table Name => Custom convention config.UseConventionForForeignKeyNames(ForeignKeyNamingConvention.Custom); string result = namingEngine.ToManyToManyForeignKeyName(typeof(Product), typeof(Category), typeof(Category), typeof(Product).GetMember("ID").Single()); }