Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Tests/Tests.SchemaIncludesAndFilter.verified.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Tables
## Tables

### MyTable

Expand Down Expand Up @@ -30,4 +30,4 @@ AS
SELECT Value
FROM MyTable
WHERE (Value > 10);
```
```
9 changes: 9 additions & 0 deletions src/Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,15 @@ await Verify(connection)
.SchemaIncludes(DbObjects.Tables);
}

[Test]
public async Task SchemaMissingInitialCatalog()
{
var connection = new SqlConnection("Server=localhost");
var exception = Assert.ThrowsAsync<Exception>(
async () => await Verify(connection));
Assert.That(exception!.Message, Does.Contain("Initial Catalog"));
}

[Test]
public async Task SchemaIncludesAndFilter()
{
Expand Down
8 changes: 7 additions & 1 deletion src/Verify.SqlServer/SchemaValidation/SqlScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ public string BuildContent(SqlConnection connection)

string BuildContent(Server server, SqlConnectionStringBuilder builder)
{
var initialCatalog = builder.InitialCatalog;
if (string.IsNullOrWhiteSpace(initialCatalog))
{
throw new("The connection string must specify an Initial Catalog (database name) for schema verification.");
}

server.SetDefaultInitFields(typeof(Table), "Name", "IsSystemObject");
server.SetDefaultInitFields(typeof(View), "Name", "IsSystemObject");
server.SetDefaultInitFields(typeof(StoredProcedure), "Name", "IsSystemObject");
server.SetDefaultInitFields(typeof(UserDefinedFunction), "Name", "IsSystemObject");
server.SetDefaultInitFields(typeof(Trigger), "Name", "IsSystemObject");
server.SetDefaultInitFields(typeof(Synonym), "Name");
var database = server.Databases[builder.InitialCatalog];
var database = server.Databases[initialCatalog];
database.Tables.Refresh();

return GetScriptingObjects(database);
Expand Down
Loading