Add xUnit tests for reading Policy settings from config file

This commit is contained in:
Dongbo Wang 2018-01-03 12:43:28 -08:00
parent 41c66dbc26
commit 117e83a025
14 changed files with 932 additions and 29 deletions

View File

@ -1364,7 +1364,8 @@ function Test-PSPesterResults
function Start-PSxUnit {
[CmdletBinding()]param(
[string] $TestResultsFile = "XUnitResults.xml"
[string] $SequentialTestResultsFile = "SequentialXUnitResults.xml",
[string] $ParallelTestResultsFile = "ParallelXUnitResults.xml"
)
# Add .NET CLI tools to PATH
@ -1375,9 +1376,11 @@ function Start-PSxUnit {
throw "PowerShell must be built before running tests!"
}
if(Test-Path $TestResultsFile)
{
Remove-Item $TestResultsFile -Force -ErrorAction SilentlyContinue
if (Test-Path $SequentialTestResultsFile) {
Remove-Item $SequentialTestResultsFile -Force -ErrorAction SilentlyContinue
}
if (Test-Path $ParallelTestResultsFile) {
Remove-Item $ParallelTestResultsFile -Force -ErrorAction SilentlyContinue
}
try {
@ -1386,12 +1389,7 @@ function Start-PSxUnit {
# Path manipulation to obtain test project output directory
dotnet restore
# --fx-version workaround required due to https://github.com/dotnet/cli/issues/7901#issuecomment-343323674
if($Environment.IsWindows)
{
dotnet xunit --fx-version 2.0.0 -xml $TestResultsFile
}
else
if(-not $Environment.IsWindows)
{
if($Environment.IsMacOS)
{
@ -1419,9 +1417,12 @@ function Start-PSxUnit {
{
throw "Dependencies $requiredDependencies not met."
}
dotnet xunit --fx-version 2.0.0 -configuration $Options.configuration -xml $TestResultsFile
}
# '-fxversion' workaround required due to https://github.com/dotnet/cli/issues/7901#issuecomment-343323674
# Run sequential tests first, and then run the tests that can execute in parallel
dotnet xunit -fxversion 2.0.0 -configuration $Options.configuration -xml $SequentialTestResultsFile -namespace "PSTests.Sequential" -parallel none
dotnet xunit -fxversion 2.0.0 -configuration $Options.configuration -xml $ParallelTestResultsFile -namespace "PSTests.Parallel" -nobuild
}
finally {
Pop-Location

View File

@ -2,7 +2,7 @@ using Xunit;
using System;
using System.Management.Automation.Language;
namespace PSTests
namespace PSTests.Parallel
{
public static class PSEnumerableBinderTests
{

View File

@ -4,7 +4,7 @@ using System.IO;
using System.Diagnostics;
using System.Management.Automation;
namespace PSTests
namespace PSTests.Parallel
{
public static class PlatformTests
{

View File

@ -2,7 +2,7 @@ using Xunit;
using System;
using System.Management.Automation;
namespace PSTests
namespace PSTests.Parallel
{
public static class PSTypeExtensionsTests
{

View File

@ -15,7 +15,7 @@ using Microsoft.PowerShell;
using Microsoft.PowerShell.Commands;
using System.Reflection;
namespace PSTests
namespace PSTests.Parallel
{
public class FileSystemProviderTests: IDisposable
{

View File

@ -2,7 +2,7 @@ using Xunit;
using System;
using System.Management.Automation;
namespace PSTests
namespace PSTests.Parallel
{
// Not static because a test requires non-const variables
public class MshSnapinInfoTests

View File

@ -0,0 +1,893 @@
using Xunit;
using System;
using System.IO;
using System.Management.Automation;
using System.Management.Automation.Configuration;
using System.Management.Automation.Internal;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace PSTests.Sequential
{
public class PowerShellPolicyFixture : IDisposable
{
private readonly string systemWideConfigFile;
private readonly string currentUserConfigFile;
private readonly string systemWideConfigBackupFile;
private readonly string currentUserConfigBackupFile;
private readonly string systemWideConfigDirectory;
private readonly string currentUserConfigDirectory;
private readonly JsonSerializer serializer;
private readonly PowerShellPolicies systemWidePolicies;
private readonly PowerShellPolicies currentUserPolicies;
private readonly bool originalTestHookValue;
public PowerShellPolicyFixture()
{
systemWideConfigDirectory = Utils.DefaultPowerShellAppBase;
currentUserConfigDirectory = Utils.GetUserConfigurationDirectory();
systemWideConfigFile = Path.Combine(systemWideConfigDirectory, "PowerShellProperties.json");
currentUserConfigFile = Path.Combine(currentUserConfigDirectory, "PowerShellProperties.json");
if (File.Exists(systemWideConfigFile))
{
systemWideConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
File.Move(systemWideConfigFile, systemWideConfigBackupFile);
}
if (File.Exists(currentUserConfigFile))
{
currentUserConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
File.Move(currentUserConfigFile, currentUserConfigBackupFile);
}
var settings = new JsonSerializerSettings()
{
TypeNameHandling = TypeNameHandling.None,
MaxDepth = 10,
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
serializer = JsonSerializer.Create(settings);
systemWidePolicies = new PowerShellPolicies()
{
ScriptExecution = new ScriptExecution() { ExecutionPolicy = "RemoteSigned", EnableScripts = true },
ScriptBlockLogging = new ScriptBlockLogging() { EnableScriptBlockInvocationLogging = true, EnableScriptBlockLogging = false },
ModuleLogging = new ModuleLogging() { EnableModuleLogging = false, ModuleNames = new string[] { "PSReadline", "PowerShellGet" } },
ProtectedEventLogging = new ProtectedEventLogging() { EnableProtectedEventLogging = false, EncryptionCertificate = new string[] { "Joe" } },
Transcription = new Transcription() { EnableInvocationHeader = true, EnableTranscripting = true, OutputDirectory = "c:\tmp" },
UpdatableHelp = new UpdatableHelp() { DefaultSourcePath = "f:\temp" },
ConsoleSessionConfiguration = new ConsoleSessionConfiguration() { EnableConsoleSessionConfiguration = true, ConsoleSessionConfigurationName = "name" }
};
currentUserPolicies = new PowerShellPolicies()
{
ScriptExecution = new ScriptExecution() { ExecutionPolicy = "RemoteSigned" },
ScriptBlockLogging = new ScriptBlockLogging() { EnableScriptBlockLogging = false },
ModuleLogging = new ModuleLogging() { EnableModuleLogging = false },
ProtectedEventLogging = new ProtectedEventLogging() { EncryptionCertificate = new string[] { "Joe" } }
};
// Set the test hook to disable policy caching
originalTestHookValue = InternalTestHooks.BypassGroupPolicyCaching;
InternalTestHooks.BypassGroupPolicyCaching = true;
}
public void Dispose()
{
CleanupConfigFiles();
if (systemWideConfigBackupFile != null)
{
File.Move(systemWideConfigBackupFile, systemWideConfigFile);
}
if (currentUserConfigBackupFile != null)
{
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
}
InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
}
internal PowerShellPolicies SystemWidePolicies
{
get { return systemWidePolicies; }
}
internal PowerShellPolicies CurrentUserPolicies
{
get { return currentUserPolicies; }
}
#region Compare_Policy_Settings
internal void CompareScriptExecution(ScriptExecution a, ScriptExecution b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableScripts, b.EnableScripts);
Assert.Equal(a.ExecutionPolicy, b.ExecutionPolicy);
}
}
internal void CompareScriptBlockLogging(ScriptBlockLogging a, ScriptBlockLogging b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableScriptBlockInvocationLogging, b.EnableScriptBlockInvocationLogging);
Assert.Equal(a.EnableScriptBlockLogging, b.EnableScriptBlockLogging);
}
}
internal void CompareModuleLogging(ModuleLogging a, ModuleLogging b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableModuleLogging, b.EnableModuleLogging);
if (a.ModuleNames == null)
{
Assert.Null(b.ModuleNames);
}
else
{
Assert.Equal(a.ModuleNames.Length, b.ModuleNames.Length);
for (int i = 0; i < a.ModuleNames.Length; i++)
{
Assert.Equal(a.ModuleNames[i], b.ModuleNames[i]);
}
}
}
}
internal void CompareProtectedEventLogging(ProtectedEventLogging a, ProtectedEventLogging b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableProtectedEventLogging, b.EnableProtectedEventLogging);
if (a.EncryptionCertificate == null)
{
Assert.Null(b.EncryptionCertificate);
}
else
{
Assert.Equal(a.EncryptionCertificate.Length, b.EncryptionCertificate.Length);
for (int i = 0; i < a.EncryptionCertificate.Length; i++)
{
Assert.Equal(a.EncryptionCertificate[i], b.EncryptionCertificate[i]);
}
}
}
}
internal void CompareTranscription(Transcription a, Transcription b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableTranscripting, b.EnableTranscripting);
Assert.Equal(a.EnableInvocationHeader, b.EnableInvocationHeader);
Assert.Equal(a.OutputDirectory, b.OutputDirectory);
}
}
internal void CompareUpdatableHelp(UpdatableHelp a, UpdatableHelp b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.DefaultSourcePath, b.DefaultSourcePath);
}
}
internal void CompareConsoleSessionConfiguration(ConsoleSessionConfiguration a, ConsoleSessionConfiguration b)
{
if (a == null)
{
Assert.Null(b);
}
else
{
Assert.Equal(a.EnableConsoleSessionConfiguration, b.EnableConsoleSessionConfiguration);
Assert.Equal(a.ConsoleSessionConfigurationName, b.ConsoleSessionConfigurationName);
}
}
internal void CompareTwoPolicies(PowerShellPolicies a, PowerShellPolicies b)
{
// Compare 'ScriptExecution' settings
CompareScriptExecution(a.ScriptExecution, b.ScriptExecution);
// Compare 'ScriptBlockLogging' settings
CompareScriptBlockLogging(a.ScriptBlockLogging, b.ScriptBlockLogging);
// Compare 'ModuleLogging' settings
CompareModuleLogging(a.ModuleLogging, b.ModuleLogging);
// Compare 'ProtectedEventLogging' settings
CompareProtectedEventLogging(a.ProtectedEventLogging, b.ProtectedEventLogging);
// Compare 'Transcription' settings
CompareTranscription(a.Transcription, b.Transcription);
// Compare 'UpdatableHelp' settings
CompareUpdatableHelp(a.UpdatableHelp, b.UpdatableHelp);
// Compare 'ConsoleSessionConfiguration' settings
CompareConsoleSessionConfiguration(a.ConsoleSessionConfiguration, b.ConsoleSessionConfiguration);
}
#endregion
#region Configuration_File_Setup
public void CleanupConfigFiles()
{
if (File.Exists(systemWideConfigFile))
{
File.Delete(systemWideConfigFile);
}
if (File.Exists(currentUserConfigFile))
{
File.Delete(currentUserConfigFile);
}
}
public void SetupConfigFile1()
{
CleanupConfigFiles();
// System wide config file has all policy settings
var systemWideConfig = new { ConsolePrompting = true, PowerShellPolicies = systemWidePolicies };
using (var streamWriter = new StreamWriter(systemWideConfigFile))
{
serializer.Serialize(streamWriter, systemWideConfig);
}
// Current user config file has partial policy settings
var currentUserConfig = new { DisablePromptToUpdateHelp = false, PowerShellPolicies = currentUserPolicies };
using (var streamWriter = new StreamWriter(currentUserConfigFile))
{
serializer.Serialize(streamWriter, currentUserConfig);
}
}
public void SetupConfigFile2()
{
CleanupConfigFiles();
// System wide config file has all policy settings
var systemWideConfig = new { ConsolePrompting = true, PowerShellPolicies = systemWidePolicies };
using (var streamWriter = new StreamWriter(systemWideConfigFile))
{
serializer.Serialize(streamWriter, systemWideConfig);
}
// Current user config file is empty
CreateEmptyFile(currentUserConfigFile);
}
public void SetupConfigFile3()
{
CleanupConfigFiles();
// System wide config file is empty
CreateEmptyFile(systemWideConfigFile);
// Current user config file has partial policy settings
var currentUserConfig = new { DisablePromptToUpdateHelp = false, PowerShellPolicies = currentUserPolicies };
using (var streamWriter = new StreamWriter(currentUserConfigFile))
{
serializer.Serialize(streamWriter, currentUserConfig);
}
}
public void SetupConfigFile4()
{
CleanupConfigFiles();
// System wide config file is empty
CreateEmptyFile(systemWideConfigFile);
// Current user config file is empty
CreateEmptyFile(currentUserConfigFile);
}
private void CreateEmptyFile(string fileName)
{
File.Create(fileName).Dispose();
}
#endregion
}
public class PowerShellPolicyTests : IClassFixture<PowerShellPolicyFixture>
{
PowerShellPolicyFixture fixture;
public PowerShellPolicyTests(PowerShellPolicyFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesNotEmpty()
{
fixture.SetupConfigFile1();
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.SystemWide);
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
Assert.NotNull(sysPolicies);
Assert.NotNull(userPolicies);
fixture.CompareTwoPolicies(sysPolicies, fixture.SystemWidePolicies);
fixture.CompareTwoPolicies(userPolicies, fixture.CurrentUserPolicies);
}
[Fact]
public void PowerShellConfig_GetPowerShellPolicies_EmptyUserConfig()
{
fixture.SetupConfigFile2();
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.SystemWide);
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
Assert.NotNull(sysPolicies);
Assert.Null(userPolicies);
fixture.CompareTwoPolicies(sysPolicies, fixture.SystemWidePolicies);
}
[Fact]
public void PowerShellConfig_GetPowerShellPolicies_EmptySystemConfig()
{
fixture.SetupConfigFile3();
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.SystemWide);
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
Assert.Null(sysPolicies);
Assert.NotNull(userPolicies);
fixture.CompareTwoPolicies(userPolicies, fixture.CurrentUserPolicies);
}
[Fact]
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesEmpty()
{
fixture.SetupConfigFile4();
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.SystemWide);
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
Assert.Null(sysPolicies);
Assert.Null(userPolicies);
}
[Fact]
public void PowerShellConfig_GetPowerShellPolicies_BothConfigFilesNotExist()
{
fixture.CleanupConfigFiles();
var sysPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.SystemWide);
var userPolicies = PowerShellConfig.Instance.GetPowerShellPolicies(ConfigScope.CurrentUser);
Assert.Null(sysPolicies);
Assert.Null(userPolicies);
}
[Fact]
public void Utils_GetPolicySetting_BothConfigFilesNotEmpty()
{
fixture.SetupConfigFile1();
ScriptExecution scriptExecution;
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
ScriptBlockLogging scriptBlockLogging;
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
ModuleLogging moduleLogging;
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
ProtectedEventLogging protectedEventLogging;
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
Transcription transcription;
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
UpdatableHelp updatableHelp;
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
ConsoleSessionConfiguration consoleSessionConfiguration;
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
}
[Fact]
public void Utils_GetPolicySetting_EmptyUserConfig()
{
fixture.SetupConfigFile2();
// The CurrentUser config is empty
ScriptExecution scriptExecution;
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.SystemWidePolicies.ScriptExecution);
ScriptBlockLogging scriptBlockLogging;
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.SystemWidePolicies.ScriptBlockLogging);
ModuleLogging moduleLogging;
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.SystemWidePolicies.ModuleLogging);
ProtectedEventLogging protectedEventLogging;
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.SystemWidePolicies.ProtectedEventLogging);
Transcription transcription;
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareTranscription(transcription, fixture.SystemWidePolicies.Transcription);
UpdatableHelp updatableHelp;
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareUpdatableHelp(updatableHelp, fixture.SystemWidePolicies.UpdatableHelp);
ConsoleSessionConfiguration consoleSessionConfiguration;
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, fixture.SystemWidePolicies.ConsoleSessionConfiguration);
}
[Fact]
public void Utils_GetPolicySetting_EmptySystemConfig()
{
fixture.SetupConfigFile3();
// The SystemWide config is empty
ScriptExecution scriptExecution;
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptExecution(scriptExecution, fixture.CurrentUserPolicies.ScriptExecution);
ScriptBlockLogging scriptBlockLogging;
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, fixture.CurrentUserPolicies.ScriptBlockLogging);
ModuleLogging moduleLogging;
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareModuleLogging(moduleLogging, fixture.CurrentUserPolicies.ModuleLogging);
ProtectedEventLogging protectedEventLogging;
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, fixture.CurrentUserPolicies.ProtectedEventLogging);
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
Transcription transcription;
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareTranscription(transcription, null);
UpdatableHelp updatableHelp;
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
ConsoleSessionConfiguration consoleSessionConfiguration;
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
}
[Fact]
public void Utils_GetPolicySetting_BothConfigFilesEmpty()
{
fixture.SetupConfigFile4();
// Both config files are empty
ScriptExecution scriptExecution;
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptExecution(scriptExecution, null);
ScriptBlockLogging scriptBlockLogging;
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
ModuleLogging moduleLogging;
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareModuleLogging(moduleLogging, null);
ProtectedEventLogging protectedEventLogging;
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
Transcription transcription;
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareTranscription(transcription, null);
UpdatableHelp updatableHelp;
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
ConsoleSessionConfiguration consoleSessionConfiguration;
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
}
[Fact]
public void Utils_GetPolicySetting_BothConfigFilesNotExist()
{
fixture.CleanupConfigFiles();
// Both config files don't exist
ScriptExecution scriptExecution;
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptExecution(scriptExecution, null);
scriptExecution = Utils.GetPolicySetting<ScriptExecution>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptExecution(scriptExecution, null);
ScriptBlockLogging scriptBlockLogging;
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
scriptBlockLogging = Utils.GetPolicySetting<ScriptBlockLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareScriptBlockLogging(scriptBlockLogging, null);
ModuleLogging moduleLogging;
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareModuleLogging(moduleLogging, null);
moduleLogging = Utils.GetPolicySetting<ModuleLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareModuleLogging(moduleLogging, null);
ProtectedEventLogging protectedEventLogging;
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserOnlyConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
protectedEventLogging = Utils.GetPolicySetting<ProtectedEventLogging>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareProtectedEventLogging(protectedEventLogging, null);
// The CurrentUser config doesn't contain any settings for 'Transcription', 'UpdatableHelp' and 'ConsoleSessionConfiguration'
Transcription transcription;
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserOnlyConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareTranscription(transcription, null);
transcription = Utils.GetPolicySetting<Transcription>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareTranscription(transcription, null);
UpdatableHelp updatableHelp;
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserOnlyConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
updatableHelp = Utils.GetPolicySetting<UpdatableHelp>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareUpdatableHelp(updatableHelp, null);
ConsoleSessionConfiguration consoleSessionConfiguration;
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserOnlyConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.SystemWideThenCurrentUserConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
consoleSessionConfiguration = Utils.GetPolicySetting<ConsoleSessionConfiguration>(Utils.CurrentUserThenSystemWideConfig);
fixture.CompareConsoleSessionConfiguration(consoleSessionConfiguration, null);
}
}
}

