-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TechnicMotor TestScript (on master) (#168)
- Add TechnicMotorScript - Add DiscoverAsync with type parameter - Add Verification based on Model #161 non-breaking
- Loading branch information
Showing
8 changed files
with
389 additions
and
7 deletions.
There are no files selected for viewing
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
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,11 @@ | ||
using System.Threading.Tasks; | ||
using SharpBrick.PoweredUp.Deployment; | ||
|
||
namespace SharpBrick.PoweredUp.TestScript | ||
{ | ||
public interface ITestScript | ||
{ | ||
void DefineDeploymentModel(DeploymentModelBuilder builder); | ||
Task ExecuteScriptAsync(Hub hub, TestScriptExecutionContext context); | ||
} | ||
} |
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,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using SharpBrick.PoweredUp.Deployment; | ||
using SharpBrick.PoweredUp.Hubs; | ||
|
||
namespace SharpBrick.PoweredUp.TestScript | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
var serviceProvider = new ServiceCollection() | ||
.AddLogging(builder => | ||
{ | ||
builder.AddConsole(); | ||
}) | ||
.AddPoweredUp() | ||
.AddWinRTBluetooth() // using WinRT Bluetooth on Windows (separate NuGet SharpBrick.PoweredUp.WinRT) | ||
.BuildServiceProvider(); | ||
|
||
var host = serviceProvider.GetService<PoweredUpHost>(); | ||
|
||
IEnumerable<ITestScript> scripts = new ITestScript[] { | ||
new TechnicMotorTestScript<TechnicLargeLinearMotor>(), | ||
}; | ||
|
||
var context = new TestScriptExecutionContext(serviceProvider.GetService<ILogger<TestScriptExecutionContext>>()); | ||
|
||
foreach (var script in scripts) | ||
{ | ||
// Test Script | ||
context.Log.LogInformation($"Execute Script {script.GetType().Name}"); | ||
|
||
// build deployment model | ||
var model = BbuildDeploymentModel(script); | ||
PrintModel(context, model); | ||
|
||
// Accept to execute Test Script | ||
var executeTest = await context.ConfirmAsync("> Confirm to execute Test Script"); | ||
|
||
if (executeTest) | ||
{ | ||
context.Log.LogInformation("> Discovering & Connecting Hub"); | ||
var hubType = HubFactory.GetTypeFromSystemType(model.Hubs[0].HubType ?? throw new InvalidOperationException("Specify the hub type in the test script.")); | ||
using var hub = await host.DiscoverAsync(hubType); | ||
await hub.ConnectAsync(); | ||
|
||
context.Log.LogInformation("> Verifying Deployment Model (fix it if necessary)"); | ||
await hub.VerifyDeploymentModelAsync(model); | ||
|
||
context.Log.LogInformation("> Start Test Script"); | ||
await script.ExecuteScriptAsync(hub, context); | ||
|
||
context.Log.LogInformation("> Switch Off Hub"); | ||
await hub.SwitchOffAsync(); | ||
} | ||
else | ||
{ | ||
context.Log.LogWarning($"> User decided not to execute Test Script"); | ||
} | ||
} | ||
|
||
} | ||
|
||
private static void PrintModel(TestScriptExecutionContext context, DeploymentModel model) | ||
{ | ||
context.Log.LogInformation($"> Deployment Model of Test Script"); | ||
|
||
foreach (var hub in model.Hubs) | ||
{ | ||
context.Log.LogInformation($" > Hub: {hub.HubType}"); | ||
|
||
foreach (var device in hub.Devices) | ||
{ | ||
context.Log.LogInformation($" > Device: {device.DeviceType} @ {device.PortId}"); | ||
} | ||
} | ||
} | ||
|
||
private static DeploymentModel BbuildDeploymentModel(ITestScript script) | ||
{ | ||
var builder = new DeploymentModelBuilder(); | ||
script.DefineDeploymentModel(builder); | ||
var model = builder.Build(); | ||
return model; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/SharpBrick.PoweredUp.TestScript/SharpBrick.PoweredUp.TestScript.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\SharpBrick.PoweredUp\SharpBrick.PoweredUp.csproj" /> | ||
<ProjectReference Include="..\..\src\SharpBrick.PoweredUp.WinRT\SharpBrick.PoweredUp.WinRT.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.