public void UpdateDevice_FailedToUpdate() { // Arrange Device device = _device1; device.Name = "updated name"; var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Find(_device1.Id)) .Returns(_device1); mockRepository.Setup(repo => repo.Update(_device1)) .Throws(new Exception()); 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.Update(_device1.Id, device); // Assert var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(500, viewResult.StatusCode); }
public void UpdateDevice() { // Arrange Device device = _device1; device.Name = "updated name"; 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 controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, null, null, _externalProcesses); // Act var result = controller.Update(_device1.Id, device); // Assert var viewResult = Assert.IsType <CreatedAtRouteResult>(result); Assert.Equal(device, viewResult.Value); }
public void Update_WithValidParameters_DeviceIsUpdated() { //Arrange var dbContext = DbContextMocker.GetDbContext(nameof(Update_WithValidParameters_DeviceIsUpdated)); var devicesController = new DevicesController(dbContext); var updateDeviceRequest = new UpdateDeviceRequest { Name = "updatedName", Location = "updatedLocation" }; var expectedDevice = new Device { Device_id = 1, Name = "updatedName", Location = "updatedLocation" }; //Act var response = devicesController.Update(1, updateDeviceRequest); var result = (ObjectResult)response.Result; var deviceReceived = result.Value.As <Device>(); dbContext.Dispose(); //Assert result.StatusCode.Should().Be((int)HttpStatusCode.OK); Assert.True(DevicesComparer.CompareDevices(deviceReceived, expectedDevice), "The device received is different " + "than the expected."); }
public void UpdateDevice_different_ids() { // 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 controller = new DevicesController(mockRepository.Object, mockLogger.Object, mockConfiguration.Object, null, null, _externalProcesses); // Act var result = controller.Update(_device1.Id, _device2); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void Update_WithoutAnExistingDevice_ReturnNotFound() { //Arrange var dbContext = DbContextMocker.GetDbContext(nameof(Update_WithoutAnExistingDevice_ReturnNotFound)); var devicesController = new DevicesController(dbContext); var updateDeviceRequest = new UpdateDeviceRequest { Name = "updatedName", Location = "updatedLocation" }; //Act var response = devicesController.Update(4, updateDeviceRequest); var result = (ObjectResult)response.Result; var deviceReceived = result.Value.As <Device>(); dbContext.Dispose(); //Assert result.StatusCode.Should().Be((int)HttpStatusCode.NotFound); }
public void UpdateDevice_notFound() { // Arrange Device device = _device1; device.Name = "updated name"; 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.Update(_device1.Id, device); // Assert Assert.IsType <NotFoundObjectResult>(result); }