public async Task ShouldRunWebsite() { await using var testSolution = await CopyTestAssets("demowebsite"); var projectPath = Path.Join(testSolution.Value, "demowebsite"); await using var iisHost = new IISHost(new Dictionary <string, string>()); using var cancel = new CancellationTokenSource(); var port = CreateRandomPort(); var name = "demosolutionsitename"; var run = iisHost.Run(_console, new CommandArguments { Path = new DirectoryInfo(projectPath), Port = port, Name = name }, cancel.Token); try { var httpClient = new HttpClient(); var res = await Retry.Get(() => httpClient.GetAsync($"http://localhost:{port}/DemoApi"), 20, Retry.ConstantTimeBackOff()); if (!res.IsSuccessStatusCode) { _console.Out.WriteLine(await res.Content.ReadAsStringAsync()); } Assert.True(res.IsSuccessStatusCode); var json = await JsonSerializer.DeserializeAsync <Dictionary <string, string> >(await res.Content.ReadAsStreamAsync()); Assert.Equal(name, json["siteName"]); } finally { cancel.Cancel(); await run; } }
public async Task ShouldNotWorkIfNotBuilt() { await using var testSolution = await CopyTestAssets("demowebsite"); var projectPath = Path.Join(testSolution.Value, "demowebsite"); await using var iisHost = new IISHost(new Dictionary <string, string>()); using var cancel = new CancellationTokenSource(); var port = CreateRandomPort(); var name = "demosolutionsitename"; var run = iisHost.Run(_console, new CommandArguments { Path = new DirectoryInfo(projectPath), Port = port, Name = name, NoBuild = true }, cancel.Token); try { var httpClient = new HttpClient(); var res = await Retry.Get(() => httpClient.GetAsync($"http://localhost:{port}/DemoApi"), 20, Retry.ConstantTimeBackOff()); Assert.False(res.IsSuccessStatusCode); } finally { cancel.Cancel(); await run; } }