public void ShellAdbCommand_ValidRequestExternalProcessThrowsException_ErrorResponse() { var device = new DeviceFactory().NewDevice("111", "device_111", true, DeviceType.Android, DeviceStatus.Online); var restClientMock = new Mock <IRestClient>(); restClientMock.Setup(r => r.GetDevice(It.IsAny <string>())).Returns(Task.FromResult <Device>(device)); var externalProcessesMock = new Mock <IExternalProcesses>(); externalProcessesMock .Setup(e => e.RunProcessAndReadOutput(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Throws <Exception>(); var adbController = new AdbController(restClientMock.Object, Logger, externalProcessesMock.Object); var result = adbController.ShellAdbCommand(new AdbCommand { AndroidDeviceId = device.Id, Command = "test" }); var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(500, viewResult.StatusCode); }
internal MinitouchController(AdbController controller, string minitouchpath, double Scale = 1) { this.minitouchpath = minitouchpath; this.controller = controller; var path = Path.GetTempPath() + "minitouch"; if (File.Exists(path)) { var ports = File.ReadAllLines(path); foreach (var port in ports) { try { if (minitouchPort == Convert.ToInt32(port)) { minitouchPort++; } else { break; } } catch { } } } using (var stream = File.AppendText(path)) { stream.WriteLine(minitouchPort); //Let other instance know that this socket is in use! } this.Scale = Scale; }
public void AdbCommand_ValidRequest_CorrectOutput() { var device = new DeviceFactory().NewDevice("111", "device_111", true, DeviceType.Android, DeviceStatus.Online); var restClientMock = new Mock <IRestClient>(); restClientMock.Setup(r => r.GetDevice(It.IsAny <string>())).Returns(Task.FromResult <Device>(device)); var externalProcessesMock = new Mock <IExternalProcesses>(); const string output = "output"; externalProcessesMock .Setup(e => e.RunProcessAndReadOutput(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(output); var adbController = new AdbController(restClientMock.Object, Logger, externalProcessesMock.Object); var result = adbController.Command(new AdbCommand { AndroidDeviceId = device.Id, Command = "test" }); var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(200, viewResult.StatusCode); Assert.Equal(output, viewResult.Value); }
public void ShellAdbCommand_NullDeviceIdAndCommand_BadRequest() { var restClientMock = new Mock <IRestClient>(); var adbController = new AdbController(restClientMock.Object, Logger, _externalProcesses); var result = adbController.ShellAdbCommand(new AdbCommand()); Assert.IsType <BadRequestObjectResult>(result); }
public void AdbCommand_NullRequest_BadRequest() { var restClientMock = new Mock <IRestClient>(); var adbController = new AdbController(restClientMock.Object, Logger, _externalProcesses); var result = adbController.Command(null); Assert.IsType <BadRequestObjectResult>(result); }
public void ShellAdbCommand_NonExistentDeviceId_BadRequest() { var restClientMock = new Mock <IRestClient>(); restClientMock.Setup(r => r.GetDevice(It.IsAny <string>())).Returns(Task.FromResult <Device>(null)); var adbController = new AdbController(restClientMock.Object, Logger, _externalProcesses); var result = adbController.ShellAdbCommand(new AdbCommand { AndroidDeviceId = "test", Command = "test" }); Assert.IsType <BadRequestObjectResult>(result); }
public void ShellAdbCommand_NotAndroidDeviceType_BadRequest() { var device = new DeviceFactory().NewDevice("111", "device_111", true, DeviceType.IOS, DeviceStatus.Online); var restClientMock = new Mock <IRestClient>(); restClientMock.Setup(r => r.GetDevice(It.IsAny <string>())).Returns(Task.FromResult <Device>(device)); var adbController = new AdbController(restClientMock.Object, Logger, _externalProcesses); var result = adbController.ShellAdbCommand(new AdbCommand { AndroidDeviceId = device.Id, Command = "test" }); Assert.IsType <BadRequestObjectResult>(result); }
private void Awake() { instance = this; adbController = new AdbController(); }