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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.snk binary

*.verified.* text eol=lf working-tree-encoding=UTF-8
*.verified.png binary

.editorconfig text eol=lf working-tree-encoding=UTF-8
*.sln.DotSettings text eol=lf working-tree-encoding=UTF-8
Expand Down
95 changes: 90 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ await Verify(connection)
// include only tables and views
.SchemaIncludes(DbObjects.Tables | DbObjects.Views);
```
<sup><a href='/src/Tests/Tests.cs#L705-L711' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L753-L759' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Available values:
Expand Down Expand Up @@ -107,10 +107,95 @@ await Verify(connection)
_ => _ is TableViewBase ||
_.Name == "MyTrigger");
```
<sup><a href='/src/Tests/Tests.cs#L730-L738' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L778-L786' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


#### Diagram

The tables of a schema can instead be verified as a [Mermaid ER diagram](https://mermaid.js.org/syntax/entityRelationshipDiagram.html), using [DbToMermaid](https://github.com/SimonCropp/DbToMermaid). Requires net10.0 or higher.

<!-- snippet: SqlServerSchemaAsDiagram -->
<a id='snippet-SqlServerSchemaAsDiagram'></a>
```cs
await Verify(connection)
.SchemaAsDiagram();
```
<sup><a href='/src/Tests/Tests.cs#L342-L347' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchemaAsDiagram' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result: [Tests.SchemaAsDiagram.verified.md](/src/Tests/Tests.SchemaAsDiagram.verified.md)

The diagram can be verified as markdown, svg, png, or any combination. One file is verified for each format.

<!-- snippet: SqlServerSchemaAsDiagramFormats -->
<a id='snippet-SqlServerSchemaAsDiagramFormats'></a>
```cs
await Verify(connection)
.SchemaAsDiagram(
DiagramFormat.Markdown |
DiagramFormat.Svg |
DiagramFormat.Png);
```
<sup><a href='/src/Tests/Tests.cs#L356-L364' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchemaAsDiagramFormats' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Result:

* [Tests.SchemaAsDiagramFormats.verified.md](/src/Tests/Tests.SchemaAsDiagramFormats.verified.md)
* [Tests.SchemaAsDiagramFormats.verified.svg](/src/Tests/Tests.SchemaAsDiagramFormats.verified.svg)
* [Tests.SchemaAsDiagramFormats.verified.png](/src/Tests/Tests.SchemaAsDiagramFormats.verified.png)

<img src="/src/Tests/Tests.SchemaAsDiagramFormats.verified.png" alt="Tests.SchemaAsDiagramFormats.verified.png">

Available values:

<!-- snippet: DiagramFormat.cs -->
<a id='snippet-DiagramFormat.cs'></a>
```cs
namespace VerifyTests.SqlServer;

/// <summary>
/// The files produced when a schema is verified as a diagram. Can be combined.
/// </summary>
[Flags]
public enum DiagramFormat
{
/// <summary>
/// A Mermaid ER diagram in a markdown code block. Uses the `md` extension.
/// </summary>
Markdown = 1,

/// <summary>
/// The diagram rendered to an image. Uses the `svg` extension.
/// </summary>
Svg = 2,

/// <summary>
/// The diagram rendered to an image. Uses the `png` extension.
/// </summary>
Png = 4,

All = Markdown | Svg | Png
}
```
<sup><a href='/src/Verify.SqlServer/SchemaValidation/DiagramFormat.cs#L1-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-DiagramFormat.cs' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

`SchemaIncludes` and `SchemaFilter` do not apply to a diagram. All tables are included.

A rendered png may not be pixel identical across machines, so compare using [ssim](https://github.com/VerifyTests/Verify/blob/main/docs/comparer.md):

<!-- snippet: UseSsimForPng -->
<a id='snippet-UseSsimForPng'></a>
```cs
VerifierSettings.UseSsimForPng();
```
<sup><a href='/src/Tests/ModuleInit.cs#L14-L18' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseSsimForPng' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The svg and png are rendered by [Naiad](https://github.com/Papyrine/Naiad). Its build check requires a sponsorship, or exemption, property to be set in the consuming project. The build error lists the options.


### Recording

Expand All @@ -129,7 +214,7 @@ command.CommandText = "select Value from MyTable";
var value = await command.ExecuteScalarAsync();
await Verify(value!);
```
<sup><a href='/src/Tests/Tests.cs#L514-L524' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L562-L572' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will result in the following verified file:
Expand Down Expand Up @@ -184,7 +269,7 @@ await Verify(
sqlEntries = entries
});
```
<sup><a href='/src/Tests/Tests.cs#L591-L621' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L639-L669' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -212,7 +297,7 @@ var sqlErrorsViaType = entries
.Select(_ => _.Data)
.OfType<ErrorEntry>();
```
<sup><a href='/src/Tests/Tests.cs#L647-L666' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Tests.cs#L695-L714' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
4 changes: 3 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;CS8632;NU1608;NU1109</NoWarn>
<Version>12.2.0</Version>
<Version>12.3.0</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>SqlServer, Verify</PackageTags>
Expand All @@ -13,5 +13,7 @@
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<Verify_SponsorshipExemption>OpenSource</Verify_SponsorshipExemption>
<Verify_SponsorshipExemptionUntil>2027-08</Verify_SponsorshipExemptionUntil>
<Papyrine_SponsorshipExemption>OpenSource</Papyrine_SponsorshipExemption>
<Papyrine_SponsorshipExemptionUntil>2027-08</Papyrine_SponsorshipExemptionUntil>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageVersion Include="Microsoft.SqlServer.SqlManagementObjects" Version="181.37.1" />
<PackageVersion Include="ProjectDefaults" Version="1.0.184" />
<PackageVersion Include="Sbom" Version="0.3.1" />
<PackageVersion Include="SqlServerToMermaid" Version="2.2.0" />
<PackageVersion Include="TUnit" Version="1.73.5" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.12" />
<PackageVersion Include="Verify" Version="33.3.2-beta.1" />
Expand Down
10 changes: 9 additions & 1 deletion src/Tests/ModuleInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ public static void Init() =>
#endregion

[ModuleInitializer]
public static void InitOther() =>
public static void InitOther()
{
#region UseSsimForPng

VerifierSettings.UseSsimForPng();

#endregion

VerifierSettings.InitializePlugins();
}
}
78 changes: 78 additions & 0 deletions src/Tests/Tests.SchemaAsDiagram.verified.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
```mermaid
erDiagram
TestSchema_SchemaTable["**TestSchema_SchemaTable**"] {
int Id pk
nvarchar(50) Name
}
ChildTable["**ChildTable**"] {
int Id pk
int ParentId
int Value
}
ColumnTypes["**ColumnTypes**"] {
int Id pk
nvarchar(100) Name
nvarchar(max)(nullable) Description
varchar(20)(nullable) Code
decimal(18,4) Amount
bit IsActive
datetime2 Created
timestamp RowVersion
money(nullable) Price
float(nullable) Ratio
smallint(nullable) SmallNum
tinyint(nullable) TinyNum
bigint(nullable) BigNum
uniqueidentifier(nullable) UniqueCode
text(nullable) Notes
varbinary(500)(nullable) BinaryData
varbinary(max)(nullable) MaxBinary
char(10)(nullable) FixedChar
binary(16)(nullable) FixedBinary
time(nullable) TimeOnly
date(nullable) DateOnly
ntext(nullable) NText
xml(nullable) Xml
}
CompositeKeyTable["**CompositeKeyTable**"] {
int Key1 pk
int Key2 pk
nvarchar(200)(nullable) Data
}
MultiIndexTable["**MultiIndexTable**"] {
int Id pk
nvarchar(100) Name
nvarchar(50) Category
int Status
}
MultiTriggerTable["**MultiTriggerTable**"] {
int Id pk
nvarchar(100)(nullable) Name
}
MyOtherTable["**MyOtherTable**"] {
int(nullable) Value
}
MyTable["**MyTable**"] {
int(nullable) Value
}
ParentTable["**ParentTable**"] {
int Id pk
nvarchar(100) Name
}
WithComputed["**WithComputed**"] {
int Id pk
nvarchar(50) FirstName
nvarchar(50) LastName
nvarchar(101) FullName "computed"
int Quantity
decimal(10,2) UnitPrice
decimal(21,2)(nullable) TotalPrice "computed"
}
WithDefaults["**WithDefaults**"] {
int Id pk
varchar(20) Status
datetime2 Created
int Score
}
ParentTable ||--o{ ChildTable : "FK_ChildTable_ParentTable"
```
78 changes: 78 additions & 0 deletions src/Tests/Tests.SchemaAsDiagramFormats.verified.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
```mermaid
erDiagram
TestSchema_SchemaTable["**TestSchema_SchemaTable**"] {
int Id pk
nvarchar(50) Name
}
ChildTable["**ChildTable**"] {
int Id pk
int ParentId
int Value
}
ColumnTypes["**ColumnTypes**"] {
int Id pk
nvarchar(100) Name
nvarchar(max)(nullable) Description
varchar(20)(nullable) Code
decimal(18,4) Amount
bit IsActive
datetime2 Created
timestamp RowVersion
money(nullable) Price
float(nullable) Ratio
smallint(nullable) SmallNum
tinyint(nullable) TinyNum
bigint(nullable) BigNum
uniqueidentifier(nullable) UniqueCode
text(nullable) Notes
varbinary(500)(nullable) BinaryData
varbinary(max)(nullable) MaxBinary
char(10)(nullable) FixedChar
binary(16)(nullable) FixedBinary
time(nullable) TimeOnly
date(nullable) DateOnly
ntext(nullable) NText
xml(nullable) Xml
}
CompositeKeyTable["**CompositeKeyTable**"] {
int Key1 pk
int Key2 pk
nvarchar(200)(nullable) Data
}
MultiIndexTable["**MultiIndexTable**"] {
int Id pk
nvarchar(100) Name
nvarchar(50) Category
int Status
}
MultiTriggerTable["**MultiTriggerTable**"] {
int Id pk
nvarchar(100)(nullable) Name
}
MyOtherTable["**MyOtherTable**"] {
int(nullable) Value
}
MyTable["**MyTable**"] {
int(nullable) Value
}
ParentTable["**ParentTable**"] {
int Id pk
nvarchar(100) Name
}
WithComputed["**WithComputed**"] {
int Id pk
nvarchar(50) FirstName
nvarchar(50) LastName
nvarchar(101) FullName "computed"
int Quantity
decimal(10,2) UnitPrice
decimal(21,2)(nullable) TotalPrice "computed"
}
WithDefaults["**WithDefaults**"] {
int Id pk
varchar(20) Status
datetime2 Created
int Score
}
ParentTable ||--o{ ChildTable : "FK_ChildTable_ParentTable"
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading