Exemplo n.º 1
0
 public static async Task Main(string[] args)
 {
     await IISHost.Run(args, (webHostBuilder) =>
     {
         webHostBuilder.UseStartup <Startup>();
     });
 }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }