Skip to content

Commit

Permalink
fix fortesting to add assembyloadcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Apr 17, 2024
1 parent 4399594 commit 60e8d15
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 23 deletions.
10 changes: 4 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand Down Expand Up @@ -94,8 +95,5 @@
<PackageVersion Include="Verify.Playwright" Version="2.3.0" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
</ItemGroup>
<Import
Project="$(MSBuildThisFileDirectory)/Directory.Packages.support.props"
Condition="Exists('$(MSBuildThisFileDirectory)/Directory.Packages.support.props')"
/>
</Project>
<Import Project="$(MSBuildThisFileDirectory)/Directory.Packages.support.props" Condition="Exists('$(MSBuildThisFileDirectory)/Directory.Packages.support.props')" />
</Project>
19 changes: 17 additions & 2 deletions sample/Sample.DependencyOne/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
using Rocket.Surgery.Conventions;
using FluentValidation;
using Rocket.Surgery.Conventions;
using Sample.DependencyOne;

[assembly: ExportConventions(Namespace = "Dep1", ClassName = "Dep1Exports")]
[assembly: Convention<Class1>]

namespace Sample.DependencyOne;

public class Class1 : IConvention;
public class Class1 : IConvention;

public static class Example1
{
public record Request(string A, double B);

private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
3 changes: 3 additions & 0 deletions sample/Sample.DependencyOne/Sample.DependencyOne.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Conventions.Abstractions\Rocket.Surgery.Conventions.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions sample/Sample.DependencyThree/Class3.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FluentValidation;
using Rocket.Surgery.Conventions;
using Sample.DependencyOne;
using Sample.DependencyThree;
Expand All @@ -10,3 +11,17 @@ public class Class3 : IConvention
{
public Class1? Class1 { get; set; }
}

public static class Example3
{
public record Request(string A, double B);

private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
3 changes: 3 additions & 0 deletions sample/Sample.DependencyThree/Sample.DependencyThree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Conventions.Abstractions\Rocket.Surgery.Conventions.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" />
</ItemGroup>
</Project>
20 changes: 18 additions & 2 deletions sample/Sample.DependencyTwo/Class2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Rocket.Surgery.Conventions;
using FluentValidation;
using Rocket.Surgery.Conventions;

[assembly: ExportConventions(Namespace = null, ClassName = "Dep2Exports")]

Expand All @@ -8,4 +9,19 @@ public static class Nested
{
[ExportConvention]
public class Class2 : IConvention;
}
}


public static class Example2
{
public record Request(string A, double B);

private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
3 changes: 3 additions & 0 deletions sample/Sample.DependencyTwo/Sample.DependencyTwo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Conventions.Abstractions\Rocket.Surgery.Conventions.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Conventions.Abstractions/ConventionContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,4 @@ public ConventionContextBuilder IncludeConvention(Assembly assembly, params Asse
_includeAssemblyConventions.AddRange(assemblies);
return this;
}
}
}
8 changes: 5 additions & 3 deletions src/Conventions.Analyzers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static string GetFullMetadataName(ISymbol? s)
return string.Empty;
}

var sb = new StringBuilder(s.MetadataName);
var sb =s is INamedTypeSymbol { Arity: > 0, IsUnboundGenericType: true } namedTypeSymbol
? new StringBuilder(namedTypeSymbol.Name + ("<" + (string.Concat(Enumerable.Range(0,3).Select(z => ","))) + ">"))
:new StringBuilder(s.MetadataName);
var last = s;

s = s.ContainingSymbol;
Expand All @@ -34,7 +36,7 @@ public static string GetFullMetadataName(ISymbol? s)
sb.Insert(0, '.');
}

sb.Insert(0, s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
sb.Insert(0, s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
//sb.Insert(0, s.MetadataName);
s = s.ContainingSymbol;
}
Expand Down Expand Up @@ -347,4 +349,4 @@ internal static SyntaxTrivia GetXmlSummary(string text)
}

private static readonly SyntaxToken XmlNewLine = XmlTextNewLine(TriviaList(), "\n", "\n", TriviaList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ private static void EnsureConfigured(ConventionContextBuilder builder)
//
// return builder;
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
Expand Down
4 changes: 3 additions & 1 deletion test/Analyzers.Tests/AssemblyProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public async Task Should_Generate_Assembly_Provider_For_GetTypes(GetTypesTestsDa
using Rocket.Surgery.Conventions.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using FluentValidation;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -168,6 +169,7 @@ public async Task Should_Generate_Assembly_Provider_For_GetTypes_From_Another_As
using Rocket.Surgery.Conventions.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using FluentValidation;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -220,4 +222,4 @@ public override async Task InitializeAsync()
)
);
}
}
}
57 changes: 54 additions & 3 deletions test/Analyzers.Tests/GenerationHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Linq.Expressions;
using FluentValidation;
using Rocket.Surgery.Extensions.Testing.SourceGenerators;

