Unit tests running now
This commit is contained in:
Родитель
8c9e3d7ae4
Коммит
e541c4c015
|
@ -58,7 +58,18 @@ try {
|
|||
if ($ConfigureTestEnvironment) {
|
||||
Write-Host "Configuring test environment"
|
||||
.\tests\Create-CcsInfrastructure.ps1 -TestRoot $testRoot
|
||||
$env = @{ "iis_admin_test_dir" = (ConvertTo-Json $testRoot).Trim('"') }
|
||||
|
||||
try {
|
||||
$projectRoot = git rev-parse --show-toplevel
|
||||
} catch {
|
||||
Write-Verbose "Error looking for project root $_, using scrpt location as reference point"
|
||||
$projectRoot = (Join-Path $PSScriptRoot "..")
|
||||
}
|
||||
|
||||
$env = @{
|
||||
"iis_admin_test_dir" = (ConvertTo-Json $testRoot).Trim('"');
|
||||
"project_dir" = $projectRoot
|
||||
}
|
||||
ReplaceTemplate ([System.IO.Path]::Combine($solutionRoot, "test", "appsettings.test.json.template")) $env
|
||||
ReplaceTemplate ([System.IO.Path]::Combine($solutionRoot, "test", "Microsoft.IIS.Administration.Tests", "test.config.json.template")) $env
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public async Task CanEnable()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -50,7 +50,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
Assert.True(Enable(FOLDER_PATH, user.Username, user.Password, PVK_PASS));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public async Task PathMustBeAllowed()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -79,7 +79,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public void CredentialsMustBeValid()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -107,7 +107,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public async Task DynamicallyAddsToStores()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -121,7 +121,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
Assert.False(GetStores().Any(store => store.Value<string>("name").Equals(NAME, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public async Task CcsCertificatesShown()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -134,7 +134,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "Pending https://github.com/Microsoft/IIS.Administration/issues/236")]
|
||||
public async Task CanCreateCcsBinding()
|
||||
{
|
||||
RequireCcsTestInfrastructure();
|
||||
|
@ -331,7 +331,6 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
user.Username = CentralCertificates.CcsTestUsername;
|
||||
user.Password = Guid.NewGuid().ToString();
|
||||
|
||||
await CreateLocalUser(user.Username, user.Password);
|
||||
|
||||
return user;
|
||||
|
@ -339,8 +338,9 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
private static Task CreateLocalUser(string username, string password)
|
||||
{
|
||||
var createScriptLocation = Path.Combine(Configuration.PROJECT_PATH, "scripts", "tests", "Create-User.ps1");
|
||||
// User creation already implemented in powershell install scripts, vs many interop calls
|
||||
return RunProcess("PowerShell.exe", $@"""c:\\src\\repos\\iis.administration\\scripts\tests\\Create-User.ps1"" -Name '{username}' -Password '{password}'");
|
||||
return RunProcess("PowerShell.exe", $@"""{createScriptLocation}"" -Name '{username}' -Password '{password}'");
|
||||
}
|
||||
|
||||
private static Task RunProcess(string tool, string arguments)
|
||||
|
|
|
@ -44,6 +44,21 @@ namespace Microsoft.IIS.Administration.Tests {
|
|||
}
|
||||
}
|
||||
|
||||
public static string PROJECT_PATH
|
||||
{
|
||||
get
|
||||
{
|
||||
var val = _config.Value<string>("project_path");
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
val = AppContext.BaseDirectory;
|
||||
}
|
||||
|
||||
return Environment.ExpandEnvironmentVariables(val);
|
||||
}
|
||||
}
|
||||
|
||||
public static JObject Raw {
|
||||
get {
|
||||
return _config;
|
||||
|
|
|
@ -217,9 +217,11 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
[Fact]
|
||||
public void CreateEditDeleteFile()
|
||||
{
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
|
||||
// Create web file
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME);
|
||||
|
@ -282,16 +284,19 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
string testContent = "Test content for copying files.";
|
||||
JObject copyInfo = null;
|
||||
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using(TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME);
|
||||
|
||||
var physicalPath = Environment.ExpandEnvironmentVariables(webFile["file_info"].Value<string>("physical_path"));
|
||||
File.WriteAllText(physicalPath, testContent);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
var fileInfo = Utils.FollowLink(client, webFile.Value<JObject>("file_info"), "self");
|
||||
var parent = fileInfo.Value<JObject>("parent");
|
||||
|
||||
|
@ -309,7 +314,8 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
//
|
||||
// Wait for copy to finish
|
||||
HttpResponseMessage res = null;
|
||||
do {
|
||||
do
|
||||
{
|
||||
res = client.GetAsync(Utils.Self(copyInfo)).Result;
|
||||
} while (res.StatusCode == HttpStatusCode.OK);
|
||||
|
||||
|
@ -322,11 +328,14 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
|
||||
Assert.Equal(copyContent, testContent);
|
||||
}
|
||||
finally {
|
||||
if (webFile != null && webFile["file_info"] != null) {
|
||||
finally
|
||||
{
|
||||
if (webFile != null && webFile["file_info"] != null)
|
||||
{
|
||||
Assert.True(client.Delete(Utils.Self(webFile.Value<JObject>("file_info"))));
|
||||
}
|
||||
if (copyInfo != null) {
|
||||
if (copyInfo != null)
|
||||
{
|
||||
Assert.True(client.Delete(Utils.Self(copyInfo.Value<JObject>("file"))));
|
||||
}
|
||||
}
|
||||
|
@ -439,9 +448,11 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
[Fact]
|
||||
public void RangeUploadDownload()
|
||||
{
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
|
||||
// Create web file
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME);
|
||||
|
@ -518,9 +529,11 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
}
|
||||
|
||||
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
|
||||
var webFiles = new List<JObject>();
|
||||
var fileInfos = new List<JObject>();
|
||||
|
@ -561,9 +574,11 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
var size = 1024 * 1024 * 5;
|
||||
var truncateSize = size / 2;
|
||||
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME);
|
||||
var fileInfo = Utils.FollowLink(client, webFile.Value<JObject>("file_info"), "self");
|
||||
|
||||
|
@ -591,10 +606,12 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
[Fact]
|
||||
public void CreateRenameFile()
|
||||
{
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
JObject target = null;
|
||||
string updatedName = "updated_test_file_name.txt";
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
|
||||
try {
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME);
|
||||
|
@ -616,10 +633,13 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
[Fact]
|
||||
public void CreateRenameDirectory()
|
||||
{
|
||||
using (HttpClient client = ApiHttpClient.Create()) {
|
||||
using (HttpClient client = ApiHttpClient.Create())
|
||||
using (TestSiteContainer container = new TestSiteContainer(client))
|
||||
{
|
||||
|
||||
JObject site = Sites.GetSite(client, container.SiteName);
|
||||
JObject target = null;
|
||||
string updatedName = "updated_test_folder_name";
|
||||
JObject site = Sites.GetSite(client, "Default Web Site");
|
||||
|
||||
try {
|
||||
var webFile = CreateWebFile(client, site, TEST_FILE_NAME, "directory");
|
||||
|
@ -1005,4 +1025,30 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestSiteContainer : IDisposable
|
||||
{
|
||||
public const string TEST_SITE_NAME = "test_site";
|
||||
public const int TEST_PORT = 50306;
|
||||
public static readonly string TEST_SITE_PATH = Path.Combine(Configuration.TEST_ROOT_PATH, TEST_SITE_NAME);
|
||||
public static readonly string SITE_URL = $"{Configuration.TEST_SERVER_URL}/api/webserver/websites";
|
||||
|
||||
public readonly string SiteName = TEST_SITE_NAME;
|
||||
private readonly string testSiteUri;
|
||||
private readonly HttpClient client;
|
||||
|
||||
public TestSiteContainer(HttpClient client)
|
||||
{
|
||||
this.client = client;
|
||||
Sites.EnsureNoSite(client, TEST_SITE_NAME);
|
||||
JObject site = Sites.CreateSite(client, TEST_SITE_NAME, TEST_PORT, TEST_SITE_PATH);
|
||||
Assert.NotNull(site);
|
||||
testSiteUri = $"{SITE_URL}/{site.Value<string>("id")}";
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Sites.DeleteSite(client, testSiteUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"ccs_user": "IisAdminCcsTestR",
|
||||
"project_path": "%project_dir%",
|
||||
"test_server": "https://localhost",
|
||||
"test_port": "44326",
|
||||
"test_root_path": "%iis_admin_test_dir%"
|
||||
"test_root_path": "%iis_admin_test_dir%",
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче