From 9f3fe49434c57264672ffe85e6e1ad8c7a46524c Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Fri, 14 Jul 2023 20:36:56 -0700 Subject: [PATCH] Add infrastructure for trimming and NativeAOT test apps. Part of #29761 --- All.sln | 14 +- Directory.Build.props | 31 +++- Directory.Build.targets | 1 + azure-pipelines.yml | 4 - eng/Versions.props | 1 + eng/helix.proj | 4 +- eng/testing/linker/SupportFiles/.editorconfig | 12 ++ .../linker/SupportFiles/Directory.Build.props | 19 ++ .../SupportFiles/Directory.Build.targets | 2 + eng/testing/linker/project.csproj.template | 24 +++ eng/testing/linker/trimmingTests.props | 8 + eng/testing/linker/trimmingTests.targets | 169 ++++++++++++++++++ .../CompiledModels/NativeAotContextModel.cs | 2 +- .../NativeAotContextModelBuilder.cs | 2 - .../CompiledModels/UserEntityType.cs | 3 +- .../EFCore.NativeAotTests.csproj | 9 +- test/EFCore.NativeAotTests/EndToEnd.cs | 16 ++ .../{ => Models}/NativeAotContext.cs | 2 +- .../{ => Models}/User.cs | 2 +- test/EFCore.NativeAotTests/Program.cs | 14 -- test/EFCore.NativeAotTests/readme.md | 3 + .../EFCore.TrimmingTests.csproj} | 7 +- .../EndToEnd.cs} | 30 ++-- .../TestUtilities}/TestEnvironment.cs | 2 +- test/EFCore.TrimmingTests/readme.md | 3 + 25 files changed, 319 insertions(+), 65 deletions(-) create mode 100644 eng/testing/linker/SupportFiles/.editorconfig create mode 100644 eng/testing/linker/SupportFiles/Directory.Build.props create mode 100644 eng/testing/linker/SupportFiles/Directory.Build.targets create mode 100644 eng/testing/linker/project.csproj.template create mode 100644 eng/testing/linker/trimmingTests.props create mode 100644 eng/testing/linker/trimmingTests.targets create mode 100644 test/EFCore.NativeAotTests/EndToEnd.cs rename test/EFCore.NativeAotTests/{ => Models}/NativeAotContext.cs (94%) rename test/EFCore.NativeAotTests/{ => Models}/User.cs (79%) delete mode 100644 test/EFCore.NativeAotTests/Program.cs create mode 100644 test/EFCore.NativeAotTests/readme.md rename test/{EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj => EFCore.TrimmingTests/EFCore.TrimmingTests.csproj} (68%) rename test/{EFCore.Trimming.Tests/Program.cs => EFCore.TrimmingTests/EndToEnd.cs} (57%) rename test/{EFCore.Trimming.Tests => EFCore.TrimmingTests/TestUtilities}/TestEnvironment.cs (91%) create mode 100644 test/EFCore.TrimmingTests/readme.md diff --git a/All.sln b/All.sln index b7fad66baf8..a149f3cc8a7 100644 --- a/All.sln +++ b/All.sln @@ -122,7 +122,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.Sqlite.Functi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Trimming.Tests", "test\EFCore.Trimming.Tests\EFCore.Trimming.Tests.csproj", "{933C8662-817C-4F45-B98B-6557E28F7BB1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.TrimmingTests", "test\EFCore.TrimmingTests\EFCore.TrimmingTests.csproj", "{59C1CEDE-AA45-41FE-8098-6279A72C421A}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Templates", "src\EFCore.Templates\EFCore.Templates.csproj", "{1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}" EndProject @@ -134,7 +134,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.HierarchyI EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.SqlServer.Abstractions", "src\EFCore.SqlServer.Abstractions\EFCore.SqlServer.Abstractions.csproj", "{3D935B7D-80BD-49AD-BDC9-E1B0C9D9494F}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EFCore.VisualBasic.FunctionalTests", "test\EFCore.VisualBasic.FunctionalTests\EFCore.VisualBasic.FunctionalTests.vbproj", "{2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}" +Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "EFCore.VisualBasic.FunctionalTests", "test\EFCore.VisualBasic.FunctionalTests\EFCore.VisualBasic.FunctionalTests.vbproj", "{2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -334,10 +334,6 @@ Global {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU - {933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.Build.0 = Release|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Debug|Any CPU.Build.0 = Debug|Any CPU {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -362,6 +358,10 @@ Global {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3}.Release|Any CPU.Build.0 = Release|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59C1CEDE-AA45-41FE-8098-6279A72C421A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -415,13 +415,13 @@ Global {F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749} {CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749} {F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749} - {933C8662-817C-4F45-B98B-6557E28F7BB1} = {258D5057-81B9-40EC-A872-D21E27452749} {1FE385D8-8F8B-4EC9-A1A9-AFCC38B8546C} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {2487950B-403A-482C-8ED3-CCF31E9E677F} = {258D5057-81B9-40EC-A872-D21E27452749} {8F722A02-71A4-4787-ACD8-FB7D5B7AE648} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {01F86E65-6448-424C-AAB5-9C6427EF6FD4} = {258D5057-81B9-40EC-A872-D21E27452749} {3D935B7D-80BD-49AD-BDC9-E1B0C9D9494F} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC} {2AC6A8AC-5C0A-422A-B21A-CDC8D75F20A3} = {258D5057-81B9-40EC-A872-D21E27452749} + {59C1CEDE-AA45-41FE-8098-6279A72C421A} = {258D5057-81B9-40EC-A872-D21E27452749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705} diff --git a/Directory.Build.props b/Directory.Build.props index a8e0887c1e5..873b6a33d32 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,11 +1,26 @@ - - - - True - False - False + + + + true + true + true + true + true + false - + + + win + osx + linux + freebsd + x64 + $(TargetOsName)-$(TargetArchitecture) + + + + diff --git a/Directory.Build.targets b/Directory.Build.targets index 25c8effe24b..96e31343dda 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,5 +1,6 @@ + false release + net8.0 False diff --git a/eng/helix.proj b/eng/helix.proj index 4195e894e36..9588a6701b9 100644 --- a/eng/helix.proj +++ b/eng/helix.proj @@ -30,7 +30,7 @@ - + @@ -64,7 +64,7 @@ net7.0 netcoreapp2.0 - 2.4.2-pre.9 + 2.5.0 02:00:00 diff --git a/eng/testing/linker/SupportFiles/.editorconfig b/eng/testing/linker/SupportFiles/.editorconfig new file mode 100644 index 00000000000..276d67e2788 --- /dev/null +++ b/eng/testing/linker/SupportFiles/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*.cs] + +dotnet_analyzer_diagnostic.severity = silent +dotnet_diagnostic.severity = silent +dotnet_code_quality.severity = silent +dotnet_analyzer_diagnostic.category-AOT.severity = error +dotnet_analyzer_diagnostic.category-Trimming.severity = error +dotnet_diagnostic.SA0001.severity = none +dotnet_diagnostic.SA1516.severity = none + diff --git a/eng/testing/linker/SupportFiles/Directory.Build.props b/eng/testing/linker/SupportFiles/Directory.Build.props new file mode 100644 index 00000000000..ae755ffdccb --- /dev/null +++ b/eng/testing/linker/SupportFiles/Directory.Build.props @@ -0,0 +1,19 @@ + + + true + full + true + true + false + false + true + false + false + true + enable + enable + + + true + + diff --git a/eng/testing/linker/SupportFiles/Directory.Build.targets b/eng/testing/linker/SupportFiles/Directory.Build.targets new file mode 100644 index 00000000000..8c119d5413b --- /dev/null +++ b/eng/testing/linker/SupportFiles/Directory.Build.targets @@ -0,0 +1,2 @@ + + diff --git a/eng/testing/linker/project.csproj.template b/eng/testing/linker/project.csproj.template new file mode 100644 index 00000000000..b934ccfcbcc --- /dev/null +++ b/eng/testing/linker/project.csproj.template @@ -0,0 +1,24 @@ + + + + {TargetFramework} + Exe + {RuntimeIdentifier} + {PublishAot} + <_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs) + {AdditionalProperties} + + + + {RuntimeHostConfigurationOptions} + + + + {AdditionalProjectReferences} + + + + {AdditionalPackageReferences} + + + diff --git a/eng/testing/linker/trimmingTests.props b/eng/testing/linker/trimmingTests.props new file mode 100644 index 00000000000..f1928b5afd3 --- /dev/null +++ b/eng/testing/linker/trimmingTests.props @@ -0,0 +1,8 @@ + + + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'trimmingTests')) + $([MSBuild]::NormalizeDirectory('$(TrimmingTestDir)', 'projects')) + $(MSBuildThisFileDirectory)project.csproj.template + enable + + diff --git a/eng/testing/linker/trimmingTests.targets b/eng/testing/linker/trimmingTests.targets new file mode 100644 index 00000000000..23de4c69149 --- /dev/null +++ b/eng/testing/linker/trimmingTests.targets @@ -0,0 +1,169 @@ + + + <_additionalSourceFiles Condition="'@(TestConsoleAppSourceFiles)' == ''" Include="$(MSBuildProjectDirectory)\**\*.cs" Exclude="$(MSBuildProjectDirectory)\*.cs" /> + + @(_additionalSourceFiles) + + + + $([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)')) + + + + + + + + + + + + $([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)', '%(Filename)', '$(PackageRID)')) + $(TargetRuntimeIdentifier) + $(DefaultNetCoreTargetFramework) + $(DefaultNetCoreTargetFramework)-%(TestConsoleAppSourceFiles.TargetOS) + + + + %(ProjectDir)%(Filename).csproj + $([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', '%(Filename)')) + $([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish')) + + + + + + %(FullPath) + %(AdditionalSourceFiles) + + + + + + + + + + + + <_projectDir>%(TestConsoleApps.ProjectDir)\ + <_projectFile>%(TestConsoleApps.ProjectFile) + <_projectSourceFile>%(TestConsoleApps.ProjectCompileItems) + + + + <_additionalProjectReference Include="<ProjectReference Include="%(ProjectReference.FullPath)" SkipUseReferenceAssembly="true" />" /> + + + + <_additionalProjectReferenceTemp Include="$(AdditionalProjectReferences)" /> + <_additionalProjectReference Include="<ProjectReference Include="$(LibrariesProjectRoot)%(_additionalProjectReferenceTemp.Identity)\src\%(_additionalProjectReferenceTemp.Identity).csproj" SkipUseReferenceAssembly="true" />" /> + + + + <_additionalProjectReferencesString>@(_additionalProjectReference, '%0a ') + + + + + + + + + contentfiles;analyzers;build + + + + + <_additionalPackageReference Include="<PackageReference Include="%(PackageReference.Identity)" Version="%(PackageReference.Version)" > <PrivateAssets>%(PackageReference.PrivateAssets)</PrivateAssets> </PackageReference>" /> + + + + <_additionalPackageReferencesString>@(_additionalPackageReference, '%0a ') + + + + <_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" /> + + + + <_switchesAsItems Include="%(TestConsoleApps.DisabledFeatureSwitches)" Value="false" /> + <_switchesAsItems Include="%(TestConsoleApps.EnabledFeatureSwitches)" Value="true" /> + + <_propertiesAsItems Include="%(TestConsoleApps.DisabledProperties)" Value="false" /> + <_propertiesAsItems Include="%(TestConsoleApps.EnabledProperties)" Value="true" /> + + + + <_runtimeHostConfigurationOptionsString>@(_switchesAsItems->'<RuntimeHostConfigurationOption Include="%(Identity)" Value="%(Value)" Trim="true" />', '%0a ') + <_additionalPropertiesString>@(_propertiesAsItems->'<%(Identity)>%(Value)</%(Identity)>', '%0a ') + + + + + + + + + + + <_RemoveProps>TreatWarningsAsErrors;BuildingSolutionFile;SolutionPath;SolutionFileName;SolutionExt;SolutionDir;CurrentSolutionConfigurationContents;Platform + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs index b4b6769fede..bfd0b56726a 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModel.cs @@ -1,7 +1,7 @@ // using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.NativeAotTests; +using Microsoft.EntityFrameworkCore.NativeAotTests.Models; #pragma warning disable 219, 612, 618 #nullable enable diff --git a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs index fecbfbc380b..0c65db5fe25 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/NativeAotContextModelBuilder.cs @@ -1,6 +1,4 @@ // -using System; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; #pragma warning disable 219, 612, 618 diff --git a/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs b/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs index 1e2a5ad0b14..259502cd902 100644 --- a/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs +++ b/test/EFCore.NativeAotTests/CompiledModels/UserEntityType.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.NativeAotTests.Models; #pragma warning disable 219, 612, 618 #nullable enable @@ -15,7 +16,7 @@ internal partial class UserEntityType public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) { var runtimeEntityType = model.AddEntityType( - "Microsoft.EntityFrameworkCore.NativeAotTests.User", + "Microsoft.EntityFrameworkCore.NativeAotTests.Models.User", typeof(User), baseEntityType); diff --git a/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj b/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj index 7dac82da3e4..dcfb9993c17 100644 --- a/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj +++ b/test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj @@ -2,14 +2,11 @@ Exe - net8.0 - enable + $(DefaultNetCoreTargetFramework) enable true - $(WarningsNotAsErrors);CS1591;SA1636;SA0001;SA1402;SA1027;SA1309;SA1201;SA1200;SA1512;SA1101 - - false - false + Microsoft.EntityFrameworkCore.NativeAotTests + Microsoft.EntityFrameworkCore.NativeAotTests diff --git a/test/EFCore.NativeAotTests/EndToEnd.cs b/test/EFCore.NativeAotTests/EndToEnd.cs new file mode 100644 index 00000000000..c4b38d8a53f --- /dev/null +++ b/test/EFCore.NativeAotTests/EndToEnd.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.EntityFrameworkCore.NativeAotTests.Models; + +// using var context = new NativeAotContext(); + +// context.Database.EnsureDeleted(); +// context.Database.EnsureCreated(); + +// context.Add(new User { Name = "Andriy" }); +// await context.SaveChangesAsync(); + +// Console.WriteLine(context.Users.First().Id); + +return 100; diff --git a/test/EFCore.NativeAotTests/NativeAotContext.cs b/test/EFCore.NativeAotTests/Models/NativeAotContext.cs similarity index 94% rename from test/EFCore.NativeAotTests/NativeAotContext.cs rename to test/EFCore.NativeAotTests/Models/NativeAotContext.cs index d3f6746d458..a663d69567c 100644 --- a/test/EFCore.NativeAotTests/NativeAotContext.cs +++ b/test/EFCore.NativeAotTests/Models/NativeAotContext.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.NativeAotTests.CompiledModels; -namespace Microsoft.EntityFrameworkCore.NativeAotTests; +namespace Microsoft.EntityFrameworkCore.NativeAotTests.Models; public class NativeAotContext : DbContext { diff --git a/test/EFCore.NativeAotTests/User.cs b/test/EFCore.NativeAotTests/Models/User.cs similarity index 79% rename from test/EFCore.NativeAotTests/User.cs rename to test/EFCore.NativeAotTests/Models/User.cs index 60f645676bf..d0876f73233 100644 --- a/test/EFCore.NativeAotTests/User.cs +++ b/test/EFCore.NativeAotTests/Models/User.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -namespace Microsoft.EntityFrameworkCore.NativeAotTests; +namespace Microsoft.EntityFrameworkCore.NativeAotTests.Models; public class User { diff --git a/test/EFCore.NativeAotTests/Program.cs b/test/EFCore.NativeAotTests/Program.cs deleted file mode 100644 index 0c56ea36789..00000000000 --- a/test/EFCore.NativeAotTests/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.EntityFrameworkCore.NativeAotTests; - -using var context = new NativeAotContext(); - -context.Database.EnsureDeleted(); -context.Database.EnsureCreated(); - -context.Add(new User { Name = "Andriy" }); -context.SaveChanges(); - -Console.WriteLine(context.Users.First().Id); diff --git a/test/EFCore.NativeAotTests/readme.md b/test/EFCore.NativeAotTests/readme.md new file mode 100644 index 00000000000..8c2ea89a6fc --- /dev/null +++ b/test/EFCore.NativeAotTests/readme.md @@ -0,0 +1,3 @@ +When `dotnet test` is executed on this project a temporary project will be generated for each file directly in this folder. The new projects will be published and executed with return code 100 signaling success. Source files in subfolders will be added to all temporary projects. All the references will be copied to the temporary projects. + +It is possible to change which projects are created and what additional files are added to them, for example see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.HttpListener/tests/TrimmingTests/System.Net.HttpListener.TrimmingTests.proj \ No newline at end of file diff --git a/test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj b/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj similarity index 68% rename from test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj rename to test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj index 33e2f616fb4..9a2fe0001a6 100644 --- a/test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj +++ b/test/EFCore.TrimmingTests/EFCore.TrimmingTests.csproj @@ -2,9 +2,10 @@ Exe - net7.0 - true - false + $(DefaultNetCoreTargetFramework) + enable + Microsoft.EntityFrameworkCore.TrimmingTests + Microsoft.EntityFrameworkCore.TrimmingTests diff --git a/test/EFCore.Trimming.Tests/Program.cs b/test/EFCore.TrimmingTests/EndToEnd.cs similarity index 57% rename from test/EFCore.Trimming.Tests/Program.cs rename to test/EFCore.TrimmingTests/EndToEnd.cs index 114f9cae257..ae1dbbccd86 100644 --- a/test/EFCore.Trimming.Tests/Program.cs +++ b/test/EFCore.TrimmingTests/EndToEnd.cs @@ -3,27 +3,27 @@ using System; using System.Linq; -using EFCore.Trimming.Tests; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TrimmingTests.TestUtilities; -await using var ctx = new BlogContext(); -await ctx.Database.EnsureDeletedAsync(); -await ctx.Database.EnsureCreatedAsync(); +//await using var ctx = new BlogContext(); +//await ctx.Database.EnsureDeletedAsync(); +//await ctx.Database.EnsureCreatedAsync(); -ctx.Add(new Blog { Name = "Some Blog Name" }); -await ctx.SaveChangesAsync(); +//ctx.Add(new Blog { Name = "Some Blog Name" }); +//await ctx.SaveChangesAsync(); -ctx.ChangeTracker.Clear(); +//ctx.ChangeTracker.Clear(); -// Execute any query to make sure the basic query pipeline works -var blog = await ctx.Blogs.Where(b => b.Name.StartsWith("Some ")).SingleAsync(); -if (blog.Name != "Some Blog Name") -{ - throw new Exception($"Incorrect blog name ({blog.Name})"); -} +//// Execute any query to make sure the basic query pipeline works +//var blog = await ctx.Blogs.Where(b => b.Name!.StartsWith("Some ")).SingleAsync(); +//if (blog.Name != "Some Blog Name") +//{ +// throw new Exception($"Incorrect blog name ({blog.Name})"); +//} -Console.WriteLine("Database query executed successfully."); +return 100; public class BlogContext : DbContext { @@ -48,5 +48,5 @@ static BlogContext() public class Blog { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } diff --git a/test/EFCore.Trimming.Tests/TestEnvironment.cs b/test/EFCore.TrimmingTests/TestUtilities/TestEnvironment.cs similarity index 91% rename from test/EFCore.Trimming.Tests/TestEnvironment.cs rename to test/EFCore.TrimmingTests/TestUtilities/TestEnvironment.cs index 2edb5e22f26..6c972f1988e 100644 --- a/test/EFCore.Trimming.Tests/TestEnvironment.cs +++ b/test/EFCore.TrimmingTests/TestUtilities/TestEnvironment.cs @@ -4,7 +4,7 @@ using System.IO; using Microsoft.Extensions.Configuration; -namespace EFCore.Trimming.Tests; +namespace Microsoft.EntityFrameworkCore.TrimmingTests.TestUtilities; public static class TestEnvironment { diff --git a/test/EFCore.TrimmingTests/readme.md b/test/EFCore.TrimmingTests/readme.md new file mode 100644 index 00000000000..8c2ea89a6fc --- /dev/null +++ b/test/EFCore.TrimmingTests/readme.md @@ -0,0 +1,3 @@ +When `dotnet test` is executed on this project a temporary project will be generated for each file directly in this folder. The new projects will be published and executed with return code 100 signaling success. Source files in subfolders will be added to all temporary projects. All the references will be copied to the temporary projects. + +It is possible to change which projects are created and what additional files are added to them, for example see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.HttpListener/tests/TrimmingTests/System.Net.HttpListener.TrimmingTests.proj \ No newline at end of file