public async Task FindAsyncDoNotCreateTest(TestTarget target, int expected) { string processPath = null; MlaunchArguments passedArguments = null; processManager .Setup(h => h.ExecuteXcodeCommandAsync("simctl", It.Is <string []> (args => args [0] == "create"), executionLog.Object, TimeSpan.FromMinutes(1))) .ReturnsAsync(new ProcessExecutionResult() { ExitCode = 0 }); // moq It.Is is not working as nicelly as we would like it, we capture data and use asserts processManager .Setup(p => p.RunAsync(It.IsAny <Process> (), It.IsAny <MlaunchArguments> (), It.IsAny <ILog> (), It.IsAny <TimeSpan?> (), It.IsAny <Dictionary <string, string> > (), It.IsAny <CancellationToken?> (), It.IsAny <bool?> ())) .Returns <Process, MlaunchArguments, ILog, TimeSpan?, Dictionary <string, string>, CancellationToken?, bool?> ((p, args, log, t, env, token, d) => { processPath = p.StartInfo.FileName; passedArguments = args; // we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :) var tempPath = args.Where(a => a is ListSimulatorsArgument).First().AsCommandLineArgument(); tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1).Replace("\"", string.Empty); CopySampleData(tempPath); return(Task.FromResult(new ProcessExecutionResult { ExitCode = 0, TimedOut = false })); }); await simulators.LoadDevices(executionLog.Object); var sims = await simulators.FindSimulators(target, executionLog.Object, false, false); Assert.AreEqual(expected, sims.Count(), $"{target} simulators count"); }
public async Task FindAsyncDoNotCreateTest(TestTarget target, bool shouldFindCompanion) { MlaunchArguments passedArguments = null; _processManager .Setup(h => h.ExecuteXcodeCommandAsync("simctl", It.Is <string[]>(args => args[0] == "create"), _executionLog.Object, TimeSpan.FromMinutes(1))) .ReturnsAsync(new ProcessExecutionResult() { ExitCode = 0 }); // moq It.Is is not working as nicelly as we would like it, we capture data and use asserts _processManager .Setup(p => p.ExecuteCommandAsync(It.IsAny <MlaunchArguments>(), It.IsAny <ILog>(), It.IsAny <TimeSpan>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <CancellationToken?>())) .Returns <MlaunchArguments, ILog, TimeSpan, Dictionary <string, string>, CancellationToken?>((args, log, t, env, token) => { passedArguments = args; // we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :) var tempPath = args.Where(a => a is ListSimulatorsArgument).First().AsCommandLineArgument(); tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1).Replace("\"", string.Empty); CopySampleData(tempPath); return(Task.FromResult(new ProcessExecutionResult { ExitCode = 0, TimedOut = false })); }); await _simulators.LoadDevices(_executionLog.Object); var(simulator, companion) = await _simulators.FindSimulators(target, _executionLog.Object, false, false); Assert.NotNull(simulator); if (shouldFindCompanion) { Assert.NotNull(companion); } else { Assert.Null(companion); } }