From c7854b7e0eac68d91d2762c08a79255b89181107 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:40:43 +1000 Subject: [PATCH 01/12] add global json required to build on machines that also have net6 sdk installed --- global.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 00000000..a601da31 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.300" + } +} From 1bab25e84753c4d6ac3feb71d926db63974785d2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:41:21 +1000 Subject: [PATCH 02/12] fix RS1032 Severity Code Description Project File Line Suppression State Error RS1032 The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period EntityFrameworkCore.Projections.Generator C:\Code\EntityFrameworkCore.Projections\src\EntityFrameworkCore.Projections.Generator\Diagnostics.cs 15 Active --- .../Diagnostics.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/EntityFrameworkCore.Projections.Generator/Diagnostics.cs b/src/EntityFrameworkCore.Projections.Generator/Diagnostics.cs index 36f833e0..6d96f843 100644 --- a/src/EntityFrameworkCore.Projections.Generator/Diagnostics.cs +++ b/src/EntityFrameworkCore.Projections.Generator/Diagnostics.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; namespace EntityFrameworkCore.Projections.Generator { @@ -12,10 +7,9 @@ public static class Diagnostics public static readonly DiagnosticDescriptor RequiresExpressionBodyDefinition = new( id: "EFP0001", title: "Method or property should expose an expression body definition", - messageFormat: "Method or property '{0}' should expose an expression body definition.", + messageFormat: "Method or property '{0}' should expose an expression body definition", category: "Design", DiagnosticSeverity.Error, isEnabledByDefault: true); - } } From cfbbfc3bfb760a4fd92bd3c0357d9f0cbff585f2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:41:53 +1000 Subject: [PATCH 03/12] update refs --- .../EntityFrameworkCore.Projections.Generator.csproj | 4 ++-- ...ityFrameworkCore.Projections.FunctionalTests.csproj | 4 ++-- ...ityFrameworkCore.Projections.Generator.Tests.csproj | 10 +++++----- .../EntityFrameworkCore.Projections.Tests.csproj | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/EntityFrameworkCore.Projections.Generator/EntityFrameworkCore.Projections.Generator.csproj b/src/EntityFrameworkCore.Projections.Generator/EntityFrameworkCore.Projections.Generator.csproj index 4919e132..0b8e0b3f 100644 --- a/src/EntityFrameworkCore.Projections.Generator/EntityFrameworkCore.Projections.Generator.csproj +++ b/src/EntityFrameworkCore.Projections.Generator/EntityFrameworkCore.Projections.Generator.csproj @@ -11,7 +11,7 @@ - - + + diff --git a/tests/EntityFrameworkCore.Projections.FunctionalTests/EntityFrameworkCore.Projections.FunctionalTests.csproj b/tests/EntityFrameworkCore.Projections.FunctionalTests/EntityFrameworkCore.Projections.FunctionalTests.csproj index 64481c32..7be02739 100644 --- a/tests/EntityFrameworkCore.Projections.FunctionalTests/EntityFrameworkCore.Projections.FunctionalTests.csproj +++ b/tests/EntityFrameworkCore.Projections.FunctionalTests/EntityFrameworkCore.Projections.FunctionalTests.csproj @@ -9,9 +9,9 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj index 5f3cbbfa..40365a6c 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -7,11 +7,11 @@ - - + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projections.Tests/EntityFrameworkCore.Projections.Tests.csproj b/tests/EntityFrameworkCore.Projections.Tests/EntityFrameworkCore.Projections.Tests.csproj index 685b4c4d..92906ce5 100644 --- a/tests/EntityFrameworkCore.Projections.Tests/EntityFrameworkCore.Projections.Tests.csproj +++ b/tests/EntityFrameworkCore.Projections.Tests/EntityFrameworkCore.Projections.Tests.csproj @@ -7,7 +7,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From a78b6258c5c32a3b68a3dd93f4395a9d1b3c6089 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:42:31 +1000 Subject: [PATCH 04/12] spelling --- .../ProjectionExpressionGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs index 3ead4680..f3f2fb26 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -21,7 +21,7 @@ public ProjectionExpressionGeneratorTests(ITestOutputHelper testOutputHelper) } [Fact] - public void EmtpyCode_Noop() + public void EmptyCode_Noop() { var compilation = CreateCompilation(@" class C { } From f284fe76bc2b71047c4ef11716a9895022c7c0eb Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 11:57:13 +1000 Subject: [PATCH 05/12] use Verify.SourceGenerators --- ...orkCore.Projections.Generator.Tests.csproj | 8 +- .../ModuleInitializer.cs | 11 ++ ...lessProjectableComputedMethod.verified.txt | 1 + ...odiedMember_RaisesDiagnostics.verified.txt | 13 ++ ...odiedMethod_RaisesDiagnostics.verified.txt | 13 ++ ...exProjectableComputedProperty.verified.txt | 1 + ...edMethodWithMultipleArguments.verified.txt | 1 + ...putedMethodWithSingleArgument.verified.txt | 1 + ...ectableComputedPropertyMethod.verified.txt | 1 + ...ableComputedPropertyUsingThis.verified.txt | 1 + ...ts.ProjectableExtensionMethod.verified.txt | 1 + ...s.ProjectableExtensionMethod2.verified.txt | 1 + ...ropertyToNavigationalProperty.verified.txt | 1 + ...ComputedInNestedClassProperty.verified.txt | 1 + ...leProjectableComputedProperty.verified.txt | 1 + ...Tests.SimpleProjectableMethod.verified.txt | 1 + ...sts.SimpleProjectableProperty.verified.txt | 1 + .../ProjectionExpressionGeneratorTests.cs | 158 +++--------------- 18 files changed, 77 insertions(+), 139 deletions(-) create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj index 40365a6c..90841b3f 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/EntityFrameworkCore.Projections.Generator.Tests.csproj @@ -11,6 +11,7 @@ + @@ -23,12 +24,7 @@ - - - - - - + diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs b/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs new file mode 100644 index 00000000..7c9188b6 --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs @@ -0,0 +1,11 @@ +using System.Runtime.CompilerServices; +using VerifyTests; + +public static class ModuleInitializer +{ + [ModuleInitializer] + public static void Init() + { + VerifySourceGenerators.Enable(); + } +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt index 9d7279cc..907f548d 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt new file mode 100644 index 00000000..c3c8dd0c --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt @@ -0,0 +1,13 @@ +{ + Diagnostics: [ + { + Id: EFP0001, + Title: Method or property should expose an expression body definition, + Severity: Error, + WarningLevel: 0, + Location: SourceFile([97..179)), + MessageFormat: Method or property '{0}' should expose an expression body definition, + Category: Design + } + ] +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt new file mode 100644 index 00000000..f99fec01 --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt @@ -0,0 +1,13 @@ +{ + Diagnostics: [ + { + Id: EFP0001, + Title: Method or property should expose an expression body definition, + Severity: Error, + WarningLevel: 0, + Location: SourceFile([97..181)), + MessageFormat: Method or property '{0}' should expose an expression body definition, + Category: Design + } + ] +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt index a574c186..6bf2618a 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt index 38072636..850acd25 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt index 6efe3ba3..791f327d 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt index 0745df13..a0a0c4e0 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt index 8f58a826..9e673d7b 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt index 8f7bc6cb..ceddff78 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projections; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt index be7893dd..5ed50e4c 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projections; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt index 6b6271ee..c312d774 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projections; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt index 7dcbc1af..93ae5866 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_D_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt index 6a3be3d3..0289d6c4 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt index 7fbd5745..facf6d5d 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt index 7fbd5745..facf6d5d 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projections; using Foo; diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs index f3f2fb26..3610ea03 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -1,7 +1,5 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading.Tasks; using VerifyXunit; @@ -21,16 +19,14 @@ public ProjectionExpressionGeneratorTests(ITestOutputHelper testOutputHelper) } [Fact] - public void EmptyCode_Noop() + public Task EmptyCode_Noop() { var compilation = CreateCompilation(@" class C { } "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Empty(result.GeneratedTrees); + return Verifier.Verify(result); } [Fact] @@ -48,11 +44,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -69,11 +61,7 @@ class C { } "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -93,11 +81,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -119,11 +103,7 @@ class D { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -143,11 +123,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -167,11 +143,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } @@ -192,11 +164,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -214,11 +182,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -236,11 +200,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -258,11 +218,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -274,7 +230,7 @@ public Task ProjectablePropertyToNavigationalProperty() using EntityFrameworkCore.Projections; namespace Foo { class D { } - + class C { public System.Collections.Generic.List Dees { get; set; } @@ -285,11 +241,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -301,7 +253,7 @@ public Task ProjectableExtensionMethod() using EntityFrameworkCore.Projections; namespace Foo { class D { } - + static class C { [Projectable] public static int Foo(this D d) => 1; @@ -310,11 +262,7 @@ static class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -333,15 +281,11 @@ static class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] - public void BlockBodiedMember_RaisesDiagnostics() + public Task BlockBodiedMember_RaisesDiagnostics() { var compilation = CreateCompilation(@" using System; @@ -349,7 +293,7 @@ public void BlockBodiedMember_RaisesDiagnostics() namespace Foo { class C { [Projectable] - public int Foo + public int Foo { get => 1; } @@ -358,12 +302,11 @@ public int Foo "); var result = RunGenerator(compilation); - - Assert.Single(result.Diagnostics); + return Verifier.Verify(result); } [Fact] - public void BlockBodiedMethod_RaisesDiagnostics() + public Task BlockBodiedMethod_RaisesDiagnostics() { var compilation = CreateCompilation(@" using System; @@ -371,7 +314,7 @@ public void BlockBodiedMethod_RaisesDiagnostics() namespace Foo { class C { [Projectable] - public int Foo() + public int Foo() { return 1; } @@ -380,48 +323,20 @@ public int Foo() "); var result = RunGenerator(compilation); - - Assert.Single(result.Diagnostics); + return Verifier.Verify(result); } #region Helpers - Compilation CreateCompilation(string source, bool expectedToCompile = true) + Compilation CreateCompilation(string source) { var references = Basic.Reference.Assemblies.NetStandard20.All.ToList(); references.Add(MetadataReference.CreateFromFile(typeof(ProjectableAttribute).Assembly.Location)); - var assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location); - - var compilation = CSharpCompilation.Create("compilation", + return CSharpCompilation.Create("compilation", new[] { CSharpSyntaxTree.ParseText(source) }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - -#if DEBUG - - if (expectedToCompile) - { - var compilationDiagnostics = compilation.GetDiagnostics(); - - if (!compilationDiagnostics.IsEmpty) - { - _testOutputHelper.WriteLine($"Original compilation diagnostics produced:"); - - foreach (var diagnostic in compilationDiagnostics) - { - _testOutputHelper.WriteLine($" > " + diagnostic.ToString()); - } - - if (compilationDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error)) - { - Debug.Fail("Compilation diagnostics produced"); - } - } - } -#endif - - return compilation; } private GeneratorDriverRunResult RunGenerator(Compilation compilation) @@ -432,29 +347,6 @@ private GeneratorDriverRunResult RunGenerator(Compilation compilation) var driver = CSharpGeneratorDriver .Create(subject) .RunGenerators(compilation); - - var result = driver.GetRunResult(); - - if (result.Diagnostics.IsEmpty) - { - _testOutputHelper.WriteLine("Run did not produce diagnostics"); - } - else - { - _testOutputHelper.WriteLine($"Diagnostics produced:"); - - foreach (var diagnostic in result.Diagnostics) - { - _testOutputHelper.WriteLine($" > " + diagnostic.ToString()); - } - } - - foreach (var newSyntaxTree in result.GeneratedTrees) - { - _testOutputHelper.WriteLine($"Produced syntax tree with path produced: {newSyntaxTree.FilePath}"); - _testOutputHelper.WriteLine(newSyntaxTree.GetText().ToString()); - } - return driver.GetRunResult(); } From e1615ec08749685e9c9d2ac3844d2444bd66fcad Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:40:43 +1000 Subject: [PATCH 06/12] add global json required to build on machines that also have net6 sdk installed --- global.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 00000000..a601da31 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.300" + } +} From d9793221c2922cfa5379dfc40ec62a656bff6ba2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:41:21 +1000 Subject: [PATCH 07/12] fix RS1032 Severity Code Description Project File Line Suppression State Error RS1032 The diagnostic message should not contain any line return character nor any leading or trailing whitespaces and should either be a single sentence without a trailing period or a multi-sentences with a trailing period EntityFrameworkCore.Projections.Generator C:\Code\EntityFrameworkCore.Projections\src\EntityFrameworkCore.Projections.Generator\Diagnostics.cs 15 Active --- .../Diagnostics.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/EntityFrameworkCore.Projectables.Generator/Diagnostics.cs b/src/EntityFrameworkCore.Projectables.Generator/Diagnostics.cs index 5d339c4c..c99af30a 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/Diagnostics.cs +++ b/src/EntityFrameworkCore.Projectables.Generator/Diagnostics.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; namespace EntityFrameworkCore.Projectables.Generator { @@ -12,10 +7,9 @@ public static class Diagnostics public static readonly DiagnosticDescriptor RequiresExpressionBodyDefinition = new( id: "EFP0001", title: "Method or property should expose an expression body definition", - messageFormat: "Method or property '{0}' should expose an expression body definition.", + messageFormat: "Method or property '{0}' should expose an expression body definition", category: "Design", DiagnosticSeverity.Error, isEnabledByDefault: true); - } } From fc80158529c2d4065a90f7ac625eb104a8ea699b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:41:53 +1000 Subject: [PATCH 08/12] update refs --- .../EntityFrameworkCore.Projectables.Generator.csproj | 4 ++-- ...tyFrameworkCore.Projectables.FunctionalTests.csproj | 4 ++-- ...tyFrameworkCore.Projectables.Generator.Tests.csproj | 10 +++++----- .../EntityFrameworkCore.Projectables.Tests.csproj | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj b/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj index ad47fb2a..b5b08e2b 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj +++ b/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj @@ -11,7 +11,7 @@ - - + + diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj b/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj index ef2e7215..9e9542f9 100644 --- a/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj @@ -9,9 +9,9 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj index a4109332..3e49afa7 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -7,11 +7,11 @@ - - + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projectables.Tests/EntityFrameworkCore.Projectables.Tests.csproj b/tests/EntityFrameworkCore.Projectables.Tests/EntityFrameworkCore.Projectables.Tests.csproj index 8d72d5a0..4fff799a 100644 --- a/tests/EntityFrameworkCore.Projectables.Tests/EntityFrameworkCore.Projectables.Tests.csproj +++ b/tests/EntityFrameworkCore.Projectables.Tests/EntityFrameworkCore.Projectables.Tests.csproj @@ -7,7 +7,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From 82a8d27952b4493abe2b72e57677d64eb2fead94 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 10:42:31 +1000 Subject: [PATCH 09/12] spelling --- .../ProjectionExpressionGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs index 54359c1b..3b2e944b 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -21,7 +21,7 @@ public ProjectionExpressionGeneratorTests(ITestOutputHelper testOutputHelper) } [Fact] - public void EmtpyCode_Noop() + public void EmptyCode_Noop() { var compilation = CreateCompilation(@" class C { } From a0e392b712c390c21f5f3eb82f7a51c66d2a235e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 31 May 2021 11:57:13 +1000 Subject: [PATCH 10/12] use Verify.SourceGenerators --- ...rkCore.Projectables.Generator.Tests.csproj | 8 +- ...lessProjectableComputedMethod.verified.txt | 1 + ...exProjectableComputedProperty.verified.txt | 1 + ...edMethodWithMultipleArguments.verified.txt | 1 + ...putedMethodWithSingleArgument.verified.txt | 1 + ...ectableComputedPropertyMethod.verified.txt | 1 + ...ableComputedPropertyUsingThis.verified.txt | 1 + ...ts.ProjectableExtensionMethod.verified.txt | 1 + ...s.ProjectableExtensionMethod2.verified.txt | 1 + ...ropertyToNavigationalProperty.verified.txt | 1 + ...ComputedInNestedClassProperty.verified.txt | 1 + ...leProjectableComputedProperty.verified.txt | 1 + ...Tests.SimpleProjectableMethod.verified.txt | 1 + ...sts.SimpleProjectableProperty.verified.txt | 1 + .../ProjectionExpressionGeneratorTests.cs | 158 +++--------------- .../ModuleInitializer.cs | 11 ++ ...odiedMember_RaisesDiagnostics.verified.txt | 13 ++ ...odiedMethod_RaisesDiagnostics.verified.txt | 13 ++ 18 files changed, 77 insertions(+), 139 deletions(-) create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt create mode 100644 tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj index 3e49afa7..27980627 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj @@ -11,6 +11,7 @@ + @@ -23,12 +24,7 @@ - - - - - - + diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt index d0258bec..b8a711e9 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ArgumentlessProjectableComputedMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt index abd064c3..444abd69 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.MoreComplexProjectableComputedProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt index 9db50124..5e3f082c 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithMultipleArguments.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt index daa7653c..91c40dd3 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedMethodWithSingleArgument.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt index 969443de..21bc93fa 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt index d505707e..3ce9c1c9 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableComputedPropertyUsingThis.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt index 3db1fb55..e766eee2 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projectables; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt index 860c71e8..ac20ae61 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectableExtensionMethod2.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projectables; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt index a2b7ca0d..de065da6 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.ProjectablePropertyToNavigationalProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using System.Linq; using EntityFrameworkCore.Projectables; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt index c331b38c..9a70c529 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedInNestedClassProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_D_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt index 71567abf..ee91b158 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableComputedProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt index 0914f895..4bbfa118 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableMethod.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt index 0914f895..4bbfa118 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.SimpleProjectableProperty.verified.txt @@ -1,3 +1,4 @@ +//HintName: Foo_C_Foo_Generated.cs using System; using EntityFrameworkCore.Projectables; using Foo; diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs index 3b2e944b..e0cd4999 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -1,7 +1,5 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading.Tasks; using VerifyXunit; @@ -21,16 +19,14 @@ public ProjectionExpressionGeneratorTests(ITestOutputHelper testOutputHelper) } [Fact] - public void EmptyCode_Noop() + public Task EmptyCode_Noop() { var compilation = CreateCompilation(@" class C { } "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Empty(result.GeneratedTrees); + return Verifier.Verify(result); } [Fact] @@ -48,11 +44,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -69,11 +61,7 @@ class C { } "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -93,11 +81,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -119,11 +103,7 @@ class D { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -143,11 +123,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -167,11 +143,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } @@ -192,11 +164,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -214,11 +182,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -236,11 +200,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -258,11 +218,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -274,7 +230,7 @@ public Task ProjectablePropertyToNavigationalProperty() using EntityFrameworkCore.Projectables; namespace Foo { class D { } - + class C { public System.Collections.Generic.List Dees { get; set; } @@ -285,11 +241,7 @@ class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -301,7 +253,7 @@ public Task ProjectableExtensionMethod() using EntityFrameworkCore.Projectables; namespace Foo { class D { } - + static class C { [Projectable] public static int Foo(this D d) => 1; @@ -310,11 +262,7 @@ static class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] @@ -333,15 +281,11 @@ static class C { "); var result = RunGenerator(compilation); - - Assert.Empty(result.Diagnostics); - Assert.Single(result.GeneratedTrees); - - return Verifier.Verify(result.GeneratedTrees[0].ToString()); + return Verifier.Verify(result); } [Fact] - public void BlockBodiedMember_RaisesDiagnostics() + public Task BlockBodiedMember_RaisesDiagnostics() { var compilation = CreateCompilation(@" using System; @@ -349,7 +293,7 @@ public void BlockBodiedMember_RaisesDiagnostics() namespace Foo { class C { [Projectable] - public int Foo + public int Foo { get => 1; } @@ -358,12 +302,11 @@ public int Foo "); var result = RunGenerator(compilation); - - Assert.Single(result.Diagnostics); + return Verifier.Verify(result); } [Fact] - public void BlockBodiedMethod_RaisesDiagnostics() + public Task BlockBodiedMethod_RaisesDiagnostics() { var compilation = CreateCompilation(@" using System; @@ -371,7 +314,7 @@ public void BlockBodiedMethod_RaisesDiagnostics() namespace Foo { class C { [Projectable] - public int Foo() + public int Foo() { return 1; } @@ -380,48 +323,20 @@ public int Foo() "); var result = RunGenerator(compilation); - - Assert.Single(result.Diagnostics); + return Verifier.Verify(result); } #region Helpers - Compilation CreateCompilation(string source, bool expectedToCompile = true) + Compilation CreateCompilation(string source) { var references = Basic.Reference.Assemblies.NetStandard20.All.ToList(); references.Add(MetadataReference.CreateFromFile(typeof(ProjectableAttribute).Assembly.Location)); - var assemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location); - - var compilation = CSharpCompilation.Create("compilation", + return CSharpCompilation.Create("compilation", new[] { CSharpSyntaxTree.ParseText(source) }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - -#if DEBUG - - if (expectedToCompile) - { - var compilationDiagnostics = compilation.GetDiagnostics(); - - if (!compilationDiagnostics.IsEmpty) - { - _testOutputHelper.WriteLine($"Original compilation diagnostics produced:"); - - foreach (var diagnostic in compilationDiagnostics) - { - _testOutputHelper.WriteLine($" > " + diagnostic.ToString()); - } - - if (compilationDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error)) - { - Debug.Fail("Compilation diagnostics produced"); - } - } - } -#endif - - return compilation; } private GeneratorDriverRunResult RunGenerator(Compilation compilation) @@ -432,29 +347,6 @@ private GeneratorDriverRunResult RunGenerator(Compilation compilation) var driver = CSharpGeneratorDriver .Create(subject) .RunGenerators(compilation); - - var result = driver.GetRunResult(); - - if (result.Diagnostics.IsEmpty) - { - _testOutputHelper.WriteLine("Run did not produce diagnostics"); - } - else - { - _testOutputHelper.WriteLine($"Diagnostics produced:"); - - foreach (var diagnostic in result.Diagnostics) - { - _testOutputHelper.WriteLine($" > " + diagnostic.ToString()); - } - } - - foreach (var newSyntaxTree in result.GeneratedTrees) - { - _testOutputHelper.WriteLine($"Produced syntax tree with path produced: {newSyntaxTree.FilePath}"); - _testOutputHelper.WriteLine(newSyntaxTree.GetText().ToString()); - } - return driver.GetRunResult(); } diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs b/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs new file mode 100644 index 00000000..7c9188b6 --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ModuleInitializer.cs @@ -0,0 +1,11 @@ +using System.Runtime.CompilerServices; +using VerifyTests; + +public static class ModuleInitializer +{ + [ModuleInitializer] + public static void Init() + { + VerifySourceGenerators.Enable(); + } +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt new file mode 100644 index 00000000..c3c8dd0c --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt @@ -0,0 +1,13 @@ +{ + Diagnostics: [ + { + Id: EFP0001, + Title: Method or property should expose an expression body definition, + Severity: Error, + WarningLevel: 0, + Location: SourceFile([97..179)), + MessageFormat: Method or property '{0}' should expose an expression body definition, + Category: Design + } + ] +} \ No newline at end of file diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt new file mode 100644 index 00000000..f99fec01 --- /dev/null +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt @@ -0,0 +1,13 @@ +{ + Diagnostics: [ + { + Id: EFP0001, + Title: Method or property should expose an expression body definition, + Severity: Error, + WarningLevel: 0, + Location: SourceFile([97..181)), + MessageFormat: Method or property '{0}' should expose an expression body definition, + Category: Design + } + ] +} \ No newline at end of file From 7a83afee9aad480e9b8c577b91c4784d7611bb1b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 1 Jun 2021 22:09:25 +1000 Subject: [PATCH 11/12] refs --- .../EntityFrameworkCore.Projectables.FunctionalTests.csproj | 2 +- .../EntityFrameworkCore.Projectables.Generator.Tests.csproj | 4 ++-- ...atorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt | 2 +- ...atorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj b/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj index 9e9542f9..98d4108e 100644 --- a/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj +++ b/tests/EntityFrameworkCore.Projectables.FunctionalTests/EntityFrameworkCore.Projectables.FunctionalTests.csproj @@ -11,7 +11,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj index 27980627..dab371ef 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/EntityFrameworkCore.Projectables.Generator.Tests.csproj @@ -11,8 +11,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt index c3c8dd0c..df080932 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMember_RaisesDiagnostics.verified.txt @@ -5,7 +5,7 @@ Title: Method or property should expose an expression body definition, Severity: Error, WarningLevel: 0, - Location: SourceFile([97..179)), + Location: : (5,8)-(9,9), MessageFormat: Method or property '{0}' should expose an expression body definition, Category: Design } diff --git a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt index f99fec01..df080932 100644 --- a/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt +++ b/tests/EntityFrameworkCore.Projections.Generator.Tests/ProjectionExpressionGeneratorTests.BlockBodiedMethod_RaisesDiagnostics.verified.txt @@ -5,7 +5,7 @@ Title: Method or property should expose an expression body definition, Severity: Error, WarningLevel: 0, - Location: SourceFile([97..181)), + Location: : (5,8)-(9,9), MessageFormat: Method or property '{0}' should expose an expression body definition, Category: Design } From 3d426e8bf02207bab0d2a38fa15b968333d82677 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 1 Jun 2021 22:11:37 +1000 Subject: [PATCH 12/12] Update ProjectionExpressionGeneratorTests.cs --- .../ProjectionExpressionGeneratorTests.cs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs index e0cd4999..3b575d36 100644 --- a/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs +++ b/tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs @@ -1,4 +1,5 @@ -using Microsoft.CodeAnalysis; +using System.Diagnostics; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using System.Linq; using System.Threading.Tasks; @@ -328,15 +329,39 @@ public int Foo() #region Helpers - Compilation CreateCompilation(string source) + Compilation CreateCompilation(string source, bool expectedToCompile = true) { var references = Basic.Reference.Assemblies.NetStandard20.All.ToList(); references.Add(MetadataReference.CreateFromFile(typeof(ProjectableAttribute).Assembly.Location)); - return CSharpCompilation.Create("compilation", + var compilation = CSharpCompilation.Create("compilation", new[] { CSharpSyntaxTree.ParseText(source) }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + +#if DEBUG + if (expectedToCompile) + { + var compilationDiagnostics = compilation.GetDiagnostics(); + + if (!compilationDiagnostics.IsEmpty) + { + _testOutputHelper.WriteLine($"Original compilation diagnostics produced:"); + + foreach (var diagnostic in compilationDiagnostics) + { + _testOutputHelper.WriteLine($" > " + diagnostic); + } + + if (compilationDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error)) + { + Debug.Fail("Compilation diagnostics produced"); + } + } + } +#endif + + return compilation; } private GeneratorDriverRunResult RunGenerator(Compilation compilation)