View File

@ -2,7 +2,7 @@ using Xunit;
using System;
using System.Management.Automation;
namespace PSTests
namespace PSTests.Parallel
{
public static class PSVersionInfoTests
{

View File

@ -3,7 +3,7 @@ using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace PSTests
namespace PSTests.Parallel
{
// NOTE: do not call AddCommand("out-host") after invoking or MergeMyResults,
// otherwise Invoke will not return any objects

View File

@ -2,7 +2,7 @@ using Xunit;
using System;
using System.Management.Automation;
namespace PSTests
namespace PSTests.Parallel
{
public static class SecuritySupportTests
{

View File

@ -10,7 +10,7 @@ using System.Management.Automation.Internal.Host;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
namespace PSTests
namespace PSTests.Parallel
{
public class SessionStateTests
{

View File

@ -3,7 +3,7 @@ using System;
using System.Management.Automation;
using System.Reflection;
namespace PSTests
namespace PSTests.Parallel
{
public static class UtilsTests
{

View File

@ -325,7 +325,8 @@ function Invoke-AppVeyorTest
Write-Host -Foreground Green 'Run CoreCLR tests'
$testResultsNonAdminFile = "$pwd\TestsResultsNonAdmin.xml"
$testResultsAdminFile = "$pwd\TestsResultsAdmin.xml"
$testResultsXUnitFile = "$pwd\TestResultsXUnit.xml"
$SequentialXUnitTestResultsFile = "$pwd\SequentialXUnitTestResults.xml"
$ParallelXUnitTestResultsFile = "$pwd\ParallelXUnitTestResults.xml"
if(!(Test-Path "$env:CoreOutput\pwsh.exe"))
{
throw "CoreCLR pwsh.exe was not built"
@ -359,9 +360,10 @@ function Invoke-AppVeyorTest
Write-Host -Foreground Green 'Upload CoreCLR Admin test results'
Update-AppVeyorTestResults -resultsFile $testResultsAdminFile
Start-PSxUnit -TestResultsFile $testResultsXUnitFile
Start-PSxUnit -SequentialTestResultsFile $SequentialXUnitTestResultsFile -ParallelTestResultsFile $ParallelXUnitTestResultsFile
Write-Host -ForegroundColor Green 'Uploading PSxUnit test results'
Update-AppVeyorTestResults -resultsFile $testResultsXUnitFile
Update-AppVeyorTestResults -resultsFile $SequentialXUnitTestResultsFile
Update-AppVeyorTestResults -resultsFile $ParallelXUnitTestResultsFile
#
# Fail the build, if tests failed
@ -372,7 +374,12 @@ function Invoke-AppVeyorTest
Test-PSPesterResults -TestResultsFile $_
}
$testPassResult = Test-XUnitTestResults -TestResultsFile $testResultsXUnitFile
@(
$SequentialXUnitTestResultsFile,
$ParallelXUnitTestResultsFile
) | ForEach-Object {
Test-XUnitTestResults -TestResultsFile $_
}
Set-BuildVariable -Name TestPassed -Value True
}

View File

@ -240,10 +240,12 @@ elseif($Stage -eq 'Build')
}
try {
$testResultsXUnitFile = "$pwd/TestResultsXUnit.xml"
Start-PSxUnit -TestResultsFile $testResultsXUnitFile
$SequentialXUnitTestResultsFile = "$pwd/SequentialXUnitTestResults.xml"
$ParallelXUnitTestResultsFile = "$pwd/ParallelXUnitTestResults.xml"
Start-PSxUnit -SequentialTestResultsFile $SequentialXUnitTestResultsFile -ParallelTestResultsFile $ParallelXUnitTestResultsFile
# If there are failures, Test-XUnitTestResults throws
$testPassResult = Test-XUnitTestResults -TestResultsFile $testResultsXUnitFile
$SequentialXUnitTestResultsFile, $ParallelXUnitTestResultsFile | ForEach-Object { Test-XUnitTestResults -TestResultsFile $_ }
}
catch {
$result = "FAIL"