fix(shared): enable dapper aot for session handlers
PR Checks / test-and-build (pull_request) Successful in 6m30s
PR Checks / test-and-build (pull_request) Successful in 6m30s
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
[module: Dapper.DapperAot]
|
||||||
@@ -5,10 +5,12 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
|
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Dapper.AOT</InterceptorsPreviewNamespaces>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapper" Version="2.1.72" />
|
<PackageReference Include="Dapper" Version="2.1.72" />
|
||||||
|
<PackageReference Include="Dapper.AOT" Version="1.0.48" PrivateAssets="all" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
|
||||||
<PackageReference Include="Npgsql" Version="10.0.2" />
|
<PackageReference Include="Npgsql" Version="10.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -8,6 +8,12 @@
|
|||||||
"resolved": "2.1.72",
|
"resolved": "2.1.72",
|
||||||
"contentHash": "ns4mGqQd9a/MhP8m6w556vVlZIa0/MfUu03zrxjZC/jlr1uVCsUac8bkdB+Fs98Llbd56rRSo1eZH5VVmeGZyw=="
|
"contentHash": "ns4mGqQd9a/MhP8m6w556vVlZIa0/MfUu03zrxjZC/jlr1uVCsUac8bkdB+Fs98Llbd56rRSo1eZH5VVmeGZyw=="
|
||||||
},
|
},
|
||||||
|
"Dapper.AOT": {
|
||||||
|
"type": "Direct",
|
||||||
|
"requested": "[1.0.48, )",
|
||||||
|
"resolved": "1.0.48",
|
||||||
|
"contentHash": "rsLM3yKr4g+YKKox9lhc8D+kz67P7Q9+xdyn1LmCsoYr1kYpJSm+Nt6slo5UrfUrcTiGJ57zUlyO8XUdV7G7iA=="
|
||||||
|
},
|
||||||
"Microsoft.Extensions.Logging.Abstractions": {
|
"Microsoft.Extensions.Logging.Abstractions": {
|
||||||
"type": "Direct",
|
"type": "Direct",
|
||||||
"requested": "[10.0.5, )",
|
"requested": "[10.0.5, )",
|
||||||
|
|||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
||||||
|
|
||||||
|
public sealed class SharedDapperAotConfigurationTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void SharedProject_ShouldEnableDapperAotForSessionInteractionHandlers()
|
||||||
|
{
|
||||||
|
var repoRoot = FindRepositoryRoot();
|
||||||
|
var sharedProjectPath = Path.Combine(repoRoot, "src", "GmRelay.Shared", "GmRelay.Shared.csproj");
|
||||||
|
var joinHandler = File.ReadAllText(Path.Combine(
|
||||||
|
repoRoot,
|
||||||
|
"src",
|
||||||
|
"GmRelay.Shared",
|
||||||
|
"Features",
|
||||||
|
"Sessions",
|
||||||
|
"CreateSession",
|
||||||
|
"JoinSessionHandler.cs"));
|
||||||
|
var leaveHandler = File.ReadAllText(Path.Combine(
|
||||||
|
repoRoot,
|
||||||
|
"src",
|
||||||
|
"GmRelay.Shared",
|
||||||
|
"Features",
|
||||||
|
"Sessions",
|
||||||
|
"CreateSession",
|
||||||
|
"LeaveSessionHandler.cs"));
|
||||||
|
|
||||||
|
Assert.Contains("using Dapper;", joinHandler, StringComparison.Ordinal);
|
||||||
|
Assert.Contains("using Dapper;", leaveHandler, StringComparison.Ordinal);
|
||||||
|
|
||||||
|
var project = XDocument.Load(sharedProjectPath);
|
||||||
|
var packageReferences = project
|
||||||
|
.Descendants("PackageReference")
|
||||||
|
.Select(reference => reference.Attribute("Include")?.Value)
|
||||||
|
.ToArray();
|
||||||
|
var interceptorNamespaces = project
|
||||||
|
.Descendants("InterceptorsPreviewNamespaces")
|
||||||
|
.Select(element => element.Value)
|
||||||
|
.ToArray();
|
||||||
|
var moduleAttributeFiles = Directory
|
||||||
|
.EnumerateFiles(Path.GetDirectoryName(sharedProjectPath)!, "*.cs", SearchOption.AllDirectories)
|
||||||
|
.Select(File.ReadAllText)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
Assert.Contains("Dapper.AOT", packageReferences);
|
||||||
|
Assert.Contains(interceptorNamespaces, value => value.Contains("Dapper.AOT", StringComparison.Ordinal));
|
||||||
|
Assert.Contains(moduleAttributeFiles, source => source.Contains("[module: Dapper.DapperAot]", StringComparison.Ordinal));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string FindRepositoryRoot()
|
||||||
|
{
|
||||||
|
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||||
|
while (directory is not null)
|
||||||
|
{
|
||||||
|
if (File.Exists(Path.Combine(directory.FullName, "Directory.Build.props")))
|
||||||
|
{
|
||||||
|
return directory.FullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
directory = directory.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidOperationException("Could not locate repository root.");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user