public void RemoveDevice_DeviceLocked() { var device = new Device(_device1.Id, _device1.Name, false, _device1.Type, DeviceStatus.Locked); // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add(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); controller.Create(_device1); // Act var result = controller.Delete(device.Id); // Assert var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(423, viewResult.StatusCode); }
public void RemoveDevice_FailedToRemove() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add(_device1)); mockRepository.Setup(repo => repo.Find(_device1.Id)) .Returns(_device1); mockRepository.Setup(repo => repo.Remove(_device1.Id)).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); controller.Create(_device1); // Act var result = controller.Delete(_device1.Id); // Assert var viewResult = Assert.IsType <ObjectResult>(result); Assert.Equal(500, viewResult.StatusCode); }
public async Task Create_WithValidParameters_DeviceIsAdded() { //Arrange var dbContext = DbContextMocker.GetDbContext(nameof(Create_WithValidParameters_DeviceIsAdded)); var devicesController = new DevicesController(dbContext); var createDeviceRequest = new CreateDeviceRequest { Name = "testName1", Location = "testLocation1" }; var expectedDevice = new Device { Device_id = 4, Name = "testName1", Location = "testLocation1" }; //Act var response = await devicesController.Create(createDeviceRequest); var result = (ObjectResult)response.Result; var deviceReceived = result.Value.As <Device>(); dbContext.Dispose(); //Assert result.StatusCode.Should().Be((int)HttpStatusCode.Created); Assert.True(DevicesComparer.CompareDevices(deviceReceived, expectedDevice), "The device received is different " + "than the expected."); }
public void CreateDevice_null() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add((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.Create(null); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void CreateDevice_DeviceNameEmpty() { var device = new Device(_device1.Id, "", _device1.Available, _device1.Type, _device1.Status); // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add(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.Create(device); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void CreateDevice() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add(_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.Create(_device1); // Assert var viewResult = Assert.IsType <CreatedAtRouteResult>(result); Assert.Equal(_device1, viewResult.Value); }
public void RemoveDevice() { // Arrange var mockRepository = new Mock <IRepository <Device> >(); mockRepository.Setup(repo => repo.Add(_device1)); 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); controller.Create(_device1); // Act var result = controller.Delete(_device1.Id); // Assert Assert.IsType <OkResult>(result); }