Ejemplo n.º 1
0
        public async Task GetCorrectProfilePaths()
        {
            using var kernel = new PowerShellKernel().UseProfiles();

            // Set variables we will retrieve later.
            await kernel.SubmitCodeAsync("$currentUserCurrentHost = $PROFILE.CurrentUserCurrentHost");

            await kernel.SubmitCodeAsync("$allUsersCurrentHost = $PROFILE.AllUsersCurrentHost");

            kernel.TryGetVariable("currentUserCurrentHost", out object profileObj).Should().BeTrue();
            profileObj.Should().BeOfType <string>();
            string currentUserCurrentHost = profileObj.As <string>();

            // Get $PROFILE default.
            kernel.TryGetVariable("PROFILE", out profileObj).Should().BeTrue();
            profileObj.Should().BeOfType <string>();
            string profileDefault = profileObj.As <string>();

            // Check that $PROFILE is not null or empty and it is the same as
            // $PROFILE.CurrentUserCurrentHost
            profileDefault.Should().NotBeNullOrEmpty();
            profileDefault.Should().Be(currentUserCurrentHost);

            kernel.TryGetVariable("allUsersCurrentHost", out profileObj).Should().BeTrue();
            profileObj.Should().BeOfType <string>();
            string allUsersCurrentHost = profileObj.As <string>();

            // Check that $PROFILE.AllUsersCurrentHost is what we expect it is:
            // $PSHOME + Microsoft.dotnet-interactive_profile.ps1
            allUsersCurrentHost.Should().Be(_allUsersCurrentHostProfilePath);
        }
Ejemplo n.º 2
0
        public async Task TryGetVariable_unwraps_PowerShell_object(string code, Type expectedType)
        {
            using var kernel = new PowerShellKernel();

            await kernel.SubmitCodeAsync(code);

            kernel.TryGetVariable("x", out object fi).Should().BeTrue();

            fi.Should().BeOfType(expectedType);
        }
Ejemplo n.º 3
0
        public async Task VerifyAllUsersProfileRuns()
        {
            var randomVariableName = Path.GetRandomFileName().Split('.')[0];

            File.WriteAllText(_allUsersCurrentHostProfilePath, $"$global:{randomVariableName} = $true");

            try
            {
                using var kernel = new PowerShellKernel().UseProfiles();

                // trigger first time setup.
                await kernel.SubmitCodeAsync("Get-Date");

                kernel.TryGetVariable(randomVariableName, out object profileObj).Should().BeTrue();

                profileObj.Should().BeOfType <bool>();
                profileObj.As <bool>().Should().BeTrue();
            }
            finally
            {
                File.Delete(_allUsersCurrentHostProfilePath);
            }
        }