Jhkim/refactoring test (#176)
Cleans up IIS initialization testing framework
This commit is contained in:
parent
68014a7acd
commit
02cffd16ec
|
|
@ -208,7 +208,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
|
||||
if (!File.Exists(fromfile))
|
||||
{
|
||||
throw new System.ApplicationException("Failed to backup " + tofile);
|
||||
throw new ApplicationException("Failed to backup " + tofile);
|
||||
}
|
||||
|
||||
// try restoring applicationhost.config again after the ininial clean up for better reliability
|
||||
|
|
@ -232,7 +232,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
// verify restoration is done successfully
|
||||
if (File.ReadAllBytes(fromfile).Length != File.ReadAllBytes(tofile).Length)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to restore applicationhost.config from " + fromfile + " to " + tofile);
|
||||
throw new ApplicationException("Failed to restore applicationhost.config from " + fromfile + " to " + tofile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -465,7 +465,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
var element = FindElement(environmentVariablesCollection, "add", "name", value);
|
||||
if (element != null)
|
||||
{
|
||||
throw new System.ApplicationException("duplicated collection item");
|
||||
throw new ApplicationException("duplicated collection item");
|
||||
}
|
||||
environmentVariablesCollection.Add(environmentVariableElement);
|
||||
}
|
||||
|
|
@ -1116,7 +1116,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output.Length != 40)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to create a certificate, output: " + output);
|
||||
throw new ApplicationException("Failed to create a certificate, output: " + output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
@ -1131,7 +1131,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output.Length != 40)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to create a certificate, output: " + output);
|
||||
throw new ApplicationException("Failed to create a certificate, output: " + output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
@ -1153,7 +1153,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output != string.Empty)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to export a certificate to RootCA, output: " + output);
|
||||
throw new ApplicationException("Failed to export a certificate to RootCA, output: " + output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
@ -1169,7 +1169,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output.Length < 500)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to get certificate public key, output: " + output);
|
||||
throw new ApplicationException("Failed to get certificate public key, output: " + output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
@ -1185,7 +1185,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output != string.Empty)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to delete a certificate (thumbprint: " + thumbPrint + ", output: " + output);
|
||||
throw new ApplicationException("Failed to delete a certificate (thumbprint: " + thumbPrint + ", output: " + output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
@ -1207,7 +1207,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
string output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output != string.Empty)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to configure certificate, output: " + output);
|
||||
throw new ApplicationException("Failed to configure certificate, output: " + output);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1227,7 +1227,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
output = TestUtility.RunPowershellScript(powershellScript);
|
||||
if (output != string.Empty)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to delete certificate, output: " + output);
|
||||
throw new ApplicationException("Failed to delete certificate, output: " + output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ namespace AspNetCoreModule.Test.Framework
|
|||
public const string UseFullIIS = "UseFullIIS";
|
||||
public const string RunAsAdministrator = "RunAsAdministrator";
|
||||
public const string MakeCertExeAvailable = "MakeCertExeAvailable";
|
||||
public const string WebSocketModuleAvailable = "WebSocketModuleAvailable";
|
||||
public const string UrlRewriteModuleAvailable = "UrlRewriteModuleAvailable";
|
||||
public const string X86Platform = "X86Platform";
|
||||
public const string Wow64BitMode = "Wow64BitMode";
|
||||
public const string RequireRunAsAdministrator = "RequireRunAsAdministrator";
|
||||
|
|
@ -65,7 +67,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
catch
|
||||
{
|
||||
_makeCertExeAvailable = false;
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
return (_makeCertExeAvailable == true);
|
||||
|
|
@ -87,9 +89,8 @@ namespace AspNetCoreModule.Test.Framework
|
|||
{
|
||||
if (_globalTestFlags == null)
|
||||
{
|
||||
bool isElevated;
|
||||
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
||||
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||
|
||||
// check if this test process is started with the Run As Administrator start option
|
||||
_globalTestFlags = Environment.ExpandEnvironmentVariables(ANCMTestFlagsEnvironmentVariable);
|
||||
|
|
@ -190,6 +191,26 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
}
|
||||
|
||||
if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "iiswsock.dll")))
|
||||
{
|
||||
// Add WebSocketModuleAvailable
|
||||
if (!_globalTestFlags.Contains(TestFlags.WebSocketModuleAvailable.ToLower()))
|
||||
{
|
||||
TestUtility.LogInformation("Added test context of " + TestFlags.WebSocketModuleAvailable);
|
||||
_globalTestFlags += ";" + TestFlags.WebSocketModuleAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "rewrite.dll")))
|
||||
{
|
||||
// Add UrlRewriteModuleAvailable
|
||||
if (!_globalTestFlags.Contains(TestFlags.UrlRewriteModuleAvailable.ToLower()))
|
||||
{
|
||||
TestUtility.LogInformation("Added test context of " + TestFlags.UrlRewriteModuleAvailable);
|
||||
_globalTestFlags += ";" + TestFlags.UrlRewriteModuleAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
_globalTestFlags = _globalTestFlags.ToLower();
|
||||
}
|
||||
|
||||
|
|
@ -213,17 +234,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
|
||||
if (!isIISInstalled)
|
||||
{
|
||||
throw new System.ApplicationException("IIS server is not installed");
|
||||
}
|
||||
|
||||
// Check websocket is installed
|
||||
if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "iiswsock.dll")))
|
||||
{
|
||||
TestUtility.LogInformation("Websocket is installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.ApplicationException("websocket module is not installed");
|
||||
throw new ApplicationException("IIS server is not installed");
|
||||
}
|
||||
|
||||
// Clean up IIS worker process
|
||||
|
|
@ -241,22 +252,12 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new System.ApplicationException("WWW service can't start");
|
||||
}
|
||||
|
||||
// check URLRewrite module exists
|
||||
if (File.Exists(Path.Combine(IISConfigUtility.Strings.IIS64BitPath, "rewrite.dll")))
|
||||
{
|
||||
TestUtility.LogInformation("Verified URL Rewrite module installed for IIS server");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.ApplicationException("URL Rewrite module is not installed");
|
||||
throw new ApplicationException("WWW service can't start");
|
||||
}
|
||||
|
||||
if (IISConfigUtility.ApppHostTemporaryBackupFileExtention == null)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to backup applicationhost.config");
|
||||
throw new ApplicationException("Failed to backup applicationhost.config");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +356,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
if (!_InitializeTestMachineCompleted)
|
||||
{
|
||||
throw new System.ApplicationException("InitializeTestMachine failed");
|
||||
throw new ApplicationException("InitializeTestMachine failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -476,7 +477,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
if (!updateSuccess)
|
||||
{
|
||||
throw new System.ApplicationException("Failed to update aspnetcore.dll");
|
||||
throw new ApplicationException("Failed to update aspnetcore.dll");
|
||||
}
|
||||
|
||||
// update applicationhost.config for IIS server with the new private ASPNET Core file name
|
||||
|
|
|
|||
|
|
@ -419,7 +419,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "appverif.exe");
|
||||
if (!File.Exists(cmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe.");
|
||||
throw new ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe.");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -427,7 +427,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "appverif.exe");
|
||||
if (!File.Exists(cmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe.");
|
||||
throw new ApplicationException("Not found :" + cmdline + "; this test requires appverif.exe.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
catch
|
||||
{
|
||||
throw new System.ApplicationException("Failed to configure Appverifier");
|
||||
throw new ApplicationException("Failed to configure Appverifier");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -456,7 +456,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "wow64", "windbg.exe");
|
||||
if (!File.Exists(debuggerCmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe.");
|
||||
throw new ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe.");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -464,7 +464,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "windbg.exe");
|
||||
if (!File.Exists(debuggerCmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe.");
|
||||
throw new ApplicationException("Not found :" + debuggerCmdline + "; this test requires windbg.exe.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -475,7 +475,7 @@ namespace AspNetCoreModule.Test.Framework
|
|||
}
|
||||
catch
|
||||
{
|
||||
throw new System.ApplicationException("Failed to attach debuger");
|
||||
throw new ApplicationException("Failed to attach debuger");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -497,12 +497,12 @@ namespace AspNetCoreModule.Test.Framework
|
|||
cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "syswow64", "appverif.exe");
|
||||
if (!File.Exists(cmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + cmdline);
|
||||
throw new ApplicationException("Not found :" + cmdline);
|
||||
}
|
||||
debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "wow64", "windbg.exe");
|
||||
if (!File.Exists(debuggerCmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + debuggerCmdline);
|
||||
throw new ApplicationException("Not found :" + debuggerCmdline);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -510,12 +510,12 @@ namespace AspNetCoreModule.Test.Framework
|
|||
cmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32", "appverif.exe");
|
||||
if (!File.Exists(cmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + cmdline);
|
||||
throw new ApplicationException("Not found :" + cmdline);
|
||||
}
|
||||
debuggerCmdline = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramFiles%"), "Debugging Tools for Windows (x64)", "windbg.exe");
|
||||
if (!File.Exists(debuggerCmdline))
|
||||
{
|
||||
throw new System.ApplicationException("Not found :" + debuggerCmdline);
|
||||
throw new ApplicationException("Not found :" + debuggerCmdline);
|
||||
}
|
||||
}
|
||||
TestUtility.RunCommand(cmdline, argument, true, false);
|
||||
|
|
|
|||
|
|
@ -695,7 +695,7 @@ namespace AspNetCoreModule.Test
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new System.ApplicationException("wrong data");
|
||||
throw new ApplicationException("wrong data");
|
||||
}
|
||||
}
|
||||
testSite.AspNetCoreApp.RestoreFile("web.config");
|
||||
|
|
|
|||
Loading…
Reference in New Issue