TestBase.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.IO;
  3. using System.Net.Http;
  4. using System.Net.Http.Headers;
  5. using System.Reflection;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.TestHost;
  8. namespace Masuit.Tools.Core.Test.AspNetCore
  9. {
  10. public abstract class TestBase
  11. {
  12. protected TestBase()
  13. {
  14. string path = Path.GetDirectoryName(typeof(Startup).GetTypeInfo().Assembly.Location);
  15. DirectoryInfo di = new DirectoryInfo(path).Parent.Parent.Parent;
  16. // Arrange
  17. //var hostBuilder = Host.CreateDefaultBuilder().ConfigureWebHostDefaults(configurationBuilder => configurationBuilder.UseStartup<Startup>().UseContentRoot(di.FullName));
  18. //var host = hostBuilder.Build();
  19. //host.Run();
  20. //todo:.NET Core3.0创建测试服务器
  21. this.Server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
  22. this.Client = this.Server.CreateClient();
  23. }
  24. public HttpClient Client { get; private set; }
  25. public EntityTagHeaderValue EntityTag { get; } = new EntityTagHeaderValue("\"TestFile\"");
  26. public DateTimeOffset LastModified { get; } = new DateTimeOffset(2016, 1, 1, 0, 0, 0, TimeSpan.Zero);
  27. public TestServer Server { get; private set; }
  28. }
  29. }