File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed
Statement/ColumnConstraint
Internal/Statement/ColumnConstraint Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 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\UniqueConstraintTest.cs" />
8384 <Compile Include =" Statement\ColumnStatementCollectionTest.cs" />
8485 <Compile Include =" Statement\PrimaryKeyStatementTest.cs" />
8586 <Compile Include =" Statement\CreateDatabaseStatementTest.cs" />
Original file line number Diff line number Diff line change 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 UniqueConstraintTest
8+ {
9+ [ TestMethod ]
10+ public void CreateStatement_StatementIsCorrect_NoConstraint ( )
11+ {
12+ var uniqueConstraint = new UniqueConstraint ( ) ;
13+ uniqueConstraint . OnConflict = OnConflictAction . None ;
14+ string output = uniqueConstraint . CreateStatement ( ) ;
15+ Assert . AreEqual ( output , "UNIQUE" ) ;
16+ }
17+
18+ [ TestMethod ]
19+ public void CreateStatement_StatementIsCorrect_WithConstraint ( )
20+ {
21+ var uniqueConstraint = new UniqueConstraint ( ) ;
22+ uniqueConstraint . OnConflict = OnConflictAction . Rollback ;
23+ string output = uniqueConstraint . CreateStatement ( ) ;
24+ Assert . AreEqual ( output , "UNIQUE ON CONFLICT ROLLBACK" ) ;
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ using System . Text ;
2+
3+ namespace SQLite . CodeFirst . Statement . ColumnConstraint
4+ {
5+ internal class UniqueConstraint : IColumnConstraint
6+ {
7+ private const string Template = "UNIQUE {conflict-clause}" ;
8+
9+ public OnConflictAction OnConflict { get ; set ; }
10+
11+ public string CreateStatement ( )
12+ {
13+ var sb = new StringBuilder ( Template ) ;
14+
15+ sb . Replace ( "{conflict-clause}" , OnConflict != OnConflictAction . None ? "ON CONFLICT " + OnConflict . ToString ( ) . ToUpperInvariant ( ) : string . Empty ) ;
16+
17+ return sb . ToString ( ) . Trim ( ) ;
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 8989 <Compile Include =" Internal\Builder\NameCreators\IndexNameCreator.cs" />
9090 <Compile Include =" Internal\Builder\NameCreators\SpecialChars.cs" />
9191 <Compile Include =" IDatabaseCreator.cs" />
92+ <Compile Include =" Internal\Statement\ColumnConstraint\UniqueConstraint.cs" />
9293 <Compile Include =" Internal\Utility\HashCreator.cs" />
9394 <Compile Include =" Internal\Utility\HistoryEntityTypeValidator.cs" />
9495 <Compile Include =" ISqliteSqlGenerator.cs" />
You can’t perform that action at this time.
0 commit comments