Fixed remaining tests
- Lots of duplication zomg
This commit is contained in:
parent
2b0889f684
commit
70036a5e3c
@ -1,6 +1,7 @@
|
||||
CreateWebHostBuilder(args).Build()
|
||||
.MigrateDbContext<WebhooksContext>((_, __) => { })
|
||||
.Run();
|
||||
// TODO: Don't do this twice...
|
||||
var host = CreateWebHostBuilder(args).Build();
|
||||
host.Services.MigrateDbContext<WebhooksContext>((_, __) => { });
|
||||
host.Run();
|
||||
|
||||
|
||||
IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
@ -16,4 +17,4 @@ IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
builder.AddConsole();
|
||||
builder.AddDebug();
|
||||
builder.AddAzureWebAppDiagnostics();
|
||||
});
|
||||
});
|
||||
|
@ -35,10 +35,17 @@
|
||||
<Content Include="Services\Ordering\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Services\Basket\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Services\Catalog\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
|
@ -26,3 +26,8 @@ global using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
global using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure;
|
||||
global using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||
global using FunctionalTests.Services.Catalog;
|
||||
|
||||
// This is a bit of a hack, since we need to differentiate each of these app's program
|
||||
global using BasketProgram = Microsoft.eShopOnContainers.Services.Basket.API.BasketSettings;
|
||||
global using CatalogProgram = Microsoft.eShopOnContainers.Services.Catalog.API.CatalogSettings;
|
||||
global using OrderingProgram = Microsoft.eShopOnContainers.Services.Ordering.API.OrderingSettings;
|
||||
|
@ -1,24 +1,35 @@
|
||||
namespace FunctionalTests.Services.Basket;
|
||||
using FunctionalTests.Middleware;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
public class BasketScenariosBase
|
||||
namespace FunctionalTests.Services.Basket;
|
||||
|
||||
public class BasketScenariosBase : WebApplicationFactory<BasketProgram>
|
||||
{
|
||||
private const string ApiUrlBase = "api/v1/basket";
|
||||
|
||||
|
||||
public TestServer CreateServer()
|
||||
{
|
||||
var path = Assembly.GetAssembly(typeof(BasketScenariosBase))
|
||||
.Location;
|
||||
return Server;
|
||||
}
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseContentRoot(Path.GetDirectoryName(path))
|
||||
.ConfigureAppConfiguration(cb =>
|
||||
{
|
||||
cb.AddJsonFile("Services/Basket/appsettings.json", optional: false)
|
||||
.AddEnvironmentVariables();
|
||||
});
|
||||
|
||||
return new TestServer(hostBuilder);
|
||||
protected override IHost CreateHost(IHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(servies =>
|
||||
{
|
||||
servies.AddSingleton<IStartupFilter, AuthStartupFilter>();
|
||||
});
|
||||
|
||||
builder.ConfigureAppConfiguration(c =>
|
||||
{
|
||||
var directory = Path.GetDirectoryName(typeof(BasketScenariosBase).Assembly.Location)!;
|
||||
|
||||
c.AddJsonFile(Path.Combine(directory, "Services/Basket/appsettings.json"), optional: false);
|
||||
});
|
||||
|
||||
return base.CreateHost(builder);
|
||||
}
|
||||
|
||||
public static class Get
|
||||
@ -39,4 +50,17 @@ public class BasketScenariosBase
|
||||
public static string CreateBasket = $"{ApiUrlBase}/";
|
||||
public static string CheckoutOrder = $"{ApiUrlBase}/checkout";
|
||||
}
|
||||
|
||||
private class AuthStartupFilter : IStartupFilter
|
||||
{
|
||||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
|
||||
{
|
||||
return app =>
|
||||
{
|
||||
app.UseMiddleware<AutoAuthorizeMiddleware>();
|
||||
|
||||
next(app);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,39 @@
|
||||
namespace FunctionalTests.Services.Catalog;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||
|
||||
public class CatalogScenariosBase
|
||||
using FunctionalTests.Services.Ordering;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
public class CatalogScenariosBase : WebApplicationFactory<CatalogProgram>
|
||||
{
|
||||
public TestServer CreateServer()
|
||||
{
|
||||
var path = Assembly.GetAssembly(typeof(CatalogScenariosBase))
|
||||
.Location;
|
||||
Services.MigrateDbContext<CatalogContext>((context, services) =>
|
||||
{
|
||||
var env = services.GetService<IWebHostEnvironment>();
|
||||
var settings = services.GetService<IOptions<CatalogSettings>>();
|
||||
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseContentRoot(Path.GetDirectoryName(path))
|
||||
.ConfigureAppConfiguration(cb =>
|
||||
{
|
||||
cb.AddJsonFile("Services/Catalog/appsettings.json", optional: false)
|
||||
.AddEnvironmentVariables();
|
||||
});
|
||||
new CatalogContextSeed()
|
||||
.SeedAsync(context, env, settings, logger)
|
||||
.Wait();
|
||||
})
|
||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||
|
||||
var testServer = new TestServer(hostBuilder);
|
||||
return Server;
|
||||
}
|
||||
|
||||
testServer.Host
|
||||
.MigrateDbContext<CatalogContext>((context, services) =>
|
||||
{
|
||||
var env = services.GetService<IWebHostEnvironment>();
|
||||
var settings = services.GetService<IOptions<CatalogSettings>>();
|
||||
var logger = services.GetService<ILogger<CatalogContextSeed>>();
|
||||
protected override IHost CreateHost(IHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureAppConfiguration(c =>
|
||||
{
|
||||
var directory = Path.GetDirectoryName(typeof(CatalogScenariosBase).Assembly.Location)!;
|
||||
|
||||
new CatalogContextSeed()
|
||||
.SeedAsync(context, env, settings, logger)
|
||||
.Wait();
|
||||
})
|
||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||
c.AddJsonFile(Path.Combine(directory, "Services/Catalog/appsettings.json"), optional: false);
|
||||
});
|
||||
|
||||
return testServer;
|
||||
return base.CreateHost(builder);
|
||||
}
|
||||
|
||||
public static class Get
|
||||
|
@ -1,23 +1,15 @@
|
||||
namespace FunctionalTests.Services.Ordering;
|
||||
using FunctionalTests.Middleware;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
public class OrderingScenariosBase
|
||||
namespace FunctionalTests.Services.Ordering;
|
||||
|
||||
public class OrderingScenariosBase : WebApplicationFactory<OrderingProgram>
|
||||
{
|
||||
public TestServer CreateServer()
|
||||
{
|
||||
var path = Assembly.GetAssembly(typeof(OrderingScenariosBase))
|
||||
.Location;
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseContentRoot(Path.GetDirectoryName(path))
|
||||
.ConfigureAppConfiguration(cb =>
|
||||
{
|
||||
cb.AddJsonFile("Services/Ordering/appsettings.json", optional: false)
|
||||
.AddEnvironmentVariables();
|
||||
});
|
||||
|
||||
var testServer = new TestServer(hostBuilder);
|
||||
|
||||
testServer.Host
|
||||
Services
|
||||
.MigrateDbContext<OrderingContext>((context, services) =>
|
||||
{
|
||||
var env = services.GetService<IWebHostEnvironment>();
|
||||
@ -30,7 +22,24 @@ public class OrderingScenariosBase
|
||||
})
|
||||
.MigrateDbContext<IntegrationEventLogContext>((_, __) => { });
|
||||
|
||||
return testServer;
|
||||
return Server;
|
||||
}
|
||||
|
||||
protected override IHost CreateHost(IHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(servies =>
|
||||
{
|
||||
servies.AddSingleton<IStartupFilter, AuthStartupFilter>();
|
||||
});
|
||||
|
||||
builder.ConfigureAppConfiguration(c =>
|
||||
{
|
||||
var directory = Path.GetDirectoryName(typeof(OrderingScenariosBase).Assembly.Location)!;
|
||||
|
||||
c.AddJsonFile(Path.Combine(directory, "Services/Ordering/appsettings.json"), optional: false);
|
||||
});
|
||||
|
||||
return base.CreateHost(builder);
|
||||
}
|
||||
|
||||
public static class Get
|
||||
@ -60,4 +69,17 @@ public class OrderingScenariosBase
|
||||
return $"api/v1/orders/{id}";
|
||||
}
|
||||
}
|
||||
|
||||
private class AuthStartupFilter : IStartupFilter
|
||||
{
|
||||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
|
||||
{
|
||||
return app =>
|
||||
{
|
||||
app.UseMiddleware<AutoAuthorizeMiddleware>();
|
||||
|
||||
next(app);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user