|
1 |
| -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Data;
|
3 | 4 | using System.Globalization;
|
4 | 5 | using Microsoft.Extensions.Configuration;
|
@@ -133,7 +134,7 @@ public void ConfigureColumnOptionsAddsColumnIdBigIntOption()
|
133 | 134 | {
|
134 | 135 | // Arrange
|
135 | 136 | SetupConfigurationSectionMocks();
|
136 |
| - var columnSectionMock = SetupColumnSectionMock("id"); |
| 137 | + var columnSectionMock = SetupColumnSectionMock("id"); |
137 | 138 | columnSectionMock.Setup(s => s["bigInt"]).Returns("true");
|
138 | 139 | var sut = new MicrosoftExtensionsColumnOptionsProvider();
|
139 | 140 |
|
@@ -475,7 +476,7 @@ public void ConfigureColumnOptionsAddsColumnLogEventExcludeStandardColumnsOption
|
475 | 476 | // Arrange
|
476 | 477 | SetupConfigurationSectionMocks();
|
477 | 478 | var columnSectionMock = SetupColumnSectionMock("logEvent");
|
478 |
| - columnSectionMock.Setup(s => s["ExcludeStandardColumns"]).Returns("true"); |
| 479 | + columnSectionMock.Setup(s => s["excludeStandardColumns"]).Returns("true"); |
479 | 480 | var sut = new MicrosoftExtensionsColumnOptionsProvider();
|
480 | 481 |
|
481 | 482 | // Act
|
@@ -572,6 +573,91 @@ public void ConfigureColumnOptionsAddsClusteredColumnstoreIndexOption()
|
572 | 573 | Assert.True(result.ClusteredColumnstoreIndex);
|
573 | 574 | }
|
574 | 575 |
|
| 576 | + [Fact] |
| 577 | + public void ConfigureColumnOptionsThrowsWhenSettingPrimaryKeyColumnNameAndClusteredColumnstoreIndex() |
| 578 | + { |
| 579 | + // Arrange |
| 580 | + SetupConfigurationSectionMocks(); |
| 581 | + _configurationSectionMock.Setup(s => s["primaryKeyColumnName"]).Returns("TestPrimaryKeyColumnName"); |
| 582 | + _configurationSectionMock.Setup(s => s["clusteredColumnstoreIndex"]).Returns("true"); |
| 583 | + var sut = new MicrosoftExtensionsColumnOptionsProvider(); |
| 584 | + |
| 585 | + // Act + assert |
| 586 | + Assert.Throws<ArgumentException>(() => sut.ConfigureColumnOptions(new ColumnOptions(), _configurationSectionMock.Object)); |
| 587 | + } |
| 588 | + |
| 589 | + [Fact] |
| 590 | + public void ConfigureColumnOptionsSetsPrimaryKeyWhenSettingPrimaryKeyColumnNameToStandardColumnName() |
| 591 | + { |
| 592 | + // Arrange |
| 593 | + SetupConfigurationSectionMocks(); |
| 594 | + _configurationSectionMock.Setup(s => s["primaryKeyColumnName"]).Returns("Message"); |
| 595 | + var sut = new MicrosoftExtensionsColumnOptionsProvider(); |
| 596 | + |
| 597 | + // Act |
| 598 | + var result = sut.ConfigureColumnOptions(new ColumnOptions(), _configurationSectionMock.Object); |
| 599 | + |
| 600 | + // Assert |
| 601 | + Assert.Equal(result.Message, result.PrimaryKey); |
| 602 | + } |
| 603 | + |
| 604 | + [Fact] |
| 605 | + public void ConfigureColumnOptionsSetsPrimaryKeyWhenSettingPrimaryKeyColumnNameToAdditionalColumn() |
| 606 | + { |
| 607 | + // Arrange |
| 608 | + const string customColumnName = "TestCustomColumn"; |
| 609 | + var customColumn = new SqlColumn { ColumnName = customColumnName }; |
| 610 | + var columnOptions = new ColumnOptions |
| 611 | + { |
| 612 | + PrimaryKey = null, |
| 613 | + AdditionalColumns = new List<SqlColumn> { customColumn } |
| 614 | + }; |
| 615 | + SetupConfigurationSectionMocks(); |
| 616 | + _configurationSectionMock.Setup(s => s["primaryKeyColumnName"]).Returns(customColumnName); |
| 617 | + var sut = new MicrosoftExtensionsColumnOptionsProvider(); |
| 618 | + |
| 619 | + // Act |
| 620 | + var result = sut.ConfigureColumnOptions(columnOptions, _configurationSectionMock.Object); |
| 621 | + |
| 622 | + // Assert |
| 623 | + Assert.Equal(customColumn, result.PrimaryKey); |
| 624 | + } |
| 625 | + |
| 626 | + [Fact] |
| 627 | + public void ConfigureColumnOptionsSetsPrimaryKeyWhenSettingPrimaryKeyColumnNameToAdditionalColumnCaseInsensitive() |
| 628 | + { |
| 629 | + // Arrange |
| 630 | + var customColumn = new SqlColumn { ColumnName = "TestCustomColumn" }; |
| 631 | + var columnOptions = new ColumnOptions |
| 632 | + { |
| 633 | + PrimaryKey = null, |
| 634 | + AdditionalColumns = new List<SqlColumn> { customColumn } |
| 635 | + }; |
| 636 | + SetupConfigurationSectionMocks(); |
| 637 | + _configurationSectionMock.Setup(s => s["primaryKeyColumnName"]).Returns("testCustomColumn"); |
| 638 | + var sut = new MicrosoftExtensionsColumnOptionsProvider(); |
| 639 | + |
| 640 | + // Act |
| 641 | + var result = sut.ConfigureColumnOptions(columnOptions, _configurationSectionMock.Object); |
| 642 | + |
| 643 | + // Assert |
| 644 | + Assert.Equal(customColumn, result.PrimaryKey); |
| 645 | + } |
| 646 | + |
| 647 | + [Fact] |
| 648 | + public void ConfigureColumnOptionsThrowsWhenSettingPrimaryKeyColumnNameToUndefinedColumnNameAndPrimaryKeyRemainsNull() |
| 649 | + { |
| 650 | + // Arrange |
| 651 | + var columnOptions = new ColumnOptions(); |
| 652 | + columnOptions.PrimaryKey = null; |
| 653 | + SetupConfigurationSectionMocks(); |
| 654 | + _configurationSectionMock.Setup(s => s["primaryKeyColumnName"]).Returns("TestUndefinedPrimaryKeyColumnName"); |
| 655 | + var sut = new MicrosoftExtensionsColumnOptionsProvider(); |
| 656 | + |
| 657 | + // Act + assert |
| 658 | + Assert.Throws<ArgumentException>(() => sut.ConfigureColumnOptions(columnOptions, _configurationSectionMock.Object)); |
| 659 | + } |
| 660 | + |
575 | 661 | private static void AssertColumnSqlOptions(string expectedColumnName, SqlDbType expectedDataType, bool expectedAllowNull, bool expectedNonClusteredIndex, SqlColumn actualColumn)
|
576 | 662 | {
|
577 | 663 | Assert.Equal(expectedColumnName, actualColumn.ColumnName);
|
|
0 commit comments