mirror of
https://github.com/fergalmoran/EFCore.NamingConventions.git
synced 2025-12-22 09:38:21 +00:00
53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Xunit;
|
|
|
|
namespace EFCore.NamingConventions.Test
|
|
{
|
|
public class LowerCaseNamingTest : RewriterTestBase
|
|
{
|
|
[Fact]
|
|
public void Table_name_is_rewritten()
|
|
{
|
|
using var context = CreateContext();
|
|
var entityType = context.Model.FindEntityType(typeof(SimpleBlog));
|
|
Assert.Equal("simpleblog", entityType.GetTableName());
|
|
}
|
|
|
|
[Fact]
|
|
public void Column_name_is_rewritten()
|
|
{
|
|
using var context = CreateContext();
|
|
var entityType = context.Model.FindEntityType(typeof(SimpleBlog));
|
|
Assert.Equal("id", entityType.FindProperty("Id").GetColumnName());
|
|
Assert.Equal("fullname", entityType.FindProperty("FullName").GetColumnName());
|
|
}
|
|
|
|
[Fact]
|
|
public void Primary_key_name_is_rewritten()
|
|
{
|
|
using var context = CreateContext();
|
|
var entityType = context.Model.FindEntityType(typeof(SimpleBlog));
|
|
Assert.Equal("pk_simpleblog", entityType.GetKeys().Single().GetName());
|
|
}
|
|
|
|
[Fact]
|
|
public void Foreign_key_name_is_rewritten()
|
|
{
|
|
using var context = CreateContext();
|
|
var entityType = context.Model.FindEntityType(typeof(Post));
|
|
Assert.Equal("fk_post_simpleblog_blogid", entityType.GetForeignKeys().Single().GetConstraintName());
|
|
}
|
|
|
|
[Fact]
|
|
public void Index_name_is_rewritten()
|
|
{
|
|
using var context = CreateContext();
|
|
var entityType = context.Model.FindEntityType(typeof(SimpleBlog));
|
|
Assert.Equal("ix_simpleblog_fullname", entityType.GetIndexes().Single().GetName());
|
|
}
|
|
|
|
TestContext CreateContext() => new TestContext(NamingConventionsExtensions.UseLowerCaseNamingConvention);
|
|
}
|
|
}
|