mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge branch 'master' of https://github.com/PowerShell/PowerShell into PesterTest_Temp
This commit is contained in:
commit
0802c32562
45 files changed
+3023
-18151
No files matched your search
@@ -1,17 +1,116 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Host;
|
||||
using System.Management.Automation.Internal;
|
||||
using System.Management.Automation.Internal.Host;
|
||||
using System.Management.Automation.Provider;
|
||||
using System.Management.Automation.Runspaces;
|
||||
using Microsoft.PowerShell;
|
||||
using Microsoft.PowerShell.Commands;
|
||||
using Microsoft.PowerShell.Linux.Host;
|
||||
|
||||
namespace PSTests
|
||||
{
|
||||
[Collection("AssemblyLoadContext")]
|
||||
public static class FileSystemProviderTests
|
||||
{
|
||||
private static ProviderInfo GetProvider()
|
||||
{
|
||||
CultureInfo currentCulture = CultureInfo.CurrentCulture;
|
||||
PSHost hostInterface = new DefaultHost(currentCulture,currentCulture);
|
||||
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
|
||||
InitialSessionState iss = InitialSessionState.CreateDefault2();
|
||||
|
||||
AutomationEngine engine = new AutomationEngine(hostInterface, runspaceConfiguration, iss);
|
||||
ExecutionContext executionContext = new ExecutionContext(engine, hostInterface, iss);
|
||||
SessionStateInternal sessionState = new SessionStateInternal(executionContext);
|
||||
|
||||
SessionStateProviderEntry providerEntry = new SessionStateProviderEntry("FileSystem",typeof(FileSystemProvider), null);
|
||||
sessionState.AddSessionStateEntry(providerEntry);
|
||||
ProviderInfo matchingProvider = sessionState.ProviderList.ToList()[0];
|
||||
|
||||
return matchingProvider;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCreateJunctionFails()
|
||||
{
|
||||
Assert.False(InternalSymbolicLinkLinkCodeMethods.CreateJunction("",""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static 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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestMode()
|
||||
{
|
||||
Assert.Equal(FileSystemProvider.Mode(null),String.Empty);
|
||||
FileSystemInfo fileSystemObject = new DirectoryInfo(@"/");
|
||||
Assert.NotEqual(FileSystemProvider.Mode(PSObject.AsPSObject(fileSystemObject)),String.Empty);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestGetProperty()
|
||||
{
|
||||
string path = @"/filesystemobject1";
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
ProviderInfo providerInfoToSet = GetProvider();
|
||||
fileSystemProvider.SetProviderInformation(providerInfoToSet);
|
||||
FileInfo fileSystemObject1 = new FileInfo(path);
|
||||
fileSystemProvider.SetProperty(path, PSObject.AsPSObject(fileSystemObject1));
|
||||
fileSystemProvider.GetProperty(path, new Collection<string>(){"Attributes"});
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestSetProperty()
|
||||
{
|
||||
string path = @"/filesystemobject1";
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
ProviderInfo providerInfoToSet = GetProvider();
|
||||
fileSystemProvider.SetProviderInformation(providerInfoToSet);
|
||||
FileInfo fileSystemObject1 = new FileInfo(path);
|
||||
fileSystemProvider.SetProperty(@"/root", PSObject.AsPSObject(fileSystemObject1));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestClearProperty()
|
||||
{
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
fileSystemProvider.ClearProperty(@"/test", new Collection<string>(){"Attributes"});
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestGetContentReader()
|
||||
{
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
IContentReader contentReader = fileSystemProvider.GetContentReader(@"/test");
|
||||
Assert.NotNull(contentReader);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestGetContentWriter()
|
||||
{
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
IContentWriter contentWriter = fileSystemProvider.GetContentWriter(@"/test");
|
||||
Assert.NotNull(contentWriter);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Need mock")]
|
||||
public static void TestClearContent()
|
||||
{
|
||||
FileSystemProvider fileSystemProvider = new FileSystemProvider();
|
||||
fileSystemProvider.ClearContent(@"/test");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
Describe "ComparisonOperator" {
|
||||
It "Should be $true for 1 -lt 2" {
|
||||
1 -lt 2 | Should Be $true
|
||||
}
|
||||
It "Should be $false for 1 -gt 2" {
|
||||
1 -gt 2 | Should Be $false
|
||||
}
|
||||
It "Should be $true for 1 -le 2" {
|
||||
1 -le 2 | Should Be $true
|
||||
}
|
||||
It "Should be $true for 1 -le 1" {
|
||||
1 -le 1 | Should Be $true
|
||||
}
|
||||
It "Should be $false for 1 -ge 2" {
|
||||
1 -ge 2 | Should Be $false
|
||||
}
|
||||
It "Should be $true for 1 -ge 1" {
|
||||
1 -ge 1 | Should Be $true
|
||||
}
|
||||
It "Should be $true for 1 -eq 1" {
|
||||
1 -eq 1 | Should Be $true
|
||||
}
|
||||
It "Should be $true for 'abc' -ceq 'abc' and $false for 'abc' -ceq 'Abc'" {
|
||||
'abc' -ceq 'abc' | Should Be $true
|
||||
'abc' -ceq 'Abc' | Should Be $false
|
||||
}
|
||||
It "Should be $true for 1 -ne 2" {
|
||||
1 -ne 2 | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be $true for 1 -and 1, $false for 1 -and 0, $false for 0 -and 0" {
|
||||
1 -and 1 | Should Be $true
|
||||
1 -and 0 | Should Be $false
|
||||
0 -and 0 | Should Be $false
|
||||
}
|
||||
It "Should be $true for 1 -or 1, $true for 1 -or 0, $false for 0 -or 0" {
|
||||
1 -or 1 | Should Be $true
|
||||
1 -or 0 | Should Be $true
|
||||
0 -or 0 | Should Be $false
|
||||
}
|
||||
It "Should be $false for -not 1, $true for -not 0" {
|
||||
-not 1 | Should Be $false
|
||||
-not 0 | Should Be $true
|
||||
}
|
||||
It "Should be $false for !1, $true for !0" {
|
||||
!1 | Should Be $false
|
||||
!0 | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be $true for 'Hello','world' -contains 'Hello'" {
|
||||
$arr= 'Hello','world'
|
||||
$arr -contains 'Hello' | Should Be $true
|
||||
}
|
||||
It "Should be $false for 'Hello','world' -ccontains 'hello' and $true for 'Hello','world' -ccontains 'Hello'" {
|
||||
$arr= 'Hello','world'
|
||||
$arr -ccontains 'hello' | Should Be $false
|
||||
$arr -ccontains 'Hello' | Should Be $true
|
||||
}
|
||||
It "Should be $true for 'Hello world' -match 'Hello*'" {
|
||||
"Hello world" -match "Hello*" | Should Be $true
|
||||
}
|
||||
It "Should be $true for 'Hello world' -like 'Hello*'" {
|
||||
"Hello world" -like "Hello*" | Should Be $true
|
||||
}
|
||||
It "Should be $false for 'Hello world' -notmatch 'Hello*'" {
|
||||
"Hello world" -notmatch "Hello*" | Should Be $false
|
||||
}
|
||||
It "Should be $false for 'Hello world' -notlike 'Hello*'" {
|
||||
"Hello world" -notlike "Hello*" | Should Be $false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
Describe ".NET class interoperability" {
|
||||
It "Should access types in System.Console" {
|
||||
[System.Console]::TreatControlCAsInput | Should Be $false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
Describe "NativeLinuxCommands" {
|
||||
It "Should return a type of System.Object for hostname cmdlet" {
|
||||
(hostname).GetType().BaseType | Should Be 'System.Object'
|
||||
(hostname).GetType().Name | Should Be String
|
||||
}
|
||||
|
||||
It "Should have not empty Name flags set for ps object" {
|
||||
ps | foreach-object { $_.ProcessName | Should Not BeNullOrEmpty }
|
||||
}
|
||||
|
||||
It "Should find Application grep" -Skip:$IsWindows {
|
||||
(get-command grep).CommandType | Should Be Application
|
||||
}
|
||||
|
||||
It "Should pipe to grep and get result" -Skip:$IsWindows {
|
||||
"hello world" | grep hello | Should Be "hello world"
|
||||
}
|
||||
|
||||
It "Should find Application touch" -Skip:$IsWindows {
|
||||
(get-command touch).CommandType | Should Be Application
|
||||
}
|
||||
|
||||
It "Should find Alias ls" -Skip:$IsWindows {
|
||||
(get-command ls).CommandType | Should Be Alias
|
||||
}
|
||||
|
||||
It "Should find Function mkdir" -Skip:$IsWindows {
|
||||
(get-command mkdir).CommandType | Should Be Function
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user