Ejemplo n.º 1
0
        public void Initialize()
        {
            OverrideEnvironmentDirectory();

            var host = TestWebHostBuilderFactory.CreateWebHostBuilder(new string[0]).Build();

            _token = new CancellationTokenSource();
            _task = Task.Run(async () => await host.RunAsync(_token.Token));
            _driver = CreateChromeDriver();

            DoAndWait(
                "Acquiring host address",
                () => host.ServerFeatures.Get<IServerAddressesFeature>()?.Addresses?.FirstOrDefault(),
                address => address != null,
                address => TestRuntime.InitializeServer(new Uri(address)),
                _ => "address was null"
            );

            DoAndWait(
                "First ping",
                () => TestRuntime.HttpClient.GetAsync("/api/ping").ConfigureAwait(false).GetAwaiter().GetResult(),
                response => response.StatusCode == HttpStatusCode.OK,
                response => { },
                response => response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()
            );

            DoAndWait(
                "Home page up",
                () => TestRuntime.HttpClient.GetAsync("/").ConfigureAwait(false).GetAwaiter().GetResult(),
                response => response.StatusCode == HttpStatusCode.OK,
                response => { },
                response => response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult()
            );

            DoAndWait(
                "Open browser on the home page",
                () =>
                {
                    TestRuntime.InitializeDriver(_driver);
                    TestRuntime.Pages.Home.Go();
                    return TestRuntime.Pages;
                },
                pages => pages.Title() == "VamBooru",
                pages => { },
                pages => $"Title: {pages.Title()}\nSource:\n{pages.Source()}"
            );
        }
Ejemplo n.º 2
0
 public static void Main(string[] args)
 {
     TestWebHostBuilderFactory.CreateWebHostBuilder(args).Build().Run();
 }