Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async Task Test_Delete_Method_With_Valid_Id()
        {
            var deleteResult = await testingInstance.Delete(1);

            var getResult = await testingInstance.Get();

            var expectedDevicesCount   = DevicesRepositoryMock.GetTestingDevices().Count() - 1;
            var getResultAsOkResult    = Assert.IsAssignableFrom <OkObjectResult>(getResult);
            var getResultAsDevicesList = getResultAsOkResult.Value as IQueryable <Device>;
            var devicesCount           = getResultAsDevicesList.Count();

            Assert.IsAssignableFrom <OkResult>(deleteResult);

            Assert.Equal(devicesCount, expectedDevicesCount);
        }
        public async Task Delete_WithoutAnExistingDevice_ReturnNotFound()
        {
            //Arrange
            var dbContext         = DbContextMocker.GetDbContext(nameof(Delete_WithoutAnExistingDevice_ReturnNotFound));
            var devicesController = new DevicesController(dbContext);

            //Act
            var response = await devicesController.Delete(4);

            var result         = (ObjectResult)response.Result;
            var deviceReceived = result.Value.As <Device>();

            dbContext.Dispose();

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Delete_WithValidParameters_DeviceIsDeleted()
        {
            //Arrange
            var dbContext         = DbContextMocker.GetDbContext(nameof(Delete_WithValidParameters_DeviceIsDeleted));
            var devicesController = new DevicesController(dbContext);

            //Act
            var response = await devicesController.Delete(1);

            var result         = (ObjectResult)response.Result;
            var deviceReceived = result.Value.As <Device>();

            dbContext.Dispose();

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
        public async Task DeleteADevicesByItsUID()
        {
            //Setting all
            var nameBD = Guid.NewGuid().ToString();

            var context = BuildContext(nameBD);

            context.Gateways.Add(new Gateway()
            {
                SerialNumber = "gw-001", Name = "Gateway 1", IpAddress = "10.0.0.1"
            });
            context.Peripherals.Add(new Peripheral()
            {
                UID = 1, Vendor = "Device 1", Date = DateTime.Parse("2021-02-16T16:17:00"), Status = true
            });
            context.PeripheralGateways.Add(new PeripheralsGateways()
            {
                GatewaySerialNumber = "gw-001", PeripheralId = 1
            });

            await context.SaveChangesAsync();

            var testContext = BuildContext(nameBD);

            //Tests
            var controller = new DevicesController(testContext);

            var response = await controller.Delete(1);

            //Verification
            var result = response.Result as AcceptedResult;

            //Bad Request Http Status Code
            Assert.AreEqual(202, result.StatusCode);

            var countDevices = await testContext.Peripherals.CountAsync();

            Assert.AreEqual(0, countDevices);
            var countRelations = await testContext.PeripheralGateways.CountAsync();

            Assert.AreEqual(0, countRelations);
        }
Ejemplo n.º 7
0
        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);
        }