-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGlobalSetup.cs
71 lines (61 loc) · 1.96 KB
/
GlobalSetup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Razor.Playwright.TestSetup;
using Razor.PostgreSql.Sut;
using TestExamplesDotnet;
using TestExamplesDotnet.EntityFrameworkCore;
using TestExamplesDotnet.Nunit;
using TestExamplesDotnet.PostgreSql;
[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[assembly: Parallelizable(ParallelScope.Children)]
namespace Razor.Playwright;
[SetUpFixture]
public class GlobalSetup
{
internal static IServiceProvider Provider => _serviceProvider ?? throw new InvalidOperationException("GlobalSetup has not been run.");
private static ServiceProvider? _serviceProvider;
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
InstallPlayWright();
var services = new ServiceCollection();
services.AddLogging(x => x.AddNunitLogging());
services.RegisterPostgreSqlContainer();
services.AddScoped<RazorSut>();
services.RegisterMigrationInitializer<BloggingContext>();
_serviceProvider = services.BuildServiceProvider();
}
private static void InstallPlayWright()
{
var attempts = 0;
while (true)
{
var exitCode = Microsoft.Playwright.Program.Main(new[] { "install", "--with-deps", "chromium" });
if (exitCode != 0)
{
Console.WriteLine($"Failed to install playwright installation exited with code {exitCode}");
if (attempts > 3)
{
Assert.Fail();
}
else
{
Console.WriteLine("Retrying playwright installation");
}
}
else
{
return;
}
attempts++;
}
}
[OneTimeTearDown]
public async Task RunAfterAnyTests()
{
if (_serviceProvider != null)
{
await _serviceProvider.DisposeAsync();
}
}
}