public async Task LoadAsyncProcessSuccess() { string processPath = null; MlaunchArguments passedArguments = null; // 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); MlaunchArgument listSimArg = passedArguments.Where(a => a is ListSimulatorsArgument).FirstOrDefault(); Assert.IsNotNull(listSimArg, "list devices arg missing"); MlaunchArgument outputFormatArg = passedArguments.Where(a => a is XmlOutputFormatArgument).FirstOrDefault(); Assert.IsNotNull(outputFormatArg, "output format arg missing"); Assert.AreEqual(75, simulators.AvailableDevices.Count()); }
public async Task LoadAsyncProcessErrorTest() { MlaunchArguments passedArguments = null; // 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) => { // we are going set the used args to validate them later, will always return an error from this method passedArguments = args; return(Task.FromResult(new ProcessExecutionResult { ExitCode = 1, TimedOut = false })); }); await Assert.ThrowsAsync <Exception>(async() => { await _simulators.LoadDevices(_executionLog.Object); }); // validate the execution of mlaunch MlaunchArgument listSimArg = passedArguments.Where(a => a is ListSimulatorsArgument).FirstOrDefault(); Assert.NotNull(listSimArg); MlaunchArgument outputFormatArg = passedArguments.Where(a => a is XmlOutputFormatArgument).FirstOrDefault(); Assert.NotNull(outputFormatArg); }
[TestCase (true)] // timeoout public void LoadAsyncProcessErrorTest (bool timeout) { string processPath = null; MlaunchArguments passedArguments = null; // 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) => { // we are going set the used args to validate them later, will always return an error from this method processPath = p.StartInfo.FileName; passedArguments = args; if (!timeout) return Task.FromResult (new ProcessExecutionResult { ExitCode = 1, TimedOut = false }); else return Task.FromResult (new ProcessExecutionResult { ExitCode = 0, TimedOut = true }); }); Assert.ThrowsAsync<Exception> (async () => { await devices.LoadDevices (executionLog.Object); }); MlaunchArgument listDevArg = passedArguments.Where (a => a is ListDevicesArgument).FirstOrDefault (); Assert.IsNotNull (listDevArg, "list devices arg missing"); MlaunchArgument outputFormatArg = passedArguments.Where (a => a is XmlOutputFormatArgument).FirstOrDefault (); Assert.IsNotNull (outputFormatArg, "output format arg missing"); }
public async Task LoadAsyncProcessSuccess() { MlaunchArguments passedArguments = null; // 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 <int>(), It.IsAny <CancellationToken?>())) .Returns <MlaunchArguments, ILog, TimeSpan, Dictionary <string, string>, int, CancellationToken?>((args, log, t, env, verbosity, 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 _simulatorLoader.LoadDevices(_executionLog.Object); MlaunchArgument listSimArg = passedArguments.Where(a => a is ListSimulatorsArgument).FirstOrDefault(); Assert.NotNull(listSimArg); MlaunchArgument outputFormatArg = passedArguments.Where(a => a is XmlOutputFormatArgument).FirstOrDefault(); Assert.NotNull(outputFormatArg); Assert.Equal(75, _simulatorLoader.AvailableDevices.Count()); }
public async Task LoadAsyncProcessSuccess(bool extraData) { string processPath = null; MlaunchArguments passedArguments = null; // 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 ListDevicesArgument).First().AsCommandLineArgument(); tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1).Replace("\"", string.Empty); var name = GetType().Assembly.GetManifestResourceNames().Where(a => a.EndsWith("devices.xml", StringComparison.Ordinal)).FirstOrDefault(); using (var outputStream = new StreamWriter(tempPath)) using (var sampleStream = new StreamReader(GetType().Assembly.GetManifestResourceStream(name))) { string line; while ((line = sampleStream.ReadLine()) != null) { outputStream.WriteLine(line); } } return(Task.FromResult(new ProcessExecutionResult { ExitCode = 0, TimedOut = false })); }); await _devices.LoadDevices(_executionLog.Object, listExtraData : extraData); // assert the devices that are expected from the sample xml MlaunchArgument listDevArg = passedArguments.Where(a => a is ListDevicesArgument).FirstOrDefault(); Assert.NotNull(listDevArg); MlaunchArgument outputFormatArg = passedArguments.Where(a => a is XmlOutputFormatArgument).FirstOrDefault(); Assert.NotNull(outputFormatArg); if (extraData) { MlaunchArgument listExtraDataArg = passedArguments.Where(a => a is ListExtraDataArgument).FirstOrDefault(); Assert.NotNull(listExtraDataArg); } Assert.Equal(2, _devices.Connected64BitIOS.Count()); Assert.Single(_devices.Connected32BitIOS); Assert.Empty(_devices.ConnectedTV); }
public void MlaunchArgumentsEqualityTest() { var args1 = new MlaunchArgument[] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("bar") }; var args2 = new MlaunchArgument[] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("bar") }; var args3 = new MlaunchArgument[] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("xyz") }; Assert.Equal(args1, args2); Assert.NotEqual(args1, args3); }
public void MlaunchArgumentsEqualityTest() { var args1 = new MlaunchArgument [] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("bar") }; var args2 = new MlaunchArgument [] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("bar") }; var args3 = new MlaunchArgument [] { new ListDevicesArgument("foo"), new ListSimulatorsArgument("xyz") }; Assert.AreEqual(args1, args2, "equality is broken"); Assert.AreNotEqual(args1, args3, "equality is broken"); }
private void AssertArgumentValue(MlaunchArgument arg, string expected, string message = null) { var value = arg.AsCommandLineArgument().Split(new char[] { '=' }, 2).LastOrDefault(); Assert.Equal(expected, value); }