public void RestartDevice_DeviceNotFound() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Find(_device1.Id)) .Returns((Device)null); var mockLogger = new Mock <IManagerLogger>(); var mockConfiguration = new Mock <IManagerConfiguration>(); var controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, null, null, _externalProcesses); // Act var result = controller.RestartDevice(_device1.Id); // Assert Assert.IsType <NotFoundObjectResult>(result); }
public void RestartDevice_Ok() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Find(_device1.Id)) .Returns(_device1); var mockLogger = new Mock <IManagerLogger>(); var mockConfiguration = new Mock <IManagerConfiguration>(); var mockDeviceUtils = new Mock <IDeviceUtils>(); mockDeviceUtils.Setup(x => x.RestartDevice(_device1)).Returns(string.Empty); var controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, mockDeviceUtils.Object, null, _externalProcesses); // Act var result = controller.RestartDevice(_device1.Id); // Assert Assert.IsType <OkResult>(result); }
public void RestartDevice_DeviceNotAvailable() { var device = new Device(_device1.Id, _device1.Name, false, _device1.Type, DeviceStatus.Locked); // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Find(device.Id)) .Returns(device); var mockLogger = new Mock <IManagerLogger>(); var mockConfiguration = new Mock <IManagerConfiguration>(); var controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, null, null, _externalProcesses); // Act var result = controller.RestartDevice(device.Id); // Assert var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(423, viewResult.StatusCode); }
public void RestartDevice_RestartFailed() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Find(_device1.Id)) .Returns(_device1); var mockLogger = new Mock <IManagerLogger>(); var mockConfiguration = new Mock <IManagerConfiguration>(); var mockDeviceUtils = new Mock <IDeviceUtils>(); mockDeviceUtils.Setup(x => x.RestartDevice(_device1)).Returns("ERROR"); var controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, mockDeviceUtils.Object, null, _externalProcesses); // Act var result = controller.RestartDevice(_device1.Id); // Assert var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(500, viewResult.StatusCode); }