|
1 | | -using System.Collections.Generic; |
2 | 1 | using System.Data; |
3 | 2 | using System.Linq; |
4 | 3 | using System.Threading.Tasks; |
5 | 4 | using DotNetProjects.Migrator.Framework; |
6 | | -using DotNetProjects.Migrator.Providers.Models.Indexes; |
7 | 5 | using DotNetProjects.Migrator.Providers.Models.Indexes.Enums; |
8 | 6 | using Migrator.Tests.Providers.Generic; |
9 | 7 | using NUnit.Framework; |
@@ -85,4 +83,64 @@ public void AddIndex_FilteredIndexGreaterOrEqualThanNumber_PartialIndexThrowsOnC |
85 | 83 | Assert.That(index.Unique, Is.True); |
86 | 84 | Assert.That(sqlException.Number, Is.EqualTo(2601)); |
87 | 85 | } |
| 86 | + |
| 87 | + [Test] |
| 88 | + public void AddIndex_IncludeColumnsSingle_Success() |
| 89 | + { |
| 90 | + // Arrange |
| 91 | + const string tableName = "TestTable"; |
| 92 | + const string columnName = "TestColumn"; |
| 93 | + const string columnName2 = "TestColumn2"; |
| 94 | + const string indexName = "TestIndexName"; |
| 95 | + |
| 96 | + Provider.AddTable(tableName, new Column(columnName, DbType.Int32), new Column(columnName2, DbType.String)); |
| 97 | + |
| 98 | + // Act |
| 99 | + Provider.AddIndex(tableName, |
| 100 | + new Index |
| 101 | + { |
| 102 | + Name = indexName, |
| 103 | + KeyColumns = [columnName], |
| 104 | + Unique = true, |
| 105 | + IncludeColumns = [columnName2] |
| 106 | + }); |
| 107 | + |
| 108 | + // Assert |
| 109 | + var index = Provider.GetIndexes(tableName).Single(); |
| 110 | + |
| 111 | + Assert.That(index.Unique, Is.True); |
| 112 | + Assert.That(index.KeyColumns.Single, Is.EqualTo(columnName).IgnoreCase); |
| 113 | + Assert.That(index.IncludeColumns.Single, Is.EqualTo(columnName2).IgnoreCase); |
| 114 | + } |
| 115 | + |
| 116 | + [Test] |
| 117 | + public void AddIndex_IncludeColumnsMultiple_Success() |
| 118 | + { |
| 119 | + // Arrange |
| 120 | + const string tableName = "TestTable"; |
| 121 | + const string columnName = "TestColumn"; |
| 122 | + const string columnName2 = "TestColumn2"; |
| 123 | + const string columnName3 = "TestColumn3"; |
| 124 | + const string indexName = "TestIndexName"; |
| 125 | + |
| 126 | + Provider.AddTable(tableName, new Column(columnName, DbType.Int32), new Column(columnName2, DbType.String), new Column(columnName3, DbType.Boolean)); |
| 127 | + |
| 128 | + // Act |
| 129 | + Provider.AddIndex(tableName, |
| 130 | + new Index |
| 131 | + { |
| 132 | + Name = indexName, |
| 133 | + KeyColumns = [columnName], |
| 134 | + Unique = true, |
| 135 | + IncludeColumns = [columnName2, columnName3] |
| 136 | + }); |
| 137 | + |
| 138 | + // Assert |
| 139 | + var index = Provider.GetIndexes(tableName).Single(); |
| 140 | + |
| 141 | + Assert.That(index.Unique, Is.True); |
| 142 | + Assert.That(index.KeyColumns.Single, Is.EqualTo(columnName).IgnoreCase); |
| 143 | + Assert.That(index.IncludeColumns, Is.EquivalentTo([columnName2, columnName3]) |
| 144 | + .Using<string>((x, y) => string.Compare(x, y, ignoreCase: true))); |
| 145 | + } |
88 | 146 | } |
0 commit comments