-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
688 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using EfCore.NamingConverter; | ||
using EfCore.NamingConverter.Sample; | ||
|
||
MyDbContext context = new(); | ||
|
||
|
93 changes: 93 additions & 0 deletions
93
EfCore.NamingConverter.Tests/CamelCaseNamingPolicyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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<IConventionPropertyBuilder> | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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<ArgumentOutOfRangeException>(() => 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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
EfCore.NamingConverter.Tests/KebabCaseLowerNamingPolicyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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<ArgumentNullException>(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); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
EfCore.NamingConverter.Tests/KebabCaseUpperNamingPolicyTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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<ArgumentNullException>(() => 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); | ||
} | ||
} | ||
} |
Oops, something went wrong.