Skip to content

Commit 3689a3a

Browse files
author
Marc Sallin
committed
#42: Added CollateConstraint and tests.
1 parent 5306d64 commit 3689a3a

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

SQLite.CodeFirst.Test/SQLite.CodeFirst.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Compile Include="Statement\ColumnConstraint\MaxLengthConstraint.cs" />
8181
<Compile Include="Statement\ColumnConstraint\ColumnConstraintCollectionTest.cs" />
8282
<Compile Include="Statement\ColumnConstraint\NotNullConstraintTest.cs" />
83+
<Compile Include="Statement\ColumnConstraint\CollateConstraintTest.cs" />
8384
<Compile Include="Statement\ColumnConstraint\UniqueConstraintTest.cs" />
8485
<Compile Include="Statement\ColumnStatementCollectionTest.cs" />
8586
<Compile Include="Statement\PrimaryKeyStatementTest.cs" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using SQLite.CodeFirst.Statement.ColumnConstraint;
3+
4+
namespace SQLite.CodeFirst.Test.Statement.ColumnConstraint
5+
{
6+
[TestClass]
7+
public class CollateConstraintTest
8+
{
9+
[TestMethod]
10+
public void CreateStatement_StatementIsCorrect_NoConstraint()
11+
{
12+
var collationConstraint = new CollateConstraint();
13+
collationConstraint.CollationFunction = CollationFunction.None;
14+
string output = collationConstraint.CreateStatement();
15+
Assert.AreEqual(output, "");
16+
}
17+
18+
[TestMethod]
19+
public void CreateStatement_StatementIsCorrect_NoCase()
20+
{
21+
var collationConstraint = new CollateConstraint();
22+
collationConstraint.CollationFunction = CollationFunction.NoCase;
23+
string output = collationConstraint.CreateStatement();
24+
Assert.AreEqual(output, "COLLATE NOCASE");
25+
}
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Text;
2+
3+
namespace SQLite.CodeFirst.Statement.ColumnConstraint
4+
{
5+
internal class CollateConstraint : IColumnConstraint
6+
{
7+
private const string Template = "COLLATE {collation-name}";
8+
9+
public CollationFunction CollationFunction { get; set; }
10+
11+
public string CreateStatement()
12+
{
13+
if (CollationFunction == CollationFunction.None)
14+
{
15+
return string.Empty;
16+
}
17+
18+
var sb = new StringBuilder(Template);
19+
20+
sb.Replace("{collation-name}", CollationFunction.ToString().ToUpperInvariant());
21+
22+
return sb.ToString().Trim();
23+
}
24+
}
25+
}

SQLite.CodeFirst/SQLite.CodeFirst.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<Compile Include="Internal\Builder\NameCreators\IndexNameCreator.cs" />
9292
<Compile Include="Internal\Builder\NameCreators\SpecialChars.cs" />
9393
<Compile Include="IDatabaseCreator.cs" />
94+
<Compile Include="Internal\Statement\ColumnConstraint\CollateConstraint.cs" />
9495
<Compile Include="Internal\Statement\ColumnConstraint\UniqueConstraint.cs" />
9596
<Compile Include="Internal\Utility\HashCreator.cs" />
9697
<Compile Include="Internal\Utility\HistoryEntityTypeValidator.cs" />

0 commit comments

Comments
 (0)