-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
CSharpUniqueNamerTest.cs
67 lines (59 loc) · 2.58 KB
/
CSharpUniqueNamerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal;
public class CSharpUniqueNamerTest
{
[ConditionalFact]
public void Returns_unique_name_for_type()
{
var namer = new CSharpUniqueNamer<DatabaseColumn>(s => s.Name, new CSharpUtilities(), null, true);
var table = new DatabaseTable { Database = new DatabaseModel(), Name = "foo" };
var input1 = new DatabaseColumn
{
Table = table,
Name = "Id",
StoreType = "int"
};
var input2 = new DatabaseColumn
{
Table = table,
Name = "Id",
StoreType = "int"
};
Assert.Equal("Id", namer.GetName(input1));
Assert.Equal("Id", namer.GetName(input1));
Assert.Equal("Id1", namer.GetName(input2));
}
[ConditionalFact]
public void Uses_comparer()
{
var namer = new CSharpUniqueNamer<DatabaseTable>(t => t.Name, new CSharpUtilities(), null, true);
var database = new DatabaseModel();
var table1 = new DatabaseTable { Database = database, Name = "A B C" };
var table2 = new DatabaseTable { Database = database, Name = "A_B_C" };
Assert.Equal("A_B_C", namer.GetName(table1));
Assert.Equal("A_B_C1", namer.GetName(table2));
}
[ConditionalTheory]
[InlineData("Name ending with s", "Name_ending_with_")]
[InlineData("Name with no s at end", "Name_with_no_s_at_end")]
public void Singularizes_names(string input, string output)
{
var pluralizer = new HumanizerPluralizer();
var namer = new CSharpUniqueNamer<DatabaseTable>(t => t.Name, new CSharpUtilities(), pluralizer.Singularize, true);
var table = new DatabaseTable { Database = new DatabaseModel(), Name = input };
Assert.Equal(output, namer.GetName(table));
}
[ConditionalTheory]
[InlineData("Name ending with s", "Name_ending_with_s")]
[InlineData("Name with no s at end", "Name_with_no_s_at_ends")]
public void Pluralizes_names(string input, string output)
{
var pluralizer = new HumanizerPluralizer();
var namer = new CSharpUniqueNamer<DatabaseTable>(t => t.Name, new CSharpUtilities(), pluralizer.Pluralize, true);
var table = new DatabaseTable { Database = new DatabaseModel(), Name = input };
Assert.Equal(output, namer.GetName(table));
}
}