This commit is contained in:
Simon Cropp 2020-11-08 19:53:02 +11:00
Родитель 16c35c9a23
Коммит 6ffc492771
26 изменённых файлов: 646 добавлений и 519 удалений

Просмотреть файл

@ -50,7 +50,7 @@ Enable VerifyEntityFramewok once at assembly load time:
```cs
VerifyEntityFramework.Enable();
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L291-L295' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablecore' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.cs#L289-L293' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablecore' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
@ -61,7 +61,7 @@ VerifyEntityFramework.Enable();
```cs
VerifyEntityFrameworkClassic.Enable();
```
<sup><a href='/src/Verify.EntityFrameworkClassic.Tests/ClassicTests.cs#L139-L143' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclassic' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFrameworkClassic.Tests/ClassicTests.cs#L137-L141' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclassic' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
@ -119,23 +119,25 @@ Will result in the following verified file:
<a id='snippet-CoreTests.Recording.verified.txt'></a>
```txt
{
target: '5',
target: 5,
sql: [
{
Type: 'ReaderExecutedAsync',
Text: "SELECT [c].[Id], [c].[Content]
Type: ReaderExecutedAsync,
Text:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'Title'"
WHERE [c].[Content] = N'Title'
},
{
Type: 'ReaderExecuted',
Text: 'SELECT COUNT(*)
FROM [Companies] AS [c]'
Type: ReaderExecuted,
Text:
SELECT COUNT(*)
FROM [Companies] AS [c]
}
]
}
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.Recording.verified.txt#L1-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-CoreTests.Recording.verified.txt' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.Recording.verified.txt#L1-L18' title='Snippet source file'>snippet source</a> | <a href='#snippet-CoreTests.Recording.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
@ -173,34 +175,37 @@ await Verifier.Verify(data2.Companies.Count());
<a id='snippet-CoreTests.MultiDbContexts.verified.txt'></a>
```txt
{
target: '5',
target: 5,
sql: [
{
Type: 'ReaderExecutedAsync',
Type: ReaderExecutedAsync,
HasTransaction: true,
Parameters: {
@p0: 0,
@p1: 'Title'
@p1: Title
},
Text: 'SET NOCOUNT ON;
Text:
SET NOCOUNT ON;
INSERT INTO [Companies] ([Id], [Content])
VALUES (@p0, @p1);'
VALUES (@p0, @p1);
},
{
Type: 'ReaderExecutedAsync',
Text: "SELECT [c].[Id], [c].[Content]
Type: ReaderExecutedAsync,
Text:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'Title'"
WHERE [c].[Content] = N'Title'
},
{
Type: 'ReaderExecuted',
Text: 'SELECT COUNT(*)
FROM [Companies] AS [c]'
Type: ReaderExecuted,
Text:
SELECT COUNT(*)
FROM [Companies] AS [c]
}
]
}
```
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.MultiDbContexts.verified.txt#L1-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-CoreTests.MultiDbContexts.verified.txt' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.EntityFramework.Tests/CoreTests.MultiDbContexts.verified.txt#L1-L30' title='Snippet source file'>snippet source</a> | <a href='#snippet-CoreTests.MultiDbContexts.verified.txt' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
@ -242,7 +247,7 @@ Will result in the following verified file:
Added: {
Company: {
Id: 0,
Content: 'before'
Content: before
}
}
}
@ -329,8 +334,8 @@ Will result in the following verified file:
Company: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}
@ -410,44 +415,44 @@ Will result in the following verified file with all data in the database:
```txt
[
{
$type: 'Company',
$type: Company,
Id: 1,
Content: 'Company1'
Content: Company1
},
{
$type: 'Company',
$type: Company,
Id: 4,
Content: 'Company2'
Content: Company2
},
{
$type: 'Company',
$type: Company,
Id: 6,
Content: 'Company3'
Content: Company3
},
{
$type: 'Company',
$type: Company,
Id: 7,
Content: 'Company4'
Content: Company4
},
{
$type: 'Employee',
$type: Employee,
Id: 2,
CompanyId: 1,
Content: 'Employee1',
Content: Employee1,
Age: 25
},
{
$type: 'Employee',
$type: Employee,
Id: 3,
CompanyId: 1,
Content: 'Employee2',
Content: Employee2,
Age: 31
},
{
$type: 'Employee',
$type: Employee,
Id: 5,
CompanyId: 4,
Content: 'Employee4',
Content: Employee4,
Age: 34
}
]

Просмотреть файл

@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;CS8632;EF1001</NoWarn>
<Version>5.0.0-beta.6</Version>
<Version>5.0.0-beta.7</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>EntityFramework, Verify</PackageTags>
<Description>Extends Verify (https://github.com/VerifyTests/Verify) to allow verification of EntityFramework bits.</Description>

Просмотреть файл

@ -2,7 +2,7 @@
Added: {
Company: {
Id: 0,
Content: 'before'
Content: before
}
}
}

Просмотреть файл

@ -1,43 +1,43 @@
[
{
$type: 'Company',
$type: Company,
Id: 1,
Content: 'Company1'
Content: Company1
},
{
$type: 'Company',
$type: Company,
Id: 4,
Content: 'Company2'
Content: Company2
},
{
$type: 'Company',
$type: Company,
Id: 6,
Content: 'Company3'
Content: Company3
},
{
$type: 'Company',
$type: Company,
Id: 7,
Content: 'Company4'
Content: Company4
},
{
$type: 'Employee',
$type: Employee,
Id: 2,
CompanyId: 1,
Content: 'Employee1',
Content: Employee1,
Age: 25
},
{
$type: 'Employee',
$type: Employee,
Id: 3,
CompanyId: 1,
Content: 'Employee2',
Content: Employee2,
Age: 31
},
{
$type: 'Employee',
$type: Employee,
Id: 5,
CompanyId: 4,
Content: 'Employee4',
Content: Employee4,
Age: 34
}
]

Просмотреть файл

@ -3,8 +3,8 @@
Company: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}

Просмотреть файл

@ -1,27 +1,30 @@
{
target: '5',
target: 5,
sql: [
{
Type: 'ReaderExecutedAsync',
Type: ReaderExecutedAsync,
HasTransaction: true,
Parameters: {
@p0: 0,
@p1: 'Title'
@p1: Title
},
Text: 'SET NOCOUNT ON;
Text:
SET NOCOUNT ON;
INSERT INTO [Companies] ([Id], [Content])
VALUES (@p0, @p1);'
VALUES (@p0, @p1);
},
{
Type: 'ReaderExecutedAsync',
Text: "SELECT [c].[Id], [c].[Content]
Type: ReaderExecutedAsync,
Text:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'Title'"
WHERE [c].[Content] = N'Title'
},
{
Type: 'ReaderExecuted',
Text: 'SELECT COUNT(*)
FROM [Companies] AS [c]'
Type: ReaderExecuted,
Text:
SELECT COUNT(*)
FROM [Companies] AS [c]
}
]
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,5 +1,6 @@
{
queryable: "SELECT [c].[Id], [c].[Content]
queryable:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'value'"
WHERE [c].[Content] = N'value'
}

Просмотреть файл

@ -1,16 +1,18 @@
{
target: '5',
target: 5,
sql: [
{
Type: 'ReaderExecutedAsync',
Text: "SELECT [c].[Id], [c].[Content]
Type: ReaderExecutedAsync,
Text:
SELECT [c].[Id], [c].[Content]
FROM [Companies] AS [c]
WHERE [c].[Content] = N'Title'"
WHERE [c].[Content] = N'Title'
},
{
Type: 'ReaderExecuted',
Text: 'SELECT COUNT(*)
FROM [Companies] AS [c]'
Type: ReaderExecuted,
Text:
SELECT COUNT(*)
FROM [Companies] AS [c]
}
]
}

Просмотреть файл

@ -3,8 +3,8 @@
Employee: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}

Просмотреть файл

@ -3,8 +3,8 @@
Employee: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}

Просмотреть файл

@ -3,15 +3,15 @@
Company: {
Id: 0,
Content: {
Original: 'companyBefore',
Current: 'companyAfter'
Original: companyBefore,
Current: companyAfter
}
},
Employee: {
Id: 0,
Content: {
Original: 'employeeBefore',
Current: 'employeeAfter'
Original: employeeBefore,
Current: employeeAfter
}
}
}

Просмотреть файл

@ -286,8 +286,6 @@ public class CoreTests
static CoreTests()
{
VerifierSettings.DisableNewLineEscaping();
#region EnableCore
VerifyEntityFramework.Enable();

Просмотреть файл

@ -10,7 +10,7 @@
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="MarkdownSnippets.MsBuild" Version="21.6.1" />
<PackageReference Include="Verify.NUnit" Version="8.0.0-beta.2" />
<PackageReference Include="Verify.NUnit" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="EfLocalDb" Version="9.0.0-beta.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Query.Internal;
@ -8,7 +9,11 @@ using VerifyTests;
class QueryableConverter :
WriteOnlyJsonConverter
{
public override void WriteJson(JsonWriter writer, object? data, JsonSerializer serializer)
public override void WriteJson(
JsonWriter writer,
object? data,
JsonSerializer serializer,
IReadOnlyDictionary<string, object> context)
{
if (data == null)
{

Просмотреть файл

@ -8,7 +8,11 @@ using VerifyTests;
class TrackerConverter :
WriteOnlyJsonConverter<ChangeTracker>
{
public override void WriteJson(JsonWriter writer, ChangeTracker? tracker, JsonSerializer serializer)
public override void WriteJson(
JsonWriter writer,
ChangeTracker? tracker,
JsonSerializer serializer,
IReadOnlyDictionary<string, object> context)
{
if (tracker == null)
{

Просмотреть файл

@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="Verify" Version="8.0.0-beta.2" />
<PackageReference Include="Verify" Version="8.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.20475.6" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />

Просмотреть файл

@ -2,7 +2,7 @@
Added: {
Company: {
Id: 0,
Content: 'before'
Content: before
}
}
}

Просмотреть файл

@ -3,8 +3,8 @@
Company: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}

Просмотреть файл

@ -3,8 +3,8 @@
Company: {
Id: 0,
Content: {
Original: 'before',
Current: 'after'
Original: before,
Current: after
}
}
}

Просмотреть файл

@ -3,15 +3,15 @@
Company: {
Id: 0,
Content: {
Original: 'companyBefore',
Current: 'companyAfter'
Original: companyBefore,
Current: companyAfter
}
},
Employee: {
Id: 0,
Content: {
Original: 'employeeBefore',
Current: 'employeeAfter'
Original: employeeBefore,
Current: employeeAfter
}
}
}

Просмотреть файл

@ -134,8 +134,6 @@ public class ClassicTests
static ClassicTests()
{
VerifierSettings.DisableNewLineEscaping();
#region EnableClassic
VerifyEntityFrameworkClassic.Enable();

Просмотреть файл

@ -7,7 +7,7 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Verify.NUnit" Version="8.0.0-beta.2" />
<PackageReference Include="Verify.NUnit" Version="8.0.0" />
<PackageReference Include="EfClassicLocalDb" Version="9.0.0-beta.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.0-preview-20201020-06" />
<PackageReference Include="ProjectDefaults" Version="1.0.47" PrivateAssets="All" />

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
@ -7,7 +8,11 @@ using VerifyTests;
class QueryableConverter :
WriteOnlyJsonConverter
{
public override void WriteJson(JsonWriter writer, object? data, JsonSerializer serializer)
public override void WriteJson(
JsonWriter writer,
object? data,
JsonSerializer serializer,
IReadOnlyDictionary<string, object> context)
{
if (data == null)
{

Просмотреть файл

@ -15,8 +15,8 @@ class TrackerConverter :
static TrackerConverter()
{
const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
FieldInfo internalContextField = typeof(DbChangeTracker).GetField("_internalContext", flags)!;
FieldInfo ownerField = internalContextField.FieldType.GetField("_owner", flags)!;
var internalContextField = typeof(DbChangeTracker).GetField("_internalContext", flags)!;
var ownerField = internalContextField.FieldType.GetField("_owner", flags)!;
func = tracker =>
{
@ -25,7 +25,11 @@ class TrackerConverter :
};
}
public override void WriteJson(JsonWriter writer, DbChangeTracker? tracker, JsonSerializer serializer)
public override void WriteJson(
JsonWriter writer,
DbChangeTracker? tracker,
JsonSerializer serializer,
IReadOnlyDictionary<string, object> context)
{
if (tracker == null)
{
@ -35,9 +39,9 @@ class TrackerConverter :
writer.WriteStartObject();
var entries = tracker.Entries().ToList();
HandleAdded(entries, writer, serializer);
var context = func(tracker);
HandleModified(entries, writer, serializer, context);
HandleDeleted(entries, writer, serializer, context);
var data = func(tracker);
HandleModified(entries, writer, serializer, data);
HandleDeleted(entries, writer, serializer, data);
writer.WriteEndObject();
}

Просмотреть файл

@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Verify" Version="8.0.0-beta.2" />
<PackageReference Include="Verify" Version="8.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />
<PackageReference Include="ProjectDefaults" Version="1.0.47" PrivateAssets="All" />