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

77 lines
2.5 KiB

  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.AspNetCore.TestHost;
  3. using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
  4. using Microsoft.eShopOnContainers.Services.Ordering.API;
  5. using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure;
  6. using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. using System.IO;
  12. using System.Reflection;
  13. namespace FunctionalTests.Services.Ordering
  14. {
  15. public class OrderingScenariosBase
  16. {
  17. public TestServer CreateServer()
  18. {
  19. var path = Assembly.GetAssembly(typeof(OrderingScenariosBase))
  20. .Location;
  21. var hostBuilder = new WebHostBuilder()
  22. .UseContentRoot(Path.GetDirectoryName(path))
  23. .ConfigureAppConfiguration(cb =>
  24. {
  25. cb.AddJsonFile("Services/Ordering/appsettings.json", optional: false)
  26. .AddEnvironmentVariables();
  27. }).UseStartup<OrderingTestsStartup>();
  28. var testServer = new TestServer(hostBuilder);
  29. testServer.Host
  30. .MigrateDbContext<OrderingContext>((context, services) =>
  31. {
  32. var env = services.GetService<IHostingEnvironment>();
  33. var settings = services.GetService<IOptions<OrderingSettings>>();
  34. var logger = services.GetService<ILogger<OrderingContextSeed>>();
  35. new OrderingContextSeed()
  36. .SeedAsync(context, env, settings, logger)
  37. .Wait();
  38. })
  39. .MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
  40. return testServer;
  41. }
  42. public static class Get
  43. {
  44. public static string Orders = "api/v1/orders";
  45. public static string OrderBy(int id)
  46. {
  47. return $"api/v1/orders/{id}";
  48. }
  49. }
  50. public static class Post
  51. {
  52. public static string AddNewOrder = "api/v1/orders/new";
  53. }
  54. public static class Put
  55. {
  56. public static string CancelOrder = "api/v1/orders/cancel";
  57. }
  58. public static class Delete
  59. {
  60. public static string OrderBy(int id)
  61. {
  62. return $"api/v1/orders/{id}";
  63. }
  64. }
  65. }
  66. }