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
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ await Verify(connection)
// include only tables and views
.SchemaIncludes(DbObjects.Tables | DbObjects.Views);
```
<sup><a href='/src/Tests/Tests.cs#L423-L429' 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#L443-L449' 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 @@ -103,7 +103,7 @@ await Verify(connection)
_ => _ is TableViewBase ||
_.Name == "MyTrigger");
```
<sup><a href='/src/Tests/Tests.cs#L448-L456' 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#L468-L476' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -125,7 +125,7 @@ command.CommandText = "select Value from MyTable";
var value = await command.ExecuteScalarAsync();
await Verify(value!);
```
<sup><a href='/src/Tests/Tests.cs#L232-L242' 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#L252-L262' 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 @@ -180,7 +180,7 @@ await Verify(
sqlEntries = entries
});
```
<sup><a href='/src/Tests/Tests.cs#L309-L339' 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#L329-L359' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -208,7 +208,7 @@ var sqlErrorsViaType = entries
.Select(_ => _.Data)
.OfType<ErrorEntry>();
```
<sup><a href='/src/Tests/Tests.cs#L365-L384' 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#L385-L404' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 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>11.3.0</Version>
<Version>11.3.1</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>SqlServer, Verify</PackageTags>
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/Tests.CommandInClause.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
Text:
select Id,
Name
from MyTable
where Id in (1,
2,
4,
6),
HasTransaction: false
}
10 changes: 10 additions & 0 deletions src/Tests/Tests.CommandNotInClause.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
Text:
select Id,
Name
from MyTable
where Id not in (1,
2,
4),
HasTransaction: false
}
20 changes: 20 additions & 0 deletions src/Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ public async Task CommandOrderByMultipleColumnsDesc()
await Verify(command);
}

[Test]
public async Task CommandInClause()
{
var command = new SqlCommand
{
CommandText = "select Id, Name from MyTable where Id in (1, 2, 4, 6)"
};
await Verify(command);
}

[Test]
public async Task CommandNotInClause()
{
var command = new SqlCommand
{
CommandText = "select Id, Name from MyTable where Id not in (1, 2, 4)"
};
await Verify(command);
}

[Test]
public async Task Exception()
{
Expand Down
37 changes: 37 additions & 0 deletions src/Verify.SqlServer/FormattedScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ public string GenerateScript(TSqlFragment fragment)
#endif
}

var inCollector = new InPredicateCollector();
fragment.Accept(inCollector);

foreach (var inPredicate in inCollector.Predicates)
{
if (inPredicate.Values.Count <= 1)
{
continue;
}

var values = new List<string>(inPredicate.Values.Count);
foreach (var value in inPredicate.Values)
{
generator.GenerateScript(value, out var text);
values.Add(text);
}

var singleLine = string.Join(", ", values);

var pos = script.IndexOf(singleLine, StringComparison.Ordinal);
if (pos == -1)
{
continue;
}

var lineStart = script.LastIndexOf('\n', pos) + 1;
var indent = new string(' ', pos - lineStart);

#if NET48
var multiLine = string.Join(",\n" + indent, values);
script = script.Substring(0, pos) + multiLine + script.Substring(pos + singleLine.Length);
#else
var multiLine = string.Join(",\n" + indent, values);
script = string.Concat(script.AsSpan(0, pos), multiLine, script.AsSpan(pos + singleLine.Length));
#endif
}

return script;
}
}
7 changes: 7 additions & 0 deletions src/Verify.SqlServer/InPredicateCollector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class InPredicateCollector : TSqlFragmentVisitor
{
public List<InPredicate> Predicates { get; } = [];

public override void Visit(InPredicate node) =>
Predicates.Add(node);
}