Skip to content

Commit baf3d43

Browse files
(#10) Test for edges where the developer is being obtuse
1 parent 66b683a commit baf3d43

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/Stravaig.Configuration.SqlServer.Tests/SourceBuilderTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,44 @@ namespace Stravaig.Configuration.SqlServer.Tests;
99
[TestFixture]
1010
public class SourceBuilderTests
1111
{
12+
[Test]
13+
public void DeveloperIsBeingObtuseByDeliberatelyNullingSchema_ThrowsException()
14+
{
15+
// Arrange
16+
const string theConnectionString = "Server=MyServer;Database=MyDatabase";
17+
var options = (SqlServerConfigurationOptions opts) =>
18+
{
19+
opts.ConnectionString = theConnectionString;
20+
opts.SchemaName = null!;
21+
};
22+
var configBuilder = SetupConfig();
23+
24+
// Act & Assert
25+
var ex = Should.Throw<SqlServerConfigurationProviderException>(
26+
() => SourceBuilder.BuildSource(configBuilder, options));
27+
28+
ex.Message.ShouldBe("The schema name is required to use SQL Server Configuration.");
29+
}
30+
31+
[Test]
32+
public void DeveloperIsBeingObtuseByDeliberatelyNullingTable_ThrowsException()
33+
{
34+
// Arrange
35+
const string theConnectionString = "Server=MyServer;Database=MyDatabase";
36+
var options = (SqlServerConfigurationOptions opts) =>
37+
{
38+
opts.ConnectionString = theConnectionString;
39+
opts.TableName = null!;
40+
};
41+
var configBuilder = SetupConfig();
42+
43+
// Act & Assert
44+
var ex = Should.Throw<SqlServerConfigurationProviderException>(
45+
() => SourceBuilder.BuildSource(configBuilder, options));
46+
47+
ex.Message.ShouldBe("The table name is required to use SQL Server Configuration.");
48+
}
49+
1250
[Test]
1351
public void SimplestOptions_HappyPath()
1452
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nulling/@EntryIndexedValue">True</s:Boolean>
23
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stravaig/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/Stravaig.Configuration.SqlServer/SourceBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static SqlServerConfigurationSource BuildSource(IConfigurationBuilder bui
2323
return new SqlServerConfigurationSource(
2424
options.ConnectionString ?? throw new SqlServerConfigurationProviderException("Cannot build a SQL Server Configuration Provider without a connection string."),
2525
TimeSpan.FromSeconds(options.RefreshSeconds),
26-
options.SchemaName,
27-
options.TableName);
26+
options.SchemaName ?? throw new SqlServerConfigurationProviderException("The schema name is required to use SQL Server Configuration."),
27+
options.TableName ?? throw new SqlServerConfigurationProviderException("The table name is required to use SQL Server Configuration."));
2828
}
2929

3030
private static void ApplyFromConnectionStringsSection(SqlServerConfigurationOptions options, IConfigurationRoot configRoot)

0 commit comments

Comments
 (0)