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); }
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 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); }