Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
test_NamedPipe.cs59 linesDownload Raw Back to csharp
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.IO;6using System.Management.Automation;7using System.Management.Automation.Remoting;8using Xunit;9 10namespace PSTests.Parallel11{12    public class NamedPipeTests13    {14        [Fact]15        public void TestCustomPipeNameCreation()16        {17            string pipeNameForFirstCall = Path.GetRandomFileName();18            string pipeNameForSecondCall = Path.GetRandomFileName();19 20            RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeNameForFirstCall);21            Assert.True(File.Exists(GetPipePath(pipeNameForFirstCall)));22 23            // The second call to this method would override the first named pipe.24            RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeNameForSecondCall);25            Assert.True(File.Exists(GetPipePath(pipeNameForSecondCall)));26 27            // Previous pipe should have been cleaned up.28            Assert.False(File.Exists(GetPipePath(pipeNameForFirstCall)));29        }30 31        [Fact]32        public void TestCustomPipeNameCreationTooLongOnNonWindows()33        {34            const string longPipeName = "DoggoipsumwaggywagssmolborkingdoggowithalongsnootforpatsdoingmeafrightenporgoYapperporgolongwatershoobcloudsbigolpupperlengthboy";35 36            if (!Platform.IsWindows)37            {38                Assert.Throws<InvalidOperationException>(() =>39                    RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(longPipeName));40            }41            else42            {43                RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(longPipeName);44                Assert.True(File.Exists(GetPipePath(longPipeName)));45            }46        }47 48        private static string GetPipePath(string pipeName)49        {50            if (Platform.IsWindows)51            {52                return $@"\\.\pipe\{pipeName}";53            }54 55            return $@"{Path.GetTempPath()}CoreFxPipe_{pipeName}";56        }57    }58}59