public async Task GetById_WithoutAnExistingDevice_ReturnsNotFound()
        {
            //Arrange
            var dbContext         = DbContextMocker.GetDbContext(nameof(GetById_WithoutAnExistingDevice_ReturnsNotFound));
            var devicesController = new DevicesController(dbContext);

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

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

            dbContext.Dispose();

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
Exemplo n.º 2
0
        public void GetById_id_notFound()
        {
            // 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.GetById(_device2.Id);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
Exemplo n.º 3
0
        public void GetById()
        {
            // 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.GetById(_device1.Id);

            // Assert
            var viewResult = Assert.IsType <JsonResult>(result);

            Assert.Equal(_device1, viewResult.Value);
        }
        public async Task GetById_WithDeviceAvailable_ReturnsDevice()
        {
            //Arrange
            var dbContext         = DbContextMocker.GetDbContext(nameof(GetById_WithDeviceAvailable_ReturnsDevice));
            var devicesController = new DevicesController(dbContext);
            var expectedDevice    = new Device
            {
                Device_id = 1, Name = "testName1", Location = "testLocation1"
            };

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

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