// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { public static class Helpers { public static string GetTestWebSitePath(string name) { return Path.Combine(TestPathUtilities.GetSolutionRootDirectory("IISIntegration"),"test", "WebSites", name); } public static string GetInProcessTestSitesPath() => GetTestWebSitePath("InProcessWebSite"); public static string GetOutOfProcessTestSitesPath() => GetTestWebSitePath("OutOfProcessWebSite"); public static async Task AssertStarts(IISDeploymentResult deploymentResult, string path = "/HelloWorld") { var response = await deploymentResult.HttpClient.GetAsync(path); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); } public static async Task StressLoad(HttpClient httpClient, string path, Action action) { async Task RunRequests() { var connection = new HttpClient() { BaseAddress = httpClient.BaseAddress }; for (int j = 0; j < 10; j++) { var response = await connection.GetAsync(path); action(response); } } List tasks = new List(); for (int i = 0; i < 10; i++) { tasks.Add(Task.Run(RunRequests)); } await Task.WhenAll(tasks); } public static void CopyFiles(DirectoryInfo source, DirectoryInfo target, ILogger logger) { foreach (DirectoryInfo directoryInfo in source.GetDirectories()) { CopyFiles(directoryInfo, target.CreateSubdirectory(directoryInfo.Name), logger); } logger.LogDebug($"Processing {target.FullName}"); foreach (FileInfo fileInfo in source.GetFiles()) { logger.LogDebug($" Copying {fileInfo.Name}"); var destFileName = Path.Combine(target.FullName, fileInfo.Name); fileInfo.CopyTo(destFileName); } } } }