WebHostBuilderTests.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System.IO;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Server.IntegrationTesting;
  7. using Microsoft.AspNetCore.Testing;
  8. using Microsoft.AspNetCore.Testing.xunit;
  9. using Microsoft.Extensions.Logging.Testing;
  10. using Xunit;
  11. using Xunit.Abstractions;
  12. namespace Microsoft.AspNetCore.Hosting.FunctionalTests
  13. {
  14. public class WebHostBuilderTests : LoggedTest
  15. {
  16. public WebHostBuilderTests(ITestOutputHelper output) : base(output) { }
  17. public static TestMatrix TestVariants => TestMatrix.ForServers(ServerType.Kestrel)
  18. .WithTfms(Tfm.Net461, Tfm.NetCoreApp22);
  19. [ConditionalTheory]
  20. [MemberData(nameof(TestVariants))]
  21. public async Task InjectedStartup_DefaultApplicationNameIsEntryAssembly(TestVariant variant)
  22. {
  23. using (StartLog(out var loggerFactory))
  24. {
  25. var logger = loggerFactory.CreateLogger(nameof(InjectedStartup_DefaultApplicationNameIsEntryAssembly));
  26. var applicationPath = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("Hosting"), "test", "TestAssets", "IStartupInjectionAssemblyName");
  27. var deploymentParameters = new DeploymentParameters(variant)
  28. {
  29. ApplicationPath = applicationPath,
  30. StatusMessagesEnabled = false
  31. };
  32. using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory))
  33. {
  34. await deployer.DeployAsync();
  35. string output = string.Empty;
  36. var mre = new ManualResetEventSlim();
  37. deployer.HostProcess.OutputDataReceived += (sender, args) =>
  38. {
  39. if (!string.IsNullOrWhiteSpace(args.Data))
  40. {
  41. output += args.Data + '\n';
  42. mre.Set();
  43. }
  44. };
  45. mre.Wait(50000);
  46. output = output.Trim('\n');
  47. Assert.Equal($"IStartupInjectionAssemblyName", output);
  48. }
  49. }
  50. }
  51. }
  52. }