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
13 changes: 6 additions & 7 deletions src/StructId.FunctionalTests/StructId.FunctionalTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="Ulid" Version="1.3.4" />
<PackageReference Include="Ulid" Version="1.4.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
58 changes: 14 additions & 44 deletions src/StructId.Tests/DapperGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;

Expand All @@ -13,13 +11,6 @@ public async Task GenerateHandler()
{
var test = new StructIdGeneratorTest<DapperGenerator>("UserId", "int")
{
SolutionTransforms =
{
(solution, projectId) => solution
.GetProject(projectId)?
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dapper.DbString).Assembly.ManifestModule.FullyQualifiedName))
.Solution ?? solution
},
TestState =
{
Sources =
Expand All @@ -37,7 +28,8 @@ public async Task GenerateHandler()
Encoding.UTF8)
},
},
}.WithAnalyzerDefaults();
}.WithAnalyzerDefaults()
.WithReferencePackages(new PackageIdentity("Dapper", "2.1.35"));

await test.RunAsync();
}
Expand All @@ -47,13 +39,6 @@ public async Task GenerateStringHandler()
{
var test = new StructIdGeneratorTest<DapperGenerator>("UserId", "string")
{
SolutionTransforms =
{
(solution, projectId) => solution
.GetProject(projectId)?
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dapper.DbString).Assembly.ManifestModule.FullyQualifiedName))
.Solution ?? solution
},
TestState =
{
Sources =
Expand All @@ -71,7 +56,8 @@ public async Task GenerateStringHandler()
Encoding.UTF8)
},
},
}.WithAnalyzerDefaults();
}.WithAnalyzerDefaults()
.WithReferencePackages(new PackageIdentity("Dapper", "2.1.35"));

await test.RunAsync();
}
Expand All @@ -83,14 +69,6 @@ public async Task GenerateCustomHandler()

var test = new StructIdGeneratorTest<DapperGenerator>("UserId", "System.Ulid")
{
SolutionTransforms =
{
(solution, projectId) => solution
.GetProject(projectId)?
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dapper.DbString).Assembly.Location))
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Ulid).Assembly.Location))
.Solution ?? solution
},
TestState =
{
Sources =
Expand Down Expand Up @@ -127,7 +105,10 @@ public override void SetValue(IDbDataParameter parameter, Ulid value)
(typeof(DapperGenerator), "DapperExtensions.cs", code, Encoding.UTF8)
},
},
}.WithAnalyzerDefaults();
}.WithAnalyzerDefaults()
.WithReferencePackages(
new PackageIdentity("Dapper", "2.1.72"),
new PackageIdentity("Ulid", "1.4.1"));

await test.RunAsync();
}
Expand All @@ -151,14 +132,6 @@ public override void SetValue(IDbDataParameter parameter, System.Ulid value)

var test = new StructIdGeneratorTest<DapperGenerator>("UserId", "System.Ulid")
{
SolutionTransforms =
{
(solution, projectId) => solution
.GetProject(projectId)?
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dapper.DbString).Assembly.Location))
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Ulid).Assembly.Location))
.Solution ?? solution
},
TestState =
{
Sources =
Expand All @@ -176,7 +149,10 @@ public override void SetValue(IDbDataParameter parameter, System.Ulid value)
(typeof(DapperGenerator), "DapperExtensions.cs", code, Encoding.UTF8)
},
},
}.WithAnalyzerDefaults();
}.WithAnalyzerDefaults()
.WithReferencePackages(
new PackageIdentity("Dapper", "2.1.72"),
new PackageIdentity("Ulid", "1.4.1"));

await test.RunAsync();
}
Expand All @@ -187,13 +163,6 @@ public async Task SkipsUnsupported()
var test = new CSharpSourceGeneratorTest<DapperGenerator, DefaultVerifier>
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
SolutionTransforms =
{
(solution, projectId) => solution
.GetProject(projectId)?
.AddMetadataReference(MetadataReference.CreateFromFile(typeof(Dapper.DbString).Assembly.ManifestModule.FullyQualifiedName))
.Solution ?? solution
},
TestState =
{
Sources =
Expand All @@ -208,7 +177,8 @@ public readonly partial record struct UserId(uint Value) : IStructId<uint>, INew
""",
},
},
}.WithAnalyzerDefaults();
}.WithAnalyzerDefaults()
.WithReferencePackages(new PackageIdentity("Dapper", "2.1.35"));

await test.RunAsync();
}
Expand Down
19 changes: 9 additions & 10 deletions src/StructId.Tests/StructId.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="1.1.3" />
<PackageReference Include="ThisAssembly.Resources" Version="2.1.2" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="Ulid" Version="1.3.4" />
<PackageReference Include="Ulid" Version="1.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -50,4 +49,4 @@
</Target>


</Project>
</Project>
13 changes: 13 additions & 0 deletions src/StructId.Tests/StructIdExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -49,6 +50,18 @@ public static TTest WithAnalyzerDefaults<TTest>(this TTest test) where TTest : A
return test;
}

public static TTest WithReferencePackages<TTest>(this TTest test, params PackageIdentity[] packages)
where TTest : AnalyzerTest<DefaultVerifier>
{
if (packages.Length == 0)
return test;

test.ReferenceAssemblies = (test.ReferenceAssemblies ?? ReferenceAssemblies.Default)
.AddPackages(packages.ToImmutableArray());

return test;
}

static void AddSourceIfNotExists(SourceFileList sources, string filename, string content)
{
if (!sources.Any(s => s.filename == filename))
Expand Down
5 changes: 3 additions & 2 deletions src/StructId/StructId.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>

<ItemGroup Condition="!$(CI)">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.25" Condition="'$(TargetFramework)' == 'net8.0'" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" Condition="'$(TargetFramework)' == 'net10.0'" />
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Ulid" Version="1.3.4" />
Expand Down
Loading