-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Sources/Kysect.PowerShellRunner.Abstractions/Cmdlets/IPowerShellCmdletExecutor.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,13 @@ | ||
using Kysect.PowerShellRunner.Abstractions.Objects; | ||
using Kysect.PowerShellRunner.Abstractions.Variables; | ||
|
||
namespace Kysect.PowerShellRunner.Abstractions.Cmdlets; | ||
|
||
public interface IPowerShellCmdletExecutor | ||
{ | ||
IReadOnlyCollection<IPowerShellObject> Execute(IPowerShellCmdlet cmdlet); | ||
PowerShellVariable<IPowerShellObject> InitializeVariable(string variableName, IPowerShellCmdlet cmdlet); | ||
|
||
IReadOnlyCollection<T> Execute<T>(IPowerShellCmdlet<T> cmdlet) where T : notnull; | ||
PowerShellVariable<T> InitializeVariable<T>(string variableName, IPowerShellCmdlet<T> cmdlet) where T : notnull; | ||
} |
8 changes: 8 additions & 0 deletions
8
Sources/Kysect.PowerShellRunner.Abstractions/Cmdlets/IPowerShellObjectMapper.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,8 @@ | ||
using Kysect.PowerShellRunner.Abstractions.Objects; | ||
|
||
namespace Kysect.PowerShellRunner.Abstractions.Cmdlets; | ||
|
||
public interface IPowerShellObjectMapper | ||
{ | ||
T Map<T>(IPowerShellObject powerShellObject) where T : notnull; | ||
} |
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
27 changes: 0 additions & 27 deletions
27
Sources/Kysect.PowerShellRunner.Tests/PowerShellAccessorCmdletExecutionContextTests.cs
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
Sources/Kysect.PowerShellRunner.Tests/PowerShellCmdletExecutorTests.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,27 @@ | ||
using FluentAssertions; | ||
using Kysect.PowerShellRunner.Abstractions.Variables; | ||
using Kysect.PowerShellRunner.Cmdlets; | ||
using Kysect.PowerShellRunner.CustomCmdlets; | ||
using Kysect.PowerShellRunner.Mapping; | ||
using Kysect.PowerShellRunner.Tests.Mocks; | ||
using NUnit.Framework; | ||
|
||
namespace Kysect.PowerShellRunner.Tests; | ||
|
||
public class PowerShellCmdletExecutorTests | ||
{ | ||
[Test] | ||
public void ExecuteAndSetTo_NonGenericImplementation_FinishWithoutError() | ||
{ | ||
string expectedResult = @"C:\\Folder"; | ||
|
||
using var testPowerShellAccessor = new FakePowerShellAccessor(); | ||
var powerShellCmdletExecutor = new PowerShellCmdletExecutor(testPowerShellAccessor, PowerShellObjectMapper.Instance); | ||
testPowerShellAccessor.SetSuccessResult(new GetLocationCmdletWrapperResult(expectedResult)); | ||
|
||
PowerShellVariable<GetLocationCmdletWrapperResult> result = powerShellCmdletExecutor.InitializeVariable("$result", new GetLocationCmdlet()); | ||
|
||
GetLocationCmdletWrapperResult resultObject = result.Values.Single(); | ||
resultObject.Path.Should().NotBeNull(); | ||
} | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
Sources/Kysect.PowerShellRunner/Cmdlets/PowerShellCmdletExecutor.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,43 @@ | ||
using Kysect.PowerShellRunner.Abstractions.Accessors; | ||
using Kysect.PowerShellRunner.Abstractions.Cmdlets; | ||
using Kysect.PowerShellRunner.Abstractions.Objects; | ||
using Kysect.PowerShellRunner.Abstractions.Queries; | ||
using Kysect.PowerShellRunner.Abstractions.Variables; | ||
using Kysect.PowerShellRunner.Executions; | ||
using Kysect.PowerShellRunner.QueryBuilding; | ||
|
||
namespace Kysect.PowerShellRunner.Cmdlets; | ||
|
||
public class PowerShellCmdletExecutor(IPowerShellAccessor accessor, IPowerShellObjectMapper powerShellObjectMapper) | ||
: IPowerShellCmdletExecutor | ||
{ | ||
public IReadOnlyCollection<IPowerShellObject> Execute(IPowerShellCmdlet cmdlet) | ||
{ | ||
PowerShellQuery powerShellQuery = cmdlet.BuildFromCmdlet(); | ||
|
||
return accessor.ExecuteAndGet(powerShellQuery).ToList(); | ||
} | ||
|
||
public PowerShellVariable<IPowerShellObject> InitializeVariable(string variableName, IPowerShellCmdlet cmdlet) | ||
{ | ||
var powerShellVariable = new PowerShellVariable(variableName); | ||
PowerShellQuery powerShellQuery = cmdlet.BuildFromCmdlet(); | ||
return new PowerShellVariableInitializer(accessor, powerShellVariable, powerShellObjectMapper).With(powerShellQuery); | ||
} | ||
|
||
public IReadOnlyCollection<T> Execute<T>(IPowerShellCmdlet<T> cmdlet) where T : notnull | ||
{ | ||
PowerShellQuery powerShellQuery = cmdlet.BuildFromCmdlet(); | ||
|
||
return accessor.ExecuteAndGet(powerShellQuery) | ||
.Select(powerShellObjectMapper.Map<T>) | ||
.ToList(); | ||
} | ||
|
||
public PowerShellVariable<T> InitializeVariable<T>(string variableName, IPowerShellCmdlet<T> cmdlet) where T : notnull | ||
{ | ||
var powerShellVariable = new PowerShellVariable(variableName); | ||
PowerShellQuery powerShellQuery = cmdlet.BuildFromCmdlet(); | ||
return new PowerShellVariableInitializer(accessor, powerShellVariable, powerShellObjectMapper).With<T>(powerShellQuery); | ||
} | ||
} |
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
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
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
3 changes: 2 additions & 1 deletion
3
Sources/Kysect.PowerShellRunner/Mapping/PowerShellObjectMapper.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