/// <summary> /// Initializes a new <see cref="AutomatedPSycheTest"/>. /// </summary> /// <param name="script">The test script containing a test</param> /// <param name="test">The test function</param> public AutomatedPSycheTest(ITestScript script, ITestFunction test) { Name = String.Format("{0}:{1}", script.Source.Name, test.DisplayName); TestType = "Integration Test"; Storage = script.Source.Name; Identifier = _identifierFactory.CreateIdentifier(Name); }
public async Task ExecuteAsync(Dictionary <string, string> testScriptArgs) { var assemblyName = testScriptArgs["assembly_name"]; var testName = testScriptArgs["test_name"]; _testScript = TestFactory.Instance(assemblyName).Create(testName); foreach (var schedule in GetRunningSchedule()) { try { var delayTask = Task.Delay(schedule.StartTime - DateTime.UtcNow); _testScript.Intialize(testScriptArgs); await delayTask; new Timer(x => { _testScript.StartAsync(); }, null, 0, 0); } catch { } } }
private static DeploymentModel BbuildDeploymentModel(ITestScript script) { var builder = new DeploymentModelBuilder(); script.DefineDeploymentModel(builder); var model = builder.Build(); return(model); }
private void OnTestScriptStarting(ITestScript script) { var localEvent = TestScriptStarting; if (localEvent != null) { localEvent(this, new TestScriptStartingEventArgs(script)); } }
private void OnTestScriptEnded(ITestScript script) { var localEvent = TestScriptEnded; if (localEvent != null) { localEvent(this, new TestScriptEndedEventArgs(script)); } }
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>(), new MindstormsSensorsTestScript(), }; 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"); } } }
/// <summary> /// Initializes a new <see cref="TestLocationManager"/> for a test. /// </summary> /// <param name="outputDirectory">The root working directory of a test</param> /// <param name="script">The current test script</param> /// <param name="test">The current test</param> public TestLocationManager(DirectoryInfo outputDirectory, ITestScript script, ITestFunction test) { _scriptDirectory = new DirectoryInfo(Path.Combine( outputDirectory.FullName, script.Source.Name)); if (!_scriptDirectory.Exists) _scriptDirectory.Create(); _testDirectory = _scriptDirectory.CreateSubdirectory(test.DisplayName); OutputDirectory = _testDirectory; ScriptLocation = script.Source.Directory; }
public ScriptingTestScriptConstructor(ITestScript script) : base(script) { }
/// <summary> /// Initializes a new instance of <see cref="TestScriptStartingEventArgs"/>. /// </summary> /// <param name="script">The test script that is starting</param> public TestScriptStartingEventArgs(ITestScript script) { Script = script; }
static async Task Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Environment.CurrentDirectory) .AddJsonFile("poweredup.json", true) .AddCommandLine(args) .Build(); var serviceCollection = new ServiceCollection() .AddLogging(builder => { builder.AddConsole(); }) .AddPoweredUp(); var bluetoothAdapter = configuration["BluetoothAdapter"] ?? "WinRT"; #if WINDOWS if (bluetoothAdapter == "WinRT") { serviceCollection.AddWinRTBluetooth(); } #endif #if NET5_0_OR_GREATER if (bluetoothAdapter == "BlueGigaBLE") { // config for "COMPortName" and "TraceDebug" (either via command line or poweredup.json) serviceCollection.AddBlueGigaBLEBluetooth(configuration); } #endif var serviceProvider = serviceCollection.BuildServiceProvider(); var host = serviceProvider.GetService <PoweredUpHost>(); IEnumerable <ITestScript> scripts = new ITestScript[] { new TechnicMotorTestScript <TechnicLargeLinearMotor>(), new MindstormsSensorsTestScript(), }; 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 async Task <IReadOnlyCollection <ErrorRecord> > ExecuteCoreAsync(PowerShell powershell, ITestFunction test, ITestScript script) { // Add the script's functions/variables to the pipeline. powershell.AddScript(script.Text); var scriptErrors = await powershell.InvokeAsync(_taskScheduler).ConfigureAwait(false); powershell.Commands.Clear(); // Clear the pipeline. if (scriptErrors.Any()) { return(scriptErrors); } // Now execute the test function plus setup/teardown. script.TestSetup.Apply(s => powershell.AddCommand(s.Name)); powershell.AddCommand(test.FunctionName); script.TestCleanup.Apply(s => powershell.AddCommand(s.Name)); var testErrors = await powershell.InvokeAsync(_taskScheduler).ConfigureAwait(false); if (testErrors.Any()) { return(testErrors); } return(new ErrorRecord[0]); }
/// <summary> /// Executes a test function. /// </summary> /// <param name="transaction">The current test transaction</param> /// <param name="powershell">The PowerShell instance to us</param> /// <param name="test">The test to run</param> /// <param name="script">The parent script</param> private async Task <IEnumerable <TestResult> > ExecuteAsync(ITestExecutionTransaction transaction, PowerShell powershell, ITestFunction test, ITestScript script) { var timer = _timerFactory(); try { if (test.ShouldSkip) { return(new SkippedResult(test.SkipReason).ToEnumerable()); } var testContext = InitializeTestContext(powershell, transaction.OutputDirectory); IReadOnlyCollection <ErrorRecord> errors; using (timer.Start()) { errors = await ExecuteCoreAsync(powershell, test, script).ConfigureAwait(false); } if (errors.Any()) { return(new FailedResult(timer.Elapsed, new PSScriptError(new ErrorRecordWrapper(errors.First()), test.Source.File)).ToEnumerable()); } return(new PassedResult(timer.Elapsed, testContext.Artifacts).ToEnumerable()); } catch (CmdletInvocationException cmdletException) { return(CreateFailed(timer.Elapsed, cmdletException.InnerException ?? cmdletException).ToEnumerable()); } catch (Exception exception) { _logger.Error("Exception occurred during test '{0}': {1}{2}{3}", test.UniqueName, exception.Message, Environment.NewLine, exception.StackTrace); return(CreateFailed(timer.Elapsed, exception).ToEnumerable()); } }
/// <summary> /// Initializes a new instance of <see cref="TestScriptStartingEventArgs"/>. /// </summary> /// <param name="script">The test script that has ended</param> public TestScriptEndedEventArgs(ITestScript script) { Script = script; }
public ScriptingTestScriptTearDowner(ITestScript script) : base(script) { }
public ScriptingTestScriptRelocator(ITestScript script) : base(script) { }
public ScriptingTestScriptSetUpper(ITestScript script) : base(script) { }