public void ToManyToManyTableNameCamelCaseTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Table Name => Default config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.FirstTableName_SecondTableName); string result = namingEngine.ToManyToManyTableName(typeof(Product), typeof(Category)); Assert.AreEqual("category_product", result); // Table Name => First Table Name & Second Table Name config.UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.FirstTableName_SecondTableName); result = namingEngine.ToManyToManyTableName(typeof(Category), typeof(Product)); Assert.AreEqual("category_product", result); // Table Name => First Table Name to Second Table Name config.UseConventionForManyToManyTableNames(ManyToManyTableNamingConvention.FirstTableNameToSecondTableName); result = namingEngine.ToManyToManyTableName(typeof(Category), typeof(Product)); Assert.AreEqual("categoryToProduct", result); // Table Name => Custom config.UseCustomConventionForManyToManyTableNames((f, s) => { Assert.AreEqual(typeof(Category), f); Assert.AreEqual(typeof(Product), s); return "CustomTableName"; }); result = namingEngine.ToManyToManyTableName(typeof(Category), typeof(Product)); Assert.AreEqual("CustomTableName", result); }
public void ToTableNameTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Table Name => Default config.UseConventionForTableNames(TablesNamingConvention.Default); string result = namingEngine.ToTableName(typeof(OrderItem)); Assert.AreEqual("OrderItem", result); // Table Name => Camel Case config.UseConventionForTableNames(TablesNamingConvention.CamelCase); result = namingEngine.ToTableName(typeof(OrderItem)); Assert.AreEqual("orderItem", result); // Table Name => Pascal Case config.UseConventionForTableNames(TablesNamingConvention.PascalCase); result = namingEngine.ToTableName(typeof(OrderItem)); Assert.AreEqual("OrderItem", result); // Table Name => Lowercase Underscore Separated config.UseConventionForTableNames(TablesNamingConvention.Lowercase); result = namingEngine.ToTableName(typeof(OrderItem)); Assert.AreEqual("order_item", result); // Table Name => Uppercase Underscore Separated config.UseConventionForTableNames(TablesNamingConvention.Uppercase); result = namingEngine.ToTableName(typeof(OrderItem)); Assert.AreEqual("ORDER_ITEM", result); // Table Name => Custom config.UseCustomConventionForTableNames(t => { Assert.AreEqual(typeof(Customer), t); return "CustomTableName"; }); result = namingEngine.ToTableName(typeof(Customer)); Assert.AreEqual("CustomTableName", result); }
public void ToElementTableNameTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Element Table Name => ElementName config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.ElementTypeName); string result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("orderItem", result); // Element Table Name => EntityName & ElementName config.UseConventionForTableNames(TablesNamingConvention.PascalCase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.EntityName_ElementName); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("ProductsOrder_OrderItem", result); // Element Table Name => EntityName & Property Name config.UseConventionForTableNames(TablesNamingConvention.Lowercase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.EntityName_PropertyName); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("products_order_items", result); // Element Table Name => EntityName & Property Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.EntityNameElementName); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("productsOrderOrderItem", result); // Element Table Name => EntityName & Property Name config.UseConventionForTableNames(TablesNamingConvention.Uppercase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.EntityNamePropertyName); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("PRODUCTS_ORDER_ITEMS", result); // Element Table Name => EntityName & Property Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseConventionForElementTableNames(ElementsTableNamingConvention.PropertyName); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("items", result); // Element Table Name => EntityName & Property Name config.UseConventionForTableNames(TablesNamingConvention.CamelCase); config.UseCustomConventionForElementTableNames((e, c, p) => { Assert.AreEqual(typeof(ProductsOrder), e); Assert.AreEqual(typeof(OrderItem), c); Assert.AreEqual(typeof(ProductsOrder).GetMember("Items").Single(), p); return "CustomElementTableName"; }); result = namingEngine.ToElementTableName(typeof(ProductsOrder), typeof(OrderItem), typeof(ProductsOrder).GetMember("Items").Single()); Assert.AreEqual("CustomElementTableName", result); }
public void ToTableNameNoCustomMethodTest() { NamingConventionsConfig config = new NamingConventionsConfig(null); NamingEngine namingEngine = new NamingEngine(config); // Table Name => Custom convention config.UseConventionForTableNames(TablesNamingConvention.Custom); string result = namingEngine.ToTableName(typeof(Customer)); }