Skip to content

Commit

Permalink
Supports naming conventions for tables, views, indexes, primary keys,…
Browse files Browse the repository at this point in the history
… and foreign keys.
  • Loading branch information
bit365 committed Nov 25, 2024
1 parent 18de42c commit b0a5b1a
Show file tree
Hide file tree
Showing 51 changed files with 372 additions and 880 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EfCore.NamingConverter" Version="1.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EfCore.NamingConverter\EfCore.NamingConverter.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion EfCore.NamingConverter.Sample/MyDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.AddNamingConventions(NamingPolicy.KebabCaseUpper);
configurationBuilder.AddNamingConventions(NamingPolicy.SnakeCaseLower);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class OrderProductEntityConfiguration : IEntityTypeConfiguration<OrderPro
{
public void Configure(EntityTypeBuilder<OrderProduct> builder)
{
builder.HasKey(x => x.Id);
builder.HasKey(x => new { x.Id, x.CategoryId });
builder.Property(x => x.ProductName).HasMaxLength(100);
builder.HasIndex(x => x.ProductName).IsUnique();
}
}
}
93 changes: 0 additions & 93 deletions EfCore.NamingConverter.Tests/CamelCaseNamingPolicyTests.cs

This file was deleted.

17 changes: 0 additions & 17 deletions EfCore.NamingConverter.Tests/ColumnNameConventionTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class ColumnNameConventionTest
{
// TODO: The test is not implemented yet
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class ForeignKeyNameConventionTest
{
// TODO:The test is not implemented yet
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class IndexNameConventionTest
{
// TDDO: The test is not implemented yet
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class KeyNameConventionTest
{
// TODO:The test is not implemented yet
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class TableNameConventionTest
{
// TODO:The test is not implemented yet
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests.Conventions
{
public class ViewNameConventionTest
{
// TODO:The test is not implemented yet
}
}
51 changes: 0 additions & 51 deletions EfCore.NamingConverter.Tests/ConvertNamingPolicyTests.cs

This file was deleted.

15 changes: 15 additions & 0 deletions EfCore.NamingConverter.Tests/Converters/CamelCaseConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class CamelCaseConverterTest
{
[Fact]
public void CanConvertNameToCamelCase()
{
var converter = new CamelCaseConverter();

Assert.Equal("camelCaseName", converter.ConvertName("CamelCaseName"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class KebabCaseLowerConverterTest
{
[Fact]
public void CanConvertNameToKebabCaseLower()
{
var converter = new KebabCaseLowerConverter();

Assert.Equal("kebab-case-lower", converter.ConvertName("KebabCaseLower"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class KebabCaseUpperConverterTest
{
[Fact]
public void CanConvertNameToKebabCaseUpper()
{
var converter = new KebabCaseUpperConverter();

Assert.Equal("SNAKE-CASE-LOWER", converter.ConvertName("SnakeCaseLower"));
}
}
}
20 changes: 20 additions & 0 deletions EfCore.NamingConverter.Tests/Converters/NameConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class NameConverterTest
{
[Theory]
[InlineData(NamingPolicy.CamelCase, "FullName", "fullName")]
[InlineData(NamingPolicy.SnakeCaseLower, "FullName", "full_name")]
[InlineData(NamingPolicy.SnakeCaseUpper, "FullName", "FULL_NAME")]
[InlineData(NamingPolicy.KebabCaseLower, "FullName", "full-name")]
[InlineData(NamingPolicy.KebabCaseUpper, "FullName", "FULL-NAME")]
[InlineData(NamingPolicy.Unspecified, "FullName", "FullName")]
public void CanConvertName(NamingPolicy namingPolicy, string input, string expected)
{
var converter = NameConverter.From(namingPolicy);
Assert.Equal(expected, converter.ConvertName(input));
}
}
}
21 changes: 21 additions & 0 deletions EfCore.NamingConverter.Tests/Converters/SeparatorConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class SeparatorConverterTest
{
class MySeparatorConverter : SeparatorConverter
{
public MySeparatorConverter() : base(lowercase: true, separator: '_')
{
}
}

[Fact]
public void CanConvertNameToSnakeCaseLower()
{
var converter = new MySeparatorConverter();
Assert.Equal("snake_case_lower", converter.ConvertName("SnakeCaseLower"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class SnakeCaseLowerConverterTest
{
[Fact]
public void CanConvertNameToSnakeCaseLower()
{
var converter = new SnakeCaseLowerConverter();
Assert.Equal("snake_case_lower", converter.ConvertName("SnakeCaseLower"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EfCore.NamingConverter.Converters;

namespace EfCore.NamingConverter.Tests.Converters
{
public class SnakeCaseUpperConverterTest
{
[Fact]
public void CanConvertNameToSnakeCaseUpper()
{
var converter = new SnakeCaseUpperConverter();

Assert.Equal("SNAKE_CASE_NAME", converter.ConvertName("SnakeCaseName"));
}
}
}
7 changes: 7 additions & 0 deletions EfCore.NamingConverter.Tests/ExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EfCore.NamingConverter.Tests
{
public class ExtensionsTest
{
// TODO:The test is not implemented yet
}
}
Loading

0 comments on commit b0a5b1a

Please sign in to comment.