@@ -22,6 +22,64 @@ public void AddIndex_TableDoesNotExist()
2222 Assert . Throws < MigrationException > ( ( ) => Provider . AddIndex ( "NotExistingIndex" , "NotExistingTable" , "column" ) ) ;
2323 }
2424
25+ [ Test ]
26+ public void AddIndex_AddAlreadyExistingIndex_Throws ( )
27+ {
28+ // Arrange
29+ const string tableName = "TestTable" ;
30+ const string columnName = "TestColumn" ;
31+ const string indexName = "TestIndexName" ;
32+
33+ Provider . AddTable ( tableName , new Column ( columnName , DbType . Int32 ) ) ;
34+ Provider . AddIndex ( tableName , new Index { Name = indexName , KeyColumns = [ columnName ] } ) ;
35+
36+ // Act/Assert
37+ // Add already existing index
38+ Assert . Throws < MigrationException > ( ( ) => Provider . AddIndex ( tableName , new Index { Name = indexName , KeyColumns = [ columnName ] } ) ) ;
39+ }
40+
41+ [ Test ]
42+ public void AddIndex_IncludeColumnsContainsColumnThatExistInKeyColumns_Throws ( )
43+ {
44+ // Arrange
45+ const string tableName = "TestTable" ;
46+ const string columnName1 = "TestColumn1" ;
47+ const string indexName = "TestIndexName" ;
48+
49+ Provider . AddTable ( tableName , new Column ( columnName1 , DbType . Int32 ) ) ;
50+
51+ Assert . Throws < MigrationException > ( ( ) => Provider . AddIndex ( tableName ,
52+ new Index
53+ {
54+ Name = indexName ,
55+ KeyColumns = [ columnName1 ] ,
56+ IncludeColumns = [ columnName1 ]
57+ } ) ) ;
58+ }
59+
60+ [ Test ]
61+ public void AddIndex_ColumnNameUsedInFilterItemDoesNotExistInKeyColumns_Throws ( )
62+ {
63+ // Arrange
64+ const string tableName = "TestTable" ;
65+ const string columnName1 = "TestColumn1" ;
66+ const string columnName2 = "TestColumn2" ;
67+ const string indexName = "TestIndexName" ;
68+
69+ Provider . AddTable ( tableName ,
70+ new Column ( columnName1 , DbType . Int32 ) ,
71+ new Column ( columnName2 , DbType . Int32 )
72+ ) ;
73+
74+ Assert . Throws < MigrationException > ( ( ) => Provider . AddIndex ( tableName ,
75+ new Index
76+ {
77+ Name = indexName ,
78+ KeyColumns = [ columnName1 ] ,
79+ FilterItems = [ new FilterItem { Filter = FilterType . GreaterThan , ColumnName = columnName2 , Value = 12 } ]
80+ } ) ) ;
81+ }
82+
2583 [ Test ]
2684 public void AddIndex_UsingIndexInstanceOverload_NonUnique_ShouldBeReadable ( )
2785 {
@@ -30,7 +88,7 @@ public void AddIndex_UsingIndexInstanceOverload_NonUnique_ShouldBeReadable()
3088 const string columnName = "TestColumn" ;
3189 const string indexName = "TestIndexName" ;
3290
33- Provider . AddTable ( tableName , new Column ( columnName , System . Data . DbType . Int32 ) ) ;
91+ Provider . AddTable ( tableName , new Column ( columnName , DbType . Int32 ) ) ;
3492
3593 // Act
3694 Provider . AddIndex ( tableName , new Index { Name = indexName , KeyColumns = [ columnName ] } ) ;
0 commit comments