AspNetCoreOnFullFramework.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using Microsoft.DotNet.Cli.Utils;
  4. namespace Microsoft.NET.Build.Tests
  5. {
  6. public class AspNetCoreOnFullFramework : SdkTest
  7. {
  8. public AspNetCoreOnFullFramework(ITestOutputHelper log) : base(log)
  9. {
  10. }
  11. [WindowsOnlyTheory]
  12. [InlineData("1.1.2")]
  13. [InlineData("2.0.4")]
  14. public void It_discovers_assembly_parts(string aspnetVersion)
  15. {
  16. var testProject = new TestProject()
  17. {
  18. Name = "AssemblyPartDiscovery",
  19. TargetFrameworks = "net462",
  20. IsExe = true
  21. };
  22. testProject.SourceFiles["Program.cs"] = @"
  23. using Microsoft.AspNetCore.Mvc.Internal;
  24. using Microsoft.Extensions.DependencyModel;
  25. using System.IO;
  26. using System.Linq;
  27. public class Program
  28. {
  29. public static void Main(string[] args)
  30. {
  31. var parts = DefaultAssemblyPartDiscoveryProvider.DiscoverAssemblyParts(""" + testProject.Name + @""");
  32. foreach (var item in parts)
  33. {
  34. System.Console.WriteLine(item.Name);
  35. }
  36. }
  37. }";
  38. TestProject referencedProjectWithPart = new()
  39. {
  40. Name = "ReferencedProjectWithPart",
  41. TargetFrameworks = "net462",
  42. IsExe = false
  43. };
  44. referencedProjectWithPart.References.Add("System.ServiceModel");
  45. referencedProjectWithPart.SourceFiles["Class1.cs"] = @"
  46. class Class1
  47. {
  48. public string X => typeof(System.ServiceModel.AddressFilterMode).ToString();
  49. }";
  50. TestProject referencedProjectWithMvc = new()
  51. {
  52. Name = "ReferencedProjectWithMVC",
  53. ProjectSdk = "Microsoft.NET.Sdk.Web",
  54. TargetFrameworks = "net462",
  55. IsExe = false
  56. };
  57. referencedProjectWithMvc.PackageReferences.Add(new TestPackageReference("Microsoft.AspNetCore.Mvc", aspnetVersion));
  58. testProject.ReferencedProjects.Add(referencedProjectWithPart);
  59. testProject.ReferencedProjects.Add(referencedProjectWithMvc);
  60. var testProjectInstance = _testAssetsManager
  61. .CreateTestProject(testProject, identifier: aspnetVersion);
  62. var buildCommand = new BuildCommand(testProjectInstance);
  63. buildCommand.Execute()
  64. .Should()
  65. .Pass();
  66. string outputPath = buildCommand.GetOutputDirectory(testProject.TargetFrameworks).FullName;
  67. string exePath = Path.Combine(outputPath, testProject.Name + ".exe");
  68. var toolCommandSpec = new SdkCommandSpec()
  69. {
  70. FileName = exePath
  71. };
  72. TestContext.Current.AddTestEnvironmentVariables(toolCommandSpec.Environment);
  73. ICommand toolCommand = toolCommandSpec.ToCommand().CaptureStdOut();
  74. var toolResult = toolCommand.Execute();
  75. toolResult.Should().Pass();
  76. }
  77. }
  78. }