示例#1
0
        public void ctr_should_return_devices()
        {
            var obj = ctr.GetAll() as OkObjectResult;
            var res = obj?.Value as DeviceListViewModel;

            Assert.NotNull(res);
        }
        public async Task GetAll_WithDevicesAvailable_ReturnsDevices()
        {
            //Arrange
            var dbContext         = DbContextMocker.GetDbContext(nameof(GetAll_WithDevicesAvailable_ReturnsDevices));
            var devicesController = new DevicesController(dbContext);
            var expectedDevices   = new List <Device>
            {
                new Device()
                {
                    Device_id = 1, Name = "testName1", Location = "testLocation1"
                },
                new Device()
                {
                    Device_id = 2, Name = "testName2", Location = "testLocation2"
                },
                new Device()
                {
                    Device_id = 3, Name = "testName3", Location = "testLocation3"
                }
            };

            //Act
            var response = await devicesController.GetAll();

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

            dbContext.Dispose();

            //Assert
            result.StatusCode.Should().Be((int)HttpStatusCode.OK);
            Assert.True(DevicesComparer.CompareDevicesLists(devicesReceived, expectedDevices), "Devices list did not contain the " +
                        "expected device.");
        }
示例#3
0
        public void GetAllDevices_empty()
        {
            // Arrange
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(mpr => mpr.GetAll()).Returns(new List <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.GetAll();

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

            Assert.Empty(viewResult);
        }
示例#4
0
        public void GetAllDevices()
        {
            // Arrange
            var testDevices    = GetTestDevices();
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(mpr => mpr.GetAll()).Returns(testDevices);

            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.GetAll();

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

            Assert.Equal(testDevices.Count(), result.Count());
            Assert.Contains(_device1, viewResult);
            Assert.Contains(_device2, viewResult);
            Assert.Contains(_device3, viewResult);
        }