Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
ImportProvider.Tests.ps169 linesDownload Raw Back to Microsoft.PowerShell.Core
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe "Import PowerShell provider" -Tags "CI" {5    BeforeAll {6        $testModulePath = Join-Path $TestDrive "ReproModule"7        New-Item -Path $testModulePath -ItemType Directory > $null8 9        New-ModuleManifest -Path "$testModulePath/ReproModule.psd1" -RootModule 'testmodule.dll'10 11        $testBinaryModulePath = Join-Path $testModulePath "testmodule.dll"12        $binaryModule = @'13using System;14using System.Collections.ObjectModel;15using System.Management.Automation;16using System.Management.Automation.Provider;17 18namespace module {19    [CmdletProvider(20        "SamplePrv",21        ProviderCapabilities.ShouldProcess)]22    public class SampleProvider : ContainerCmdletProvider {23        protected override bool IsValidPath(string path) {24            return true;25        }26 27        protected override bool ItemExists(string path) {28            return path == "test.txt";29        }30 31        protected override void GetItem(string path) {32            Item resultItem;33            if (path == "test.txt") {34            resultItem = new Item { Name = "test.txt" };35            } else {36            throw new Exception("Item not found.");37            }38 39            WriteItemObject(resultItem, path, false);40        }41 42        protected override Collection<PSDriveInfo> InitializeDefaultDrives() {43            var drive = new PSDriveInfo(44            "defaultSampleDrive",45            ProviderInfo,46            "/",47            "Sample default drive",48            null);49            var result = new Collection<PSDriveInfo> {drive};50            return result;51        }52 53        private class Item {54            public string Name { get; set; }55        }56    }57}58'@59        Add-Type -OutputAssembly $testBinaryModulePath -TypeDefinition $binaryModule60 61        $pwsh = "$PSHOME\pwsh"62    }63 64    It "Import a PowerShell provider with correct name" {65        $result = & $pwsh -NoProfile -Command "Import-Module -Name $testModulePath; (Get-Item ReproModule\SamplePrv::test.txt).PSPath"66        $result | Should -BeExactly "ReproModule\SamplePrv::test.txt"67    }68}69