Fix style issues in xUnit tests (#8465)

This commit is contained in:
Ilya
2018-12-18 21:11:21 +05:00
committed by GitHub
parent 2b4199a78a
commit c857392c34
12 changed files with 82 additions and 51 deletions
+10 -3
View File
@@ -19,8 +19,10 @@ namespace TestOrder.TestCaseOrdering
{
int priority = 0;
foreach (IAttributeInfo attr in testCase.TestMethod.Method.GetCustomAttributes((typeof(TestPriorityAttribute).AssemblyQualifiedName)))
foreach (IAttributeInfo attr in testCase.TestMethod.Method.GetCustomAttributes(typeof(TestPriorityAttribute).AssemblyQualifiedName))
{
priority = attr.GetNamedArgument<int>("Priority");
}
GetOrCreate(sortedMethods, priority).Add(testCase);
}
@@ -29,15 +31,20 @@ namespace TestOrder.TestCaseOrdering
{
list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name));
foreach (TTestCase testCase in list)
{
yield return testCase;
}
}
}
static TValue GetOrCreate<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key) where TValue : new()
private static TValue GetOrCreate<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key) where TValue : new()
{
TValue result;
if (dictionary.TryGetValue(key, out result)) return result;
if (dictionary.TryGetValue(key, out result))
{
return result;
}
result = new TValue();
dictionary[key] = result;
+2 -1
View File
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation.Language;
using Xunit;
namespace PSTests.Parallel
{
+3 -2
View File
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Management.Automation;
using Xunit;
namespace PSTests.Parallel
{
+2 -1
View File
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using Xunit;
namespace PSTests.Parallel
{
+38 -30
View File
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -13,23 +13,30 @@ using System.Management.Automation.Internal;
using System.Management.Automation.Internal.Host;
using System.Management.Automation.Provider;
using System.Management.Automation.Runspaces;
using System.Reflection;
using Microsoft.PowerShell;
using Microsoft.PowerShell.Commands;
using System.Reflection;
using Xunit;
namespace PSTests.Parallel
{
public class FileSystemProviderTests: IDisposable
public class FileSystemProviderTests : IDisposable
{
private string testPath;
private string testContent;
public FileSystemProviderTests()
{
testPath = Path.GetTempFileName();
testContent = "test content!";
if(File.Exists(testPath)) File.Delete(testPath);
File.AppendAllText(testPath,testContent);
if (File.Exists(testPath))
{
File.Delete(testPath);
}
File.AppendAllText(testPath, testContent);
}
void IDisposable.Dispose()
{
File.Delete(testPath);
@@ -38,18 +45,19 @@ namespace PSTests.Parallel
private ExecutionContext GetExecutionContext()
{
CultureInfo currentCulture = CultureInfo.CurrentCulture;
PSHost hostInterface = new DefaultHost(currentCulture,currentCulture);
PSHost hostInterface = new DefaultHost(currentCulture, currentCulture);
InitialSessionState iss = InitialSessionState.CreateDefault2();
AutomationEngine engine = new AutomationEngine(hostInterface, iss);
ExecutionContext executionContext = new ExecutionContext(engine, hostInterface, iss);
return executionContext;
}
private ProviderInfo GetProvider()
{
ExecutionContext executionContext = GetExecutionContext();
SessionStateInternal sessionState = new SessionStateInternal(executionContext);
SessionStateProviderEntry providerEntry = new SessionStateProviderEntry("FileSystem",typeof(FileSystemProvider), null);
SessionStateProviderEntry providerEntry = new SessionStateProviderEntry("FileSystem", typeof(FileSystemProvider), null);
sessionState.AddSessionStateEntry(providerEntry);
ProviderInfo matchingProvider = sessionState.ProviderList.ToList()[0];
@@ -59,7 +67,7 @@ namespace PSTests.Parallel
[Fact]
public void TestCreateJunctionFails()
{
if(!Platform.IsWindows)
if (!Platform.IsWindows)
{
Assert.False(InternalSymbolicLinkLinkCodeMethods.CreateJunction(string.Empty, string.Empty));
}
@@ -73,20 +81,20 @@ namespace PSTests.Parallel
public void TestGetHelpMaml()
{
FileSystemProvider fileSystemProvider = new FileSystemProvider();
Assert.Equal(fileSystemProvider.GetHelpMaml(String.Empty,String.Empty),String.Empty);
Assert.Equal(fileSystemProvider.GetHelpMaml("helpItemName",String.Empty),String.Empty);
Assert.Equal(fileSystemProvider.GetHelpMaml(String.Empty,"path"),String.Empty);
Assert.Equal(fileSystemProvider.GetHelpMaml(string.Empty, string.Empty), string.Empty);
Assert.Equal(fileSystemProvider.GetHelpMaml("helpItemName", string.Empty), string.Empty);
Assert.Equal(fileSystemProvider.GetHelpMaml(string.Empty, "path"), string.Empty);
}
[Fact]
public void TestMode()
{
Assert.Equal(FileSystemProvider.Mode(null),String.Empty);
Assert.Equal(FileSystemProvider.Mode(null), string.Empty);
FileSystemInfo directoryObject = null;
FileSystemInfo fileObject = null;
FileSystemInfo executableObject = null;
if(!Platform.IsWindows)
if (!Platform.IsWindows)
{
directoryObject = new DirectoryInfo(@"/");
fileObject = new FileInfo(@"/etc/hosts");
@@ -99,9 +107,9 @@ namespace PSTests.Parallel
executableObject = new FileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
Assert.Equal("d-----", FileSystemProvider.Mode(PSObject.AsPSObject(directoryObject)).Replace("r","-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(fileObject)).Replace("r","-").Replace("a","-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(executableObject)).Replace("r","-").Replace("a","-"));
Assert.Equal("d-----", FileSystemProvider.Mode(PSObject.AsPSObject(directoryObject)).Replace("r", "-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(fileObject)).Replace("r", "-").Replace("a", "-"));
Assert.Equal("------", FileSystemProvider.Mode(PSObject.AsPSObject(executableObject)).Replace("r", "-").Replace("a", "-"));
}
[Fact]
@@ -111,15 +119,15 @@ namespace PSTests.Parallel
ProviderInfo providerInfoToSet = GetProvider();
fileSystemProvider.SetProviderInformation(providerInfoToSet);
fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
PSObject pso=new PSObject();
pso.AddOrSetProperty("IsReadOnly",false);
PSObject pso = new PSObject();
pso.AddOrSetProperty("IsReadOnly", false);
fileSystemProvider.SetProperty(testPath, pso);
fileSystemProvider.GetProperty(testPath, new Collection<string>(){"IsReadOnly"});
fileSystemProvider.GetProperty(testPath, new Collection<string>(){ "IsReadOnly" });
FileInfo fileSystemObject1 = new FileInfo(testPath);
PSObject psobject1=PSObject.AsPSObject(fileSystemObject1);
foreach(PSPropertyInfo property in psobject1.Properties)
PSObject psobject1 = PSObject.AsPSObject(fileSystemObject1);
foreach (PSPropertyInfo property in psobject1.Properties)
{
if(property.Name == "IsReadOnly")
if (property.Name == "IsReadOnly")
{
Assert.False((bool)property.Value);
}
@@ -133,12 +141,12 @@ namespace PSTests.Parallel
ProviderInfo providerInfoToSet = GetProvider();
fileSystemProvider.SetProviderInformation(providerInfoToSet);
fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
fileSystemProvider.GetProperty(testPath, new Collection<string>(){"Name"});
fileSystemProvider.GetProperty(testPath, new Collection<string>(){ "Name" });
FileInfo fileSystemObject1 = new FileInfo(testPath);
PSObject psobject1=PSObject.AsPSObject(fileSystemObject1);
foreach(PSPropertyInfo property in psobject1.Properties)
PSObject psobject1 = PSObject.AsPSObject(fileSystemObject1);
foreach (PSPropertyInfo property in psobject1.Properties)
{
if(property.Name == "FullName")
if (property.Name == "FullName")
{
Assert.Equal(testPath, property.Value);
}
@@ -152,7 +160,7 @@ namespace PSTests.Parallel
ProviderInfo providerInfoToSet = GetProvider();
fileSystemProvider.SetProviderInformation(providerInfoToSet);
fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
fileSystemProvider.ClearProperty(testPath, new Collection<string>(){"Attributes"});
fileSystemProvider.ClearProperty(testPath, new Collection<string>(){ "Attributes" });
}
[Fact]
@@ -164,7 +172,7 @@ namespace PSTests.Parallel
fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
IContentReader contentReader = fileSystemProvider.GetContentReader(testPath);
Assert.Equal(contentReader.Read(1)[0],testContent);
Assert.Equal(contentReader.Read(1)[0], testContent);
contentReader.Close();
}
@@ -177,9 +185,9 @@ namespace PSTests.Parallel
fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
IContentWriter contentWriter = fileSystemProvider.GetContentWriter(testPath);
contentWriter.Write(new List<string>(){"contentWriterTestContent"});
contentWriter.Write(new List<string>(){ "contentWriterTestContent" });
contentWriter.Close();
Assert.Equal(File.ReadAllText(testPath), testContent+@"contentWriterTestContent"+ System.Environment.NewLine);
Assert.Equal(File.ReadAllText(testPath), testContent + @"contentWriterTestContent" + System.Environment.NewLine);
}
[Fact]
+2 -1
View File
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using Xunit;
namespace PSTests.Parallel
{
+11 -5
View File
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.IO;
using System.Management.Automation;
@@ -9,13 +9,14 @@ using System.Management.Automation.Internal;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
namespace PSTests.Sequential
{
[TestCaseOrderer("TestOrder.TestCaseOrdering.PriorityOrderer", "powershell-tests")]
public class PowerShellPolicyFixture : IDisposable
{
private const string configFileName = "powershell.config.json";
private const string ConfigFileName = "powershell.config.json";
private readonly string systemWideConfigFile;
private readonly string currentUserConfigFile;
@@ -43,14 +44,15 @@ namespace PSTests.Sequential
Directory.CreateDirectory(currentUserConfigDirectory);
}
systemWideConfigFile = Path.Combine(systemWideConfigDirectory, configFileName);
currentUserConfigFile = Path.Combine(currentUserConfigDirectory, configFileName);
systemWideConfigFile = Path.Combine(systemWideConfigDirectory, ConfigFileName);
currentUserConfigFile = Path.Combine(currentUserConfigDirectory, ConfigFileName);
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());
@@ -102,6 +104,7 @@ namespace PSTests.Sequential
{
File.Move(currentUserConfigBackupFile, currentUserConfigFile);
}
InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
}
@@ -264,6 +267,7 @@ namespace PSTests.Sequential
{
File.Delete(systemWideConfigFile);
}
if (File.Exists(currentUserConfigFile))
{
File.Delete(currentUserConfigFile);
@@ -322,8 +326,10 @@ namespace PSTests.Sequential
public void SetupConfigFile4()
{
CleanupConfigFiles();
// System wide config file is empty
CreateEmptyFile(systemWideConfigFile);
// Current user config file is empty
CreateEmptyFile(currentUserConfigFile);
}
@@ -338,7 +344,7 @@ namespace PSTests.Sequential
public class PowerShellPolicyTests : IClassFixture<PowerShellPolicyFixture>
{
PowerShellPolicyFixture fixture;
private PowerShellPolicyFixture fixture;
public PowerShellPolicyTests(PowerShellPolicyFixture fixture)
{
+2 -1
View File
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using Xunit;
namespace PSTests.Parallel
{
+5 -3
View File
@@ -1,19 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Xunit;
namespace PSTests.Parallel
{
// NOTE: do not call AddCommand("out-host") after invoking or MergeMyResults,
// otherwise Invoke will not return any objects
public class RunspaceTests
{
private static int count = 1;
private static string script = String.Format($"get-command get-command");
private static string script = string.Format($"get-command get-command");
[Fact]
public void TestRunspaceWithPipeline()
@@ -30,6 +30,7 @@ namespace PSTests.Parallel
++objCount;
Assert.NotNull(result);
}
Assert.Equal(count, objCount);
}
@@ -56,6 +57,7 @@ namespace PSTests.Parallel
++objCount;
Assert.NotNull(result);
}
Assert.Equal(count, objCount);
}
+2 -1
View File
@@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using Xunit;
namespace PSTests.Parallel
{
+3 -2
View File
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Collections;
using System.Collections.ObjectModel;
@@ -11,6 +11,7 @@ using System.Management.Automation.Internal;
using System.Management.Automation.Internal.Host;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
using Xunit;
namespace PSTests.Parallel
{
@@ -21,7 +22,7 @@ namespace PSTests.Parallel
{
Skip.IfNot(Platform.IsWindows);
CultureInfo currentCulture = CultureInfo.CurrentCulture;
PSHost hostInterface = new DefaultHost(currentCulture,currentCulture);
PSHost hostInterface = new DefaultHost(currentCulture, currentCulture);
InitialSessionState iss = InitialSessionState.CreateDefault2();
AutomationEngine engine = new AutomationEngine(hostInterface, iss);
ExecutionContext executionContext = new ExecutionContext(engine, hostInterface, iss);
+2 -1
View File
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Xunit;
using System;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Reflection;
using Xunit;
namespace PSTests.Parallel
{