You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DistributedApplicationTestFactory.cs 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // DistributedApplicationTestFactory.cs
  3. using System.Reflection;
  4. using Microsoft.Extensions.Logging;
  5. using Xunit.Abstractions;
  6. namespace Microsoft.AutoGen.Integration.Tests;
  7. internal static class DistributedApplicationTestFactory
  8. {
  9. /// <summary>
  10. /// Creates an <see cref="IDistributedApplicationTestingBuilder"/> for the specified app host assembly.
  11. /// </summary>
  12. public static async Task<IDistributedApplicationTestingBuilder> CreateAsync(string appHostAssemblyPath, ITestOutputHelper? testOutput)
  13. {
  14. var appHostProjectName = Path.GetFileNameWithoutExtension(appHostAssemblyPath) ?? throw new InvalidOperationException("AppHost assembly was not found.");
  15. var appHostAssembly = Assembly.LoadFrom(Path.Combine(AppContext.BaseDirectory, appHostAssemblyPath));
  16. var appHostType = appHostAssembly.GetTypes().FirstOrDefault(t => t.Name.EndsWith("_AppHost"))
  17. ?? throw new InvalidOperationException("Generated AppHost type not found.");
  18. var builder = await DistributedApplicationTestingBuilder.CreateAsync(appHostType);
  19. //builder.WithRandomParameterValues();
  20. builder.WithRandomVolumeNames();
  21. builder.WithContainersLifetime(ContainerLifetime.Session);
  22. builder.Services.AddLogging(logging =>
  23. {
  24. logging.ClearProviders();
  25. logging.AddSimpleConsole();
  26. logging.AddFakeLogging();
  27. if (testOutput is not null)
  28. {
  29. logging.AddXUnit(testOutput);
  30. }
  31. logging.SetMinimumLevel(LogLevel.Trace);
  32. logging.AddFilter("Aspire", LogLevel.Trace);
  33. logging.AddFilter(builder.Environment.ApplicationName, LogLevel.Trace);
  34. });
  35. return builder;
  36. }
  37. }