diff --git a/EfCore.NamingConverter.Sample/EfCore.NamingConverter.Sample.csproj b/EfCore.NamingConverter.Sample/EfCore.NamingConverter.Sample.csproj index 7a3ed84..ce3d842 100644 --- a/EfCore.NamingConverter.Sample/EfCore.NamingConverter.Sample.csproj +++ b/EfCore.NamingConverter.Sample/EfCore.NamingConverter.Sample.csproj @@ -8,8 +8,11 @@ - + + + + diff --git a/EfCore.NamingConverter.Sample/MyDbContext.cs b/EfCore.NamingConverter.Sample/MyDbContext.cs index 3401d68..f5fa435 100644 --- a/EfCore.NamingConverter.Sample/MyDbContext.cs +++ b/EfCore.NamingConverter.Sample/MyDbContext.cs @@ -17,7 +17,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { - configurationBuilder.AddNamingConventions(NamingPolicy.KebabCaseUpper); + configurationBuilder.AddNamingConventions(NamingPolicy.SnakeCaseLower); } } } diff --git a/EfCore.NamingConverter.Sample/OrderProductEntityConfiguration.cs b/EfCore.NamingConverter.Sample/OrderProductEntityConfiguration.cs index f892654..bd63cfc 100644 --- a/EfCore.NamingConverter.Sample/OrderProductEntityConfiguration.cs +++ b/EfCore.NamingConverter.Sample/OrderProductEntityConfiguration.cs @@ -7,8 +7,9 @@ public class OrderProductEntityConfiguration : IEntityTypeConfiguration 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(); } } } diff --git a/EfCore.NamingConverter.Tests/CamelCaseNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/CamelCaseNamingPolicyTests.cs deleted file mode 100644 index e5fd518..0000000 --- a/EfCore.NamingConverter.Tests/CamelCaseNamingPolicyTests.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class CamelCaseNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldConvertToCamelCase() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - var input = "TestName"; - var expected = "testName"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleNullInput() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - - // Act - var result = policy.ConvertName(null); - - // Assert - Assert.Null(result); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - var input = "Word"; - var expected = "word"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - var input = "MultipleWordsInString"; - var expected = "multipleWordsInString"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldNotChangeAlreadyCamelCase() - { - // Arrange - var policy = new CamelCaseNamingPolicy(); - var input = "alreadyCamelCase"; - var expected = "alreadyCamelCase"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} diff --git a/EfCore.NamingConverter.Tests/ColumnNameConventionTests.cs b/EfCore.NamingConverter.Tests/ColumnNameConventionTests.cs deleted file mode 100644 index 85a7a66..0000000 --- a/EfCore.NamingConverter.Tests/ColumnNameConventionTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class ColumnNameConventionTests - { - [Theory] - [InlineData(NamingPolicy.CamelCase, "TestName", "testName")] - [InlineData(NamingPolicy.SnakeCaseLower, "TestName", "test_name")] - [InlineData(NamingPolicy.SnakeCaseUpper, "TestName", "TEST_NAME")] - [InlineData(NamingPolicy.KebabCaseLower, "TestName", "test-name")] - [InlineData(NamingPolicy.KebabCaseUpper, "TestName", "TEST-NAME")] - public void ProcessPropertyAdded_ShouldConvertColumnName(NamingPolicy namingPolicy, string originalName, string expectedName) - { - // TODO: The test is not complete. You need to create a mock for IConventionPropertyBuilder and IConventionContext - } - } -} - diff --git a/EfCore.NamingConverter.Tests/Conventions/ColumnNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/ColumnNameConventionTest.cs new file mode 100644 index 0000000..153f5b0 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/ColumnNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class ColumnNameConventionTest + { + // TODO: The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/Conventions/ForeignKeyNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/ForeignKeyNameConventionTest.cs new file mode 100644 index 0000000..93e83ce --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/ForeignKeyNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class ForeignKeyNameConventionTest + { + // TODO:The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/Conventions/IndexNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/IndexNameConventionTest.cs new file mode 100644 index 0000000..77fb98e --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/IndexNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class IndexNameConventionTest + { + // TDDO: The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/Conventions/KeyNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/KeyNameConventionTest.cs new file mode 100644 index 0000000..8a8e09a --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/KeyNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class KeyNameConventionTest + { + // TODO:The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/Conventions/TableNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/TableNameConventionTest.cs new file mode 100644 index 0000000..1699504 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/TableNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class TableNameConventionTest + { + // TODO:The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/Conventions/ViewNameConventionTest.cs b/EfCore.NamingConverter.Tests/Conventions/ViewNameConventionTest.cs new file mode 100644 index 0000000..18a1af0 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Conventions/ViewNameConventionTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests.Conventions +{ + public class ViewNameConventionTest + { + // TODO:The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/ConvertNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/ConvertNamingPolicyTests.cs deleted file mode 100644 index d228345..0000000 --- a/EfCore.NamingConverter.Tests/ConvertNamingPolicyTests.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class ConvertNamingPolicyTests - { - [Theory] - [InlineData(NamingPolicy.Unspecified, typeof(NoneCaseNamingPolicy))] - [InlineData(NamingPolicy.CamelCase, typeof(CamelCaseNamingPolicy))] - [InlineData(NamingPolicy.SnakeCaseLower, typeof(SnakeCaseLowerNamingPolicy))] - [InlineData(NamingPolicy.SnakeCaseUpper, typeof(SnakeCaseUpperNamingPolicy))] - [InlineData(NamingPolicy.KebabCaseLower, typeof(KebabCaseLowerNamingPolicy))] - [InlineData(NamingPolicy.KebabCaseUpper, typeof(KebabCaseUpperNamingPolicy))] - public void From_ShouldReturnCorrectPolicy(NamingPolicy namingPolicy, Type expectedType) - { - // Act - var result = ConvertNamingPolicy.From(namingPolicy); - - // Assert - Assert.IsType(expectedType, result); - } - - [Fact] - public void From_ShouldThrowArgumentOutOfRangeExceptionForInvalidPolicy() - { - // Arrange - var invalidPolicy = (NamingPolicy)999; - - // Act & Assert - Assert.Throws(() => ConvertNamingPolicy.From(invalidPolicy)); - } - - [Theory] - [InlineData("TestName", "testName", NamingPolicy.CamelCase)] - [InlineData("TestName", "test_name", NamingPolicy.SnakeCaseLower)] - [InlineData("TestName", "TEST_NAME", NamingPolicy.SnakeCaseUpper)] - [InlineData("TestName", "test-name", NamingPolicy.KebabCaseLower)] - [InlineData("TestName", "TEST-NAME", NamingPolicy.KebabCaseUpper)] - [InlineData("TestName", "TestName", NamingPolicy.Unspecified)] - public void ConvertName_ShouldConvertNameAccordingToPolicy(string input, string expected, NamingPolicy namingPolicy) - { - // Arrange - var policy = ConvertNamingPolicy.From(namingPolicy); - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} - diff --git a/EfCore.NamingConverter.Tests/Converters/CamelCaseConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/CamelCaseConverterTest.cs new file mode 100644 index 0000000..1b616a2 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/CamelCaseConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/KebabCaseLowerConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/KebabCaseLowerConverterTest.cs new file mode 100644 index 0000000..7726afe --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/KebabCaseLowerConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/KebabCaseUpperConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/KebabCaseUpperConverterTest.cs new file mode 100644 index 0000000..b00a0b6 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/KebabCaseUpperConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/NameConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/NameConverterTest.cs new file mode 100644 index 0000000..5747601 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/NameConverterTest.cs @@ -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)); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/SeparatorConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/SeparatorConverterTest.cs new file mode 100644 index 0000000..e59eca2 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/SeparatorConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/SnakeCaseLowerConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/SnakeCaseLowerConverterTest.cs new file mode 100644 index 0000000..bcb3962 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/SnakeCaseLowerConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/Converters/SnakeCaseUpperConverterTest.cs b/EfCore.NamingConverter.Tests/Converters/SnakeCaseUpperConverterTest.cs new file mode 100644 index 0000000..06852f9 --- /dev/null +++ b/EfCore.NamingConverter.Tests/Converters/SnakeCaseUpperConverterTest.cs @@ -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")); + } + } +} diff --git a/EfCore.NamingConverter.Tests/ExtensionsTest.cs b/EfCore.NamingConverter.Tests/ExtensionsTest.cs new file mode 100644 index 0000000..af917e8 --- /dev/null +++ b/EfCore.NamingConverter.Tests/ExtensionsTest.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Tests +{ + public class ExtensionsTest + { + // TODO:The test is not implemented yet + } +} diff --git a/EfCore.NamingConverter.Tests/KebabCaseLowerNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/KebabCaseLowerNamingPolicyTests.cs deleted file mode 100644 index 3776cb6..0000000 --- a/EfCore.NamingConverter.Tests/KebabCaseLowerNamingPolicyTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class KebabCaseLowerNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldConvertToKebabCaseLower() - { - // Arrange - var policy = new KebabCaseLowerNamingPolicy(); - var input = "TestName"; - var expected = "test-name"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldThrowOnNullInput() - { - // Arrange - var policy = new KebabCaseLowerNamingPolicy(); - - // Act - void action() => policy.ConvertName(null); - - // Assert - Assert.Throws(action); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new KebabCaseLowerNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new KebabCaseLowerNamingPolicy(); - var input = "Word"; - var expected = "word"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new KebabCaseLowerNamingPolicy(); - var input = "MultipleWordsInString"; - var expected = "multiple-words-in-string"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} diff --git a/EfCore.NamingConverter.Tests/KebabCaseUpperNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/KebabCaseUpperNamingPolicyTests.cs deleted file mode 100644 index 5437304..0000000 --- a/EfCore.NamingConverter.Tests/KebabCaseUpperNamingPolicyTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class KebabCaseUpperNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldConvertToKebabCaseUpper() - { - // Arrange - var policy = new KebabCaseUpperNamingPolicy(); - var input = "TestName"; - var expected = "TEST-NAME"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldThrowArgumentNullException() - { - // Arrange - var policy = new KebabCaseUpperNamingPolicy(); - - // Act & Assert - Assert.Throws(() => policy.ConvertName(null)); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new KebabCaseUpperNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new KebabCaseUpperNamingPolicy(); - var input = "Word"; - var expected = "WORD"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new KebabCaseUpperNamingPolicy(); - var input = "MultipleWordsInString"; - var expected = "MULTIPLE-WORDS-IN-STRING"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter.Tests/ModelConfigurationBuilderExtensionsTests.cs b/EfCore.NamingConverter.Tests/ModelConfigurationBuilderExtensionsTests.cs deleted file mode 100644 index 3df7540..0000000 --- a/EfCore.NamingConverter.Tests/ModelConfigurationBuilderExtensionsTests.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class ModelConfigurationBuilderExtensionsTests - { - // TODO: add tests - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter.Tests/NoneCaseNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/NoneCaseNamingPolicyTests.cs deleted file mode 100644 index 996685e..0000000 --- a/EfCore.NamingConverter.Tests/NoneCaseNamingPolicyTests.cs +++ /dev/null @@ -1,77 +0,0 @@ -using Xunit; -using EfCore.NamingConverter; - -namespace EfCore.NamingConverter.Tests -{ - public class NoneCaseNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldReturnSameString() - { - // Arrange - var policy = new NoneCaseNamingPolicy(); - var input = "TestName"; - var expected = "TestName"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldThrowArgumentNullExceptionNullInput() - { - // Arrange - var policy = new NoneCaseNamingPolicy(); - // Act & Assert - Assert.Throws(() => policy.ConvertName(null)); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new NoneCaseNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new NoneCaseNamingPolicy(); - var input = "Word"; - var expected = "Word"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new NoneCaseNamingPolicy(); - var input = "Multiple Words In String"; - var expected = "Multiple Words In String"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter.Tests/SeparatorNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/SeparatorNamingPolicyTests.cs deleted file mode 100644 index 4c5a704..0000000 --- a/EfCore.NamingConverter.Tests/SeparatorNamingPolicyTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class SeparatorNamingPolicyTests - { - private class TestSeparatorNamingPolicy(bool lowercase, char separator) : SeparatorNamingPolicy(lowercase, separator) - { - } - - [Fact] - public void ConvertName_ShouldConvertToLowercaseWithSeparator() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = "TestName"; - var expected = "test-name"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldConvertToUppercaseWithSeparator() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: false, separator: '-'); - var input = "TestName"; - var expected = "TEST-NAME"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleNullInput() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - - // Act & Assert - Assert.Throws(() => policy.ConvertName(null)); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = "Word"; - var expected = "word"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = "MultipleWordsInString"; - var expected = "multiple-words-in-string"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSpaces() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = "Multiple Words In String"; - var expected = "multiple-words-in-string"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleNonAlphanumericCharacters() - { - // Arrange - var policy = new TestSeparatorNamingPolicy(lowercase: true, separator: '-'); - var input = "Test@Name#With$Special%Characters"; - var expected = "test@name#with$special%characters"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter.Tests/SnakeCaseLowerNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/SnakeCaseLowerNamingPolicyTests.cs deleted file mode 100644 index 43c2d01..0000000 --- a/EfCore.NamingConverter.Tests/SnakeCaseLowerNamingPolicyTests.cs +++ /dev/null @@ -1,105 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class SnakeCaseLowerNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldConvertToSnakeCaseLower() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = "TestName"; - var expected = "test_name"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldThrowArgumentNullExceptionOnNullInput() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - - // Act & Assert - Assert.Throws(() => policy.ConvertName(null)); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = "Word"; - var expected = "word"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = "MultipleWordsInString"; - var expected = "multiple_words_in_string"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSpaces() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = "Multiple Words In String"; - var expected = "multiple_words_in_string"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleNonAlphanumericCharacters() - { - // Arrange - var policy = new SnakeCaseLowerNamingPolicy(); - var input = "Test@Name#With$Special%Characters"; - var expected = "test@name#with$special%characters"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} diff --git a/EfCore.NamingConverter.Tests/SnakeCaseUpperNamingPolicyTests.cs b/EfCore.NamingConverter.Tests/SnakeCaseUpperNamingPolicyTests.cs deleted file mode 100644 index 316b8eb..0000000 --- a/EfCore.NamingConverter.Tests/SnakeCaseUpperNamingPolicyTests.cs +++ /dev/null @@ -1,104 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class SnakeCaseUpperNamingPolicyTests - { - [Fact] - public void ConvertName_ShouldConvertToSnakeCaseUpper() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = "TestName"; - var expected = "TEST_NAME"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldThrowArgumentNullException() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - // Act & Assert - Assert.Throws(() => policy.ConvertName(null)); - } - - [Fact] - public void ConvertName_ShouldHandleEmptyString() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = string.Empty; - var expected = string.Empty; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSingleWord() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = "Word"; - var expected = "WORD"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleMultipleWords() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = "MultipleWordsInString"; - var expected = "MULTIPLE_WORDS_IN_STRING"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleSpaces() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = "Multiple Words In String"; - var expected = "MULTIPLE_WORDS_IN_STRING"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - - [Fact] - public void ConvertName_ShouldHandleNonAlphanumericCharacters() - { - // Arrange - var policy = new SnakeCaseUpperNamingPolicy(); - var input = "Test@Name#With$Special%Characters"; - var expected = "TEST@NAME#WITH$SPECIAL%CHARACTERS"; - - // Act - var result = policy.ConvertName(input); - - // Assert - Assert.Equal(expected, result); - } - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter.Tests/TableNameConventionTests.cs b/EfCore.NamingConverter.Tests/TableNameConventionTests.cs deleted file mode 100644 index e5e4504..0000000 --- a/EfCore.NamingConverter.Tests/TableNameConventionTests.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace EfCore.NamingConverter.Tests -{ - public class TableNameConventionTests - { - [Theory] - [InlineData(NamingPolicy.CamelCase, "TestTable", "testTable")] - [InlineData(NamingPolicy.SnakeCaseLower, "TestTable", "test_table")] - [InlineData(NamingPolicy.SnakeCaseUpper, "TestTable", "TEST_TABLE")] - [InlineData(NamingPolicy.KebabCaseLower, "TestTable", "test-table")] - [InlineData(NamingPolicy.KebabCaseUpper, "TestTable", "TEST-TABLE")] - [InlineData(NamingPolicy.Unspecified, "TestTable", "TestTable")] - public void ProcessEntityTypeAdded_ShouldConvertTableName(NamingPolicy namingPolicy, string originalName, string expectedName) - { - // TODO: This test is not complete. You need to create a mock for IConventionEntityTypeBuilder and call the ProcessEntityTypeAdded method. - } - } -} - diff --git a/EfCore.NamingConverter/ColumnNameConvention.cs b/EfCore.NamingConverter/Conventions/ColumnNameConvention.cs similarity index 51% rename from EfCore.NamingConverter/ColumnNameConvention.cs rename to EfCore.NamingConverter/Conventions/ColumnNameConvention.cs index dc9008a..f61fb9e 100644 --- a/EfCore.NamingConverter/ColumnNameConvention.cs +++ b/EfCore.NamingConverter/Conventions/ColumnNameConvention.cs @@ -1,16 +1,16 @@ -using Microsoft.EntityFrameworkCore; +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions; -namespace EfCore.NamingConverter +namespace EfCore.NamingConverter.Conventions { - public class ColumnNameConvention(NamingPolicy namingPolicy) : IPropertyAddedConvention + public class ColumnNameConvention(NameConverter converter) : IPropertyAddedConvention { public void ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext context) { - ConvertNamingPolicy convertNamingPolicy = ConvertNamingPolicy.From(namingPolicy); string propertyName = propertyBuilder.Metadata.GetColumnName(); - propertyBuilder.HasColumnName(convertNamingPolicy.ConvertName(propertyName)); + propertyBuilder.HasColumnName(converter.ConvertName(propertyName)); } } } diff --git a/EfCore.NamingConverter/Conventions/ForeignKeyNameConvention.cs b/EfCore.NamingConverter/Conventions/ForeignKeyNameConvention.cs new file mode 100644 index 0000000..5ddfaf2 --- /dev/null +++ b/EfCore.NamingConverter/Conventions/ForeignKeyNameConvention.cs @@ -0,0 +1,31 @@ +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; + +namespace EfCore.NamingConverter.Conventions +{ + public class ForeignKeyNameConvention(NameConverter converter) : IForeignKeyAddedConvention, IForeignKeyPropertiesChangedConvention + { + public void ProcessForeignKeyAdded(IConventionForeignKeyBuilder foreignKeyBuilder, IConventionContext context) + { + string? foreignKeyName = foreignKeyBuilder.Metadata.GetDefaultName(); + + if (foreignKeyName != null) + { + foreignKeyBuilder.HasConstraintName(converter.ConvertName(foreignKeyName)); + } + } + + public void ProcessForeignKeyPropertiesChanged(IConventionForeignKeyBuilder relationshipBuilder, IReadOnlyList oldDependentProperties, IConventionKey oldPrincipalKey, IConventionContext> context) + { + string? foreignKeyName = relationshipBuilder.Metadata.GetDefaultName(); + + if (foreignKeyName != null && relationshipBuilder.Metadata.IsInModel) + { + relationshipBuilder.HasConstraintName(converter.ConvertName(foreignKeyName)); + } + } + } +} diff --git a/EfCore.NamingConverter/Conventions/IndexNameConvention.cs b/EfCore.NamingConverter/Conventions/IndexNameConvention.cs new file mode 100644 index 0000000..f378338 --- /dev/null +++ b/EfCore.NamingConverter/Conventions/IndexNameConvention.cs @@ -0,0 +1,20 @@ +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; + +namespace EfCore.NamingConverter.Conventions +{ + public class IndexNameConvention(NameConverter converter) : IIndexAddedConvention + { + public void ProcessIndexAdded(IConventionIndexBuilder indexBuilder, IConventionContext context) + { + string? indexName = indexBuilder.Metadata.GetDatabaseName(); + + if (indexName != null) + { + indexBuilder.HasDatabaseName(converter.ConvertName(indexName)); + } + } + } +} diff --git a/EfCore.NamingConverter/Conventions/KeyNameConvention.cs b/EfCore.NamingConverter/Conventions/KeyNameConvention.cs new file mode 100644 index 0000000..d5e9688 --- /dev/null +++ b/EfCore.NamingConverter/Conventions/KeyNameConvention.cs @@ -0,0 +1,20 @@ +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; + +namespace EfCore.NamingConverter.Conventions +{ + public class KeyNameConvention(NameConverter converter) : IKeyAddedConvention + { + public void ProcessKeyAdded(IConventionKeyBuilder keyBuilder, IConventionContext context) + { + string? keyName = keyBuilder.Metadata.GetName(); + + if (keyName != null) + { + keyBuilder.HasName(converter.ConvertName(keyName)); + } + } + } +} diff --git a/EfCore.NamingConverter/TableNameConvention.cs b/EfCore.NamingConverter/Conventions/TableNameConvention.cs similarity index 55% rename from EfCore.NamingConverter/TableNameConvention.cs rename to EfCore.NamingConverter/Conventions/TableNameConvention.cs index 4376f0a..3f6385c 100644 --- a/EfCore.NamingConverter/TableNameConvention.cs +++ b/EfCore.NamingConverter/Conventions/TableNameConvention.cs @@ -1,19 +1,19 @@ -using Microsoft.EntityFrameworkCore; +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Conventions; -namespace EfCore.NamingConverter +namespace EfCore.NamingConverter.Conventions { - public class TableNameConvention(NamingPolicy namingPolicy) : IEntityTypeAddedConvention + public class TableNameConvention(NameConverter converter) : IEntityTypeAddedConvention { public void ProcessEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext context) { - ConvertNamingPolicy convertNamingPolicy = ConvertNamingPolicy.From(namingPolicy); - string? tableName = entityTypeBuilder.Metadata.GetTableName(); + if (tableName != null) { - entityTypeBuilder.ToTable(convertNamingPolicy.ConvertName(tableName)); + entityTypeBuilder.ToTable(converter.ConvertName(tableName)); } } } diff --git a/EfCore.NamingConverter/Conventions/ViewNameConvention.cs b/EfCore.NamingConverter/Conventions/ViewNameConvention.cs new file mode 100644 index 0000000..4a40fab --- /dev/null +++ b/EfCore.NamingConverter/Conventions/ViewNameConvention.cs @@ -0,0 +1,21 @@ +using EfCore.NamingConverter.Converters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; + +namespace EfCore.NamingConverter.Conventions +{ + public class ViewNameConvention(NameConverter nameConverter) : IEntityTypeAddedConvention + { + public void ProcessEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext context) + { + string? viewName = entityTypeBuilder.Metadata.GetViewName(); + + if (viewName != null && entityTypeBuilder.Metadata.GetViewNameConfigurationSource() == ConfigurationSource.Convention) + { + entityTypeBuilder.ToView(nameConverter.ConvertName(viewName)); + } + } + } +} diff --git a/EfCore.NamingConverter/ConvertNamingPolicy.cs b/EfCore.NamingConverter/ConvertNamingPolicy.cs deleted file mode 100644 index 30697af..0000000 --- a/EfCore.NamingConverter/ConvertNamingPolicy.cs +++ /dev/null @@ -1,62 +0,0 @@ - -namespace EfCore.NamingConverter -{ - public abstract class ConvertNamingPolicy - { - /// - /// Initializes a new instance of . - /// - protected ConvertNamingPolicy() { } - - /// - /// Returns the naming policy for camel-casing. - /// - public static ConvertNamingPolicy CamelCase { get; } = new CamelCaseNamingPolicy(); - - /// - /// Returns the naming policy for lower snake-casing. - /// - public static ConvertNamingPolicy SnakeCaseLower { get; } = new SnakeCaseLowerNamingPolicy(); - - /// - /// Returns the naming policy for upper snake-casing. - /// - public static ConvertNamingPolicy SnakeCaseUpper { get; } = new SnakeCaseUpperNamingPolicy(); - - /// - /// Returns the naming policy for lower kebab-casing. - /// - public static ConvertNamingPolicy KebabCaseLower { get; } = new KebabCaseLowerNamingPolicy(); - - /// - /// Returns the naming policy for upper kebab-casing. - /// - public static ConvertNamingPolicy KebabCaseUpper { get; } = new KebabCaseUpperNamingPolicy(); - - /// - /// Returns the naming policy for no conversion. - /// - public static ConvertNamingPolicy None { get; } = new NoneCaseNamingPolicy(); - - /// - /// When overridden in a derived class, converts the specified name according to the policy. - /// - /// The name to convert. - /// The converted name. - public abstract string ConvertName(string name); - - public static ConvertNamingPolicy From(NamingPolicy namingPolicy) - { - return namingPolicy switch - { - NamingPolicy.Unspecified => None, - NamingPolicy.CamelCase => CamelCase, - NamingPolicy.SnakeCaseLower => SnakeCaseLower, - NamingPolicy.SnakeCaseUpper => SnakeCaseUpper, - NamingPolicy.KebabCaseLower => KebabCaseLower, - NamingPolicy.KebabCaseUpper => KebabCaseUpper, - _ => throw new ArgumentOutOfRangeException(nameof(namingPolicy)) - }; - } - } -} diff --git a/EfCore.NamingConverter/CamelCaseNamingPolicy.cs b/EfCore.NamingConverter/Converters/CamelCaseConverter.cs similarity index 87% rename from EfCore.NamingConverter/CamelCaseNamingPolicy.cs rename to EfCore.NamingConverter/Converters/CamelCaseConverter.cs index 3d2b9d7..4a7e62d 100644 --- a/EfCore.NamingConverter/CamelCaseNamingPolicy.cs +++ b/EfCore.NamingConverter/Converters/CamelCaseConverter.cs @@ -1,6 +1,6 @@ -namespace EfCore.NamingConverter +namespace EfCore.NamingConverter.Converters { - internal sealed class CamelCaseNamingPolicy : ConvertNamingPolicy + internal sealed class CamelCaseConverter : NameConverter { public override string ConvertName(string name) { @@ -25,7 +25,7 @@ private static void FixCasing(Span chars) break; } - bool hasNext = (i + 1 < chars.Length); + bool hasNext = i + 1 < chars.Length; // Stop when next char is already lowercase. if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) diff --git a/EfCore.NamingConverter/Constants.cs b/EfCore.NamingConverter/Converters/Constants.cs similarity index 64% rename from EfCore.NamingConverter/Constants.cs rename to EfCore.NamingConverter/Converters/Constants.cs index 89a773e..4d8f791 100644 --- a/EfCore.NamingConverter/Constants.cs +++ b/EfCore.NamingConverter/Converters/Constants.cs @@ -1,6 +1,6 @@ -namespace EfCore.NamingConverter +namespace EfCore.NamingConverter.Converters { - public static class Constants + internal static class Constants { public const int StackallocByteThreshold = 256; diff --git a/EfCore.NamingConverter/Converters/KebabCaseLowerConverter.cs b/EfCore.NamingConverter/Converters/KebabCaseLowerConverter.cs new file mode 100644 index 0000000..842cb09 --- /dev/null +++ b/EfCore.NamingConverter/Converters/KebabCaseLowerConverter.cs @@ -0,0 +1,9 @@ +namespace EfCore.NamingConverter.Converters +{ + internal sealed class KebabCaseLowerConverter : SeparatorConverter + { + public KebabCaseLowerConverter() : base(lowercase: true, separator: '-') + { + } + } +} \ No newline at end of file diff --git a/EfCore.NamingConverter/Converters/KebabCaseUpperConverter.cs b/EfCore.NamingConverter/Converters/KebabCaseUpperConverter.cs new file mode 100644 index 0000000..616ca76 --- /dev/null +++ b/EfCore.NamingConverter/Converters/KebabCaseUpperConverter.cs @@ -0,0 +1,9 @@ +namespace EfCore.NamingConverter.Converters +{ + internal sealed class KebabCaseUpperConverter : SeparatorConverter + { + public KebabCaseUpperConverter() : base(lowercase: false, separator: '-') + { + } + } +} \ No newline at end of file diff --git a/EfCore.NamingConverter/Converters/NameConverter.cs b/EfCore.NamingConverter/Converters/NameConverter.cs new file mode 100644 index 0000000..cc07c5a --- /dev/null +++ b/EfCore.NamingConverter/Converters/NameConverter.cs @@ -0,0 +1,36 @@ + +namespace EfCore.NamingConverter.Converters +{ + public abstract class NameConverter + { + protected NameConverter() { } + + public static NameConverter CamelCase { get; } = new CamelCaseConverter(); + + public static NameConverter SnakeCaseLower { get; } = new SnakeCaseLowerConverter(); + + public static NameConverter SnakeCaseUpper { get; } = new SnakeCaseUpperConverter(); + + public static NameConverter KebabCaseLower { get; } = new KebabCaseLowerConverter(); + + public static NameConverter KebabCaseUpper { get; } = new KebabCaseUpperConverter(); + + public static NameConverter None { get; } = new NoneCaseConverter(); + + public abstract string ConvertName(string name); + + public static NameConverter From(NamingPolicy namingPolicy) + { + return namingPolicy switch + { + NamingPolicy.Unspecified => None, + NamingPolicy.CamelCase => CamelCase, + NamingPolicy.SnakeCaseLower => SnakeCaseLower, + NamingPolicy.SnakeCaseUpper => SnakeCaseUpper, + NamingPolicy.KebabCaseLower => KebabCaseLower, + NamingPolicy.KebabCaseUpper => KebabCaseUpper, + _ => throw new ArgumentOutOfRangeException(nameof(namingPolicy)) + }; + } + } +} diff --git a/EfCore.NamingConverter/Converters/NoneCaseConverter.cs b/EfCore.NamingConverter/Converters/NoneCaseConverter.cs new file mode 100644 index 0000000..62196d4 --- /dev/null +++ b/EfCore.NamingConverter/Converters/NoneCaseConverter.cs @@ -0,0 +1,7 @@ +namespace EfCore.NamingConverter.Converters +{ + internal class NoneCaseConverter : NameConverter + { + public override string ConvertName(string name) => name; + } +} diff --git a/EfCore.NamingConverter/SeparatorNamingPolicy.cs b/EfCore.NamingConverter/Converters/SeparatorConverter.cs similarity index 97% rename from EfCore.NamingConverter/SeparatorNamingPolicy.cs rename to EfCore.NamingConverter/Converters/SeparatorConverter.cs index 98bfcee..cd945a5 100644 --- a/EfCore.NamingConverter/SeparatorNamingPolicy.cs +++ b/EfCore.NamingConverter/Converters/SeparatorConverter.cs @@ -3,14 +3,14 @@ using System.Globalization; using System.Runtime.CompilerServices; -namespace EfCore.NamingConverter +namespace EfCore.NamingConverter.Converters { - internal abstract class SeparatorNamingPolicy : ConvertNamingPolicy + internal abstract class SeparatorConverter : NameConverter { private readonly bool _lowercase; private readonly char _separator; - internal SeparatorNamingPolicy(bool lowercase, char separator) + internal SeparatorConverter(bool lowercase, char separator) { Debug.Assert(char.IsPunctuation(separator)); diff --git a/EfCore.NamingConverter/Converters/SnakeCaseLowerConverter.cs b/EfCore.NamingConverter/Converters/SnakeCaseLowerConverter.cs new file mode 100644 index 0000000..d21cd26 --- /dev/null +++ b/EfCore.NamingConverter/Converters/SnakeCaseLowerConverter.cs @@ -0,0 +1,9 @@ +namespace EfCore.NamingConverter.Converters +{ + internal sealed class SnakeCaseLowerConverter : SeparatorConverter + { + public SnakeCaseLowerConverter() : base(lowercase: true, separator: '_') + { + } + } +} diff --git a/EfCore.NamingConverter/Converters/SnakeCaseUpperConverter.cs b/EfCore.NamingConverter/Converters/SnakeCaseUpperConverter.cs new file mode 100644 index 0000000..e912b22 --- /dev/null +++ b/EfCore.NamingConverter/Converters/SnakeCaseUpperConverter.cs @@ -0,0 +1,9 @@ +namespace EfCore.NamingConverter.Converters +{ + internal class SnakeCaseUpperConverter : SeparatorConverter + { + public SnakeCaseUpperConverter() : base(lowercase: false, separator: '_') + { + } + } +} diff --git a/EfCore.NamingConverter/EfCore.NamingConverter.csproj b/EfCore.NamingConverter/EfCore.NamingConverter.csproj index 8d63210..58e6813 100644 --- a/EfCore.NamingConverter/EfCore.NamingConverter.csproj +++ b/EfCore.NamingConverter/EfCore.NamingConverter.csproj @@ -8,7 +8,7 @@ Entity Framework Core Naming Converter https://github.com/bit365/efcore-naming-converter README.md - 1.0.5 + 1.0.6 diff --git a/EfCore.NamingConverter/Extensions.cs b/EfCore.NamingConverter/Extensions.cs index f9b3b77..7f80026 100644 --- a/EfCore.NamingConverter/Extensions.cs +++ b/EfCore.NamingConverter/Extensions.cs @@ -1,3 +1,5 @@ +using EfCore.NamingConverter.Conventions; +using EfCore.NamingConverter.Converters; using Microsoft.EntityFrameworkCore; namespace EfCore.NamingConverter @@ -6,8 +8,14 @@ public static class Extensions { public static void AddNamingConventions(this ModelConfigurationBuilder configurationBuilder, NamingPolicy namingPolicy = NamingPolicy.Unspecified) { - configurationBuilder.Conventions.Add(_ => new TableNameConvention(namingPolicy)); - configurationBuilder.Conventions.Add(_ => new ColumnNameConvention(namingPolicy)); + NameConverter converter = NameConverter.From(namingPolicy); + + configurationBuilder.Conventions.Add(_ => new TableNameConvention(converter)); + configurationBuilder.Conventions.Add(_ => new ViewNameConvention(converter)); + configurationBuilder.Conventions.Add(_ => new ColumnNameConvention(converter)); + configurationBuilder.Conventions.Add(_ => new IndexNameConvention(converter)); + configurationBuilder.Conventions.Add(_ => new KeyNameConvention(converter)); + configurationBuilder.Conventions.Add(_ => new ForeignKeyNameConvention(converter)); } } } \ No newline at end of file diff --git a/EfCore.NamingConverter/KebabCaseLowerNamingPolicy.cs b/EfCore.NamingConverter/KebabCaseLowerNamingPolicy.cs deleted file mode 100644 index 575fb64..0000000 --- a/EfCore.NamingConverter/KebabCaseLowerNamingPolicy.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EfCore.NamingConverter -{ - internal sealed class KebabCaseLowerNamingPolicy : SeparatorNamingPolicy - { - public KebabCaseLowerNamingPolicy() : base(lowercase: true, separator: '-') - { - } - } -} \ No newline at end of file diff --git a/EfCore.NamingConverter/KebabCaseUpperNamingPolicy.cs b/EfCore.NamingConverter/KebabCaseUpperNamingPolicy.cs deleted file mode 100644 index 2222788..0000000 --- a/EfCore.NamingConverter/KebabCaseUpperNamingPolicy.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EfCore.NamingConverter -{ - internal sealed class KebabCaseUpperNamingPolicy : SeparatorNamingPolicy - { - public KebabCaseUpperNamingPolicy() : base(lowercase: false, separator: '-') - { - } - } -} diff --git a/EfCore.NamingConverter/NoneCaseNamingPolicy.cs b/EfCore.NamingConverter/NoneCaseNamingPolicy.cs deleted file mode 100644 index 6766a43..0000000 --- a/EfCore.NamingConverter/NoneCaseNamingPolicy.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EfCore.NamingConverter -{ - internal class NoneCaseNamingPolicy : ConvertNamingPolicy - { - public override string ConvertName(string name) => name; - } -} diff --git a/EfCore.NamingConverter/SnakeCaseLowerNamingPolicy.cs b/EfCore.NamingConverter/SnakeCaseLowerNamingPolicy.cs deleted file mode 100644 index 04baebb..0000000 --- a/EfCore.NamingConverter/SnakeCaseLowerNamingPolicy.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EfCore.NamingConverter -{ - internal sealed class SnakeCaseLowerNamingPolicy : SeparatorNamingPolicy - { - public SnakeCaseLowerNamingPolicy() : base(lowercase: true, separator: '_') - { - } - } -} diff --git a/EfCore.NamingConverter/SnakeCaseUpperNamingPolicy.cs b/EfCore.NamingConverter/SnakeCaseUpperNamingPolicy.cs deleted file mode 100644 index 99f0562..0000000 --- a/EfCore.NamingConverter/SnakeCaseUpperNamingPolicy.cs +++ /dev/null @@ -1,10 +0,0 @@ - -namespace EfCore.NamingConverter -{ - internal class SnakeCaseUpperNamingPolicy : SeparatorNamingPolicy - { - public SnakeCaseUpperNamingPolicy() : base(lowercase: false, separator: '_') - { - } - } -}