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 @@ -168,7 +168,7 @@ await Verify(
entries
});
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L648-L673' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L682-L707' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -265,7 +265,7 @@ await data

await Verify();
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L519-L542' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingDisableForInstance' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L553-L576' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingDisableForInstance' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

<!-- snippet: CoreTests.RecordingDisabledTest.verified.txt -->
Expand Down Expand Up @@ -623,7 +623,7 @@ protected override void ConfigureWebHost(IWebHostBuilder webBuilder)
_ => dataBuilder.Options));
}
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L602-L614' title='Snippet source file'>snippet source</a> | <a href='#snippet-EnableRecordingWithIdentifier' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L636-L648' title='Snippet source file'>snippet source</a> | <a href='#snippet-EnableRecordingWithIdentifier' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Then use the same identifier for recording:
Expand All @@ -639,7 +639,7 @@ var companies = await httpClient.GetFromJsonAsync<Company[]>("/companies");

var entries = Recording.Stop(testName);
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L575-L585' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordWithIdentifier' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L609-L619' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordWithIdentifier' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The results will not be automatically included in verified file so it will have to be verified manually:
Expand All @@ -654,7 +654,7 @@ await Verify(
sql = entries
});
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L587-L596' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyRecordedCommandsWithIdentifier' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L621-L630' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyRecordedCommandsWithIdentifier' 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;EF1001;NU1608;NU1109</NoWarn>
<Version>15.0.1</Version>
<Version>15.0.2</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>EntityFramework, Verify</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
ef: {
Type: ReaderExecutedAsync,
HasTransaction: false,
Parameters: {
@ids1 (Int32): 1,
@ids2 (Int32): 2,
@ids3 (Int32): 4,
@ids4 (Int32): 6
},
Text:
select c.Id,
c.Name
from Companies as c
where c.Id in (@ids1,
@ids2,
@ids3,
@ids4)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
ef: {
Type: ReaderExecutedAsync,
HasTransaction: false,
Parameters: {
@ids1 (Int32): 1,
@ids2 (Int32): 2,
@ids3 (Int32): 4
},
Text:
select c.Id,
c.Name
from Companies as c
where c.Id not in (@ids1,
@ids2,
@ids3)
}
}
34 changes: 34 additions & 0 deletions src/Verify.EntityFramework.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,40 @@ await data
await Verify();
}

[Test]
public async Task RecordingInClause()
{
var database = await DbContextBuilder.GetDatabase();
var data = database.Context;

Recording.Start();

var ids = new[] { 1, 2, 4, 6 };
await data
.Companies
.Where(_ => ids.Contains(_.Id))
.ToListAsync();

await Verify();
}

[Test]
public async Task RecordingNotInClause()
{
var database = await DbContextBuilder.GetDatabase();
var data = database.Context;

Recording.Start();

var ids = new[] { 1, 2, 4 };
await data
.Companies
.Where(_ => !ids.Contains(_.Id))
.ToListAsync();

await Verify();
}

[Test]
public async Task RecordingDisabledTest()
{
Expand Down
33 changes: 33 additions & 0 deletions src/Verify.EntityFramework/FormattedScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@ public string GenerateScript(TSqlFragment fragment)
script = string.Concat(script.AsSpan(0, pos), multiLine, script.AsSpan(pos + singleLine.Length));
}

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);

var multiLine = string.Join(",\n" + indent, values);

script = string.Concat(script.AsSpan(0, pos), multiLine, script.AsSpan(pos + singleLine.Length));
}

return script;
}
}
7 changes: 7 additions & 0 deletions src/Verify.EntityFramework/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);
}