namespace Rocket.Surgery.Conventions.Analyzers.Tests;
Expand All @@ -6,7 +8,7 @@ public static class GenerationHelpers
{
public static async Task<GeneratorTestResults[]> CreateDeps(GeneratorTestContextBuilder rootBuilder)
{
var baseBuilder = rootBuilder;
var baseBuilder = rootBuilder.AddReferences(typeof(IValidator).Assembly, typeof(Expression<>).Assembly);
var c1 = await Class1(baseBuilder);
var c2 = await Class2(baseBuilder);
var c3 = await Class3(baseBuilder, c1);
Expand All @@ -29,6 +31,7 @@ public static Task<GeneratorTestResults> Class1(GeneratorTestContextBuilder buil
.AddSources(
@"using Rocket.Surgery.Conventions;
using Sample.DependencyOne;
using FluentValidation;
[assembly: ExportConventions(Namespace = ""Dep1"", ClassName = ""Dep1Exports"")]
[assembly: Convention(typeof(Class1))]
Expand All @@ -38,6 +41,21 @@ namespace Sample.DependencyOne;
public class Class1 : IConvention
{
}
public static class Example1
{
public record Request(string A, double B);
private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
"
)
.Build()
Expand All @@ -50,6 +68,7 @@ public static Task<GeneratorTestResults> Class2(GeneratorTestContextBuilder buil
.WithProjectName("SampleDependencyTwo")
.AddSources(
@"using Rocket.Surgery.Conventions;
using FluentValidation;
[assembly: ExportConventions(Namespace = null, ClassName = ""Dep2Exports"")]
namespace Sample.DependencyTwo;
Expand All @@ -58,7 +77,23 @@ public static class Nested
{
[ExportConvention]
public class Class2 : IConvention;
}"
}
public static class Example2
{
public record Request(string A, double B);
private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
"
)
.Build()
.GenerateAsync();
Expand All @@ -73,6 +108,7 @@ public static Task<GeneratorTestResults> Class3(GeneratorTestContextBuilder buil
@"using Rocket.Surgery.Conventions;
using Sample.DependencyOne;
using Sample.DependencyThree;
using FluentValidation;
[assembly: Convention(typeof(Class3))]
Expand All @@ -82,6 +118,21 @@ public class Class3 : IConvention
{
public Class1? Class1 { get; set; }
}
public static class Example3
{
public record Request(string A, double B);
private class Validator : AbstractValidator<Request>
{
public Validator()
{
RuleFor(x => x.A).NotEmpty();
RuleFor(x => x.B).GreaterThan(0);
}
}
}
"
)
.Build()
Expand Down Expand Up @@ -154,4 +205,4 @@ public class Class3 : IConvention
.Build()
.GenerateAsync();
}
}
}
6 changes: 4 additions & 2 deletions test/Analyzers.Tests/GeneratorTestContextBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Immutable;
using System.Reflection;
using FluentValidation;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -26,7 +27,8 @@ public static GeneratorTestContextBuilder AddCommonReferences(this GeneratorTest
typeof(ConventionContext).Assembly,
typeof(IConventionContext).Assembly,
typeof(IServiceProvider).Assembly,
typeof(IConfiguration).Assembly
typeof(IConfiguration).Assembly,
typeof(IValidator).Assembly
);
}

Expand All @@ -48,4 +50,4 @@ public static GeneratorTestContextBuilder AddCommonGenerators(this GeneratorTest
&& z.GetCustomAttributes<GeneratorAttribute>().Any()
)
.ToImmutableArray();
}
}
8 changes: 6 additions & 2 deletions test/Analyzers.Tests/GetTypesTestsData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using FluentValidation;
using Microsoft.Extensions.Configuration;
using Rocket.Surgery.Conventions.Configuration;
using Rocket.Surgery.Conventions.DependencyInjection;
Expand All @@ -12,7 +13,10 @@ public class GetTypesTestsData
public static IEnumerable<object[]> GetTypesData()
{
// ReSharper disable RedundantNameQualifier

yield return TestMethod(z => z
.FromAssemblyDependenciesOf<IValidator>()
.GetTypes(x => x.NotInfoOf(TypeInfoFilter.Abstract).AssignableTo(typeof(AbstractValidator<>))));
yield break;

yield return TestMethod(z => z.FromAssemblyOf<IConvention>().GetTypes(x => x.StartsWith("IService")));
yield return TestMethod(z => z.FromAssemblyOf<IConvention>().GetTypes(x => x.StartsWith("S").EndsWith("Convention")));
Expand Down Expand Up @@ -221,4 +225,4 @@ public override string ToString()
return Name;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
Expand Down
Loading

0 comments on commit 60e8d15

Please sign in to comment.