-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da8c579
commit af87237
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
test/PowerShellEditorServices.Test.Shared/RunspaceSynchronizer/testModule.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# | ||
# Copyright (c) Microsoft. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
# | ||
|
||
function Search-Foo { | ||
param () | ||
"success" | ||
} | ||
|
||
Set-Alias sfoo Search-Foo | ||
|
||
Export-ModuleMember -Function Search-Foo -Alias sfoo |
65 changes: 65 additions & 0 deletions
65
test/PowerShellEditorServices.Test/Language/RunspaceSynchronizerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.ObjectModel; | ||
using Xunit; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Test.Language | ||
{ | ||
using System.Management.Automation; | ||
|
||
public class RunspaceSynchronizerTests | ||
{ | ||
[Trait("Category", "RunspaceSynchronizer")] | ||
[Theory] | ||
// variable test | ||
[InlineData("$foo = 'foo'", "$foo", "foo")] | ||
// module functions test | ||
[InlineData("Import-Module ../../../../PowerShellEditorServices.Test.Shared/RunspaceSynchronizer/testModule.psm1", "Search-Foo", "success")] | ||
// module aliases test | ||
[InlineData("Import-Module ../../../../PowerShellEditorServices.Test.Shared/RunspaceSynchronizer/testModule.psm1", "(Get-Alias sfoo).Definition", "Search-Foo")] | ||
public void TestRunspaceSynchronizerSyncsData(string sourceScript, string targetScript, object expected) | ||
{ | ||
using (PowerShell pwshSource = PowerShell.Create()) | ||
using (PowerShell pwshTarget = PowerShell.Create()) | ||
{ | ||
RunspaceSynchronizer.InitializeRunspaces(pwshSource.Runspace, pwshTarget.Runspace); | ||
AssertExpectedIsSynced(pwshSource, pwshTarget, sourceScript, targetScript, expected); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TestRunspaceSynchronizerOverwritesTypes() | ||
{ | ||
using (PowerShell pwshSource = PowerShell.Create()) | ||
using (PowerShell pwshTarget = PowerShell.Create()) | ||
{ | ||
RunspaceSynchronizer.InitializeRunspaces(pwshSource.Runspace, pwshTarget.Runspace); | ||
AssertExpectedIsSynced(pwshSource, pwshTarget, "$foo = 444", "$foo.GetType().Name", "Int32"); | ||
AssertExpectedIsSynced(pwshSource, pwshTarget, "$foo = 'change to string'", "$foo.GetType().Name", "String"); | ||
} | ||
} | ||
|
||
private static void AssertExpectedIsSynced( | ||
PowerShell pwshSource, | ||
PowerShell pwshTarget, | ||
string sourceScript, | ||
string targetScript, | ||
object expected) | ||
{ | ||
pwshSource.AddScript(sourceScript).Invoke(); | ||
RunspaceSynchronizer.Activate(); | ||
|
||
// We need to allow the event some time to fire. | ||
System.Threading.Thread.Sleep(1000); | ||
|
||
var results = pwshTarget.AddScript(targetScript).Invoke<PSObject>(); | ||
|
||
Assert.Single(results); | ||
Assert.NotNull(results[0].BaseObject); | ||
Assert.Equal(expected, results[0].BaseObject); | ||
} | ||
} | ||
} |