implement Initialize convention

This commit is contained in:
Simon 2023-02-07 10:49:18 +11:00
Родитель f0c41429fd
Коммит 414b180555
8 изменённых файлов: 39 добавлений и 17 удалений

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

@ -35,7 +35,7 @@ static IModel GetDbModel()
public static void Init()
{
var model = GetDbModel();
VerifyEntityFramework.Enable(model);
VerifyEntityFramework.Initialize(model);
}
```
<sup><a href='/src/Verify.EntityFramework.Tests/ModuleInitializer.cs#L5-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-enablecore' title='Start of snippet'>anchor</a></sup>
@ -49,14 +49,14 @@ The `GetDbModel` pattern allows an instance of the `IModel` to be stored for use
<!-- snippet: EnableClassic -->
<a id='snippet-enableclassic'></a>
```cs
VerifyEntityFrameworkClassic.Enable();
VerifyEntityFrameworkClassic.Initialize();
```
<sup><a href='/src/Verify.EntityFrameworkClassic.Tests/ClassicTests.cs#L130-L134' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclassic' title='Start of snippet'>anchor</a></sup>
<a id='snippet-enableclassic-1'></a>
```cs
[ModuleInitializer]
public static void Init() =>
VerifyEntityFrameworkClassic.Enable();
VerifyEntityFrameworkClassic.Initialize();
```
<sup><a href='/src/Verify.EntityFrameworkClassic.Tests/ModuleInitializer.cs#L3-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-enableclassic-1' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

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

@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;CS8632;EF1001</NoWarn>
<Version>9.3.1</Version>
<Version>9.4.0</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>

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

@ -16,15 +16,12 @@ public static class ModuleInitializer
public static void Init()
{
var model = GetDbModel();
VerifyEntityFramework.Enable(model);
VerifyEntityFramework.Initialize(model);
}
#endregion
[ModuleInitializer]
public static void InitOther()
{
VerifySqlServer.Enable();
VerifyDiffPlex.Initialize();
}
public static void InitOther() =>
VerifierSettings.InitializePlugins();
}

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

@ -12,7 +12,7 @@
<PackageReference Include="Verify.DiffPlex" Version="2.2.0" />
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.1" PrivateAssets="all" />
<PackageReference Include="Verify.NUnit" Version="19.9.2" />
<PackageReference Include="Verify.SqlServer" Version="5.0.1" />
<PackageReference Include="Verify.SqlServer" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="ProjectDefaults" Version="1.0.84" PrivateAssets="all" />

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

@ -79,11 +79,25 @@ public static class VerifyEntityFramework
}
}
[Obsolete("Use Initialize")]
public static void Enable(DbContext context) =>
Enable(context.Model);
Initialize(context);
public static void Enable(IModel? model = null)
public static void Initialize(DbContext context) =>
Initialize(context.Model);
[Obsolete("Use Initialize")]
public static void Enable(IModel? model = null) =>
Initialize(model);
public static bool Initialized { get; private set; }
public static void Initialize(IModel? model = null)
{
if (Initialized)
{
throw new("Already Initialized");
}
InnerVerifier.ThrowIfVerifyHasBeenRun();
if (model != null)
{

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

@ -129,7 +129,7 @@ public class ClassicTests
{
#region EnableClassic
VerifyEntityFrameworkClassic.Enable();
VerifyEntityFrameworkClassic.Initialize();
#endregion

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

@ -4,11 +4,11 @@
[ModuleInitializer]
public static void Init() =>
VerifyEntityFrameworkClassic.Enable();
VerifyEntityFrameworkClassic.Initialize();
#endregion
[ModuleInitializer]
public static void InitOther() =>
VerifyDiffPlex.Initialize();
VerifierSettings.InitializePlugins();
}

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

@ -2,8 +2,19 @@
public static class VerifyEntityFrameworkClassic
{
public static void Enable()
[Obsolete("Use Initialize")]
public static void Enable() =>
Initialize();
public static bool Initialized { get; private set; }
public static void Initialize()
{
if (Initialized)
{
throw new("Already Initialized");
}
VerifierSettings.RegisterFileConverter(
QueryableToSql,
(target, _) => QueryableConverter.IsQueryable(target));