コード例 #1
0
        public void GetDeviceScreenshotById_ScreenshotLocked_ThrowsTimeoutException()
        {
            var device = new Device(_device1.Id, _device1.Name, false, _device1.Type, DeviceStatus.Online);

            // Arrange
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(repo => repo.Find(device.Id))
            .Returns(device);

            var mockLogger            = new Mock <IManagerLogger>();
            var mockConfiguration     = new Mock <IManagerConfiguration>();
            var mockDeviceUtils       = new Mock <IDeviceUtils>();
            var mockScreenshotService = new Mock <IScreenshotService>();

            var controller = new DevicesController(
                mockRepository.Object,
                mockLogger.Object,
                mockConfiguration.Object,
                mockDeviceUtils.Object,
                mockScreenshotService.Object,
                _externalProcesses);

            controller.ScreenshotLocked.Add(device.Id);
            controller.ScreenshotLockedTimeout = 500;

            // Act
            // Assert
            var start = DateTime.Now;

            Assert.Throws <TimeoutException>(() => controller.GetDeviceScreenshotById(device.Id));
            Assert.True(start + TimeSpan.FromMilliseconds(controller.ScreenshotLockedTimeout) <
                        DateTime.Now + TimeSpan.FromMilliseconds(1000));
            Assert.Contains(device.Id, controller.ScreenshotLocked);
        }
コード例 #2
0
        public void GetDeviceScreenshotById_DeviceOfflineFailedToGetDefault()
        {
            var device = new Device(_device1.Id, _device1.Name, false, _device1.Type, DeviceStatus.Offline);

            // Arrange
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(repo => repo.Find(device.Id))
            .Returns(device);

            var mockLogger            = new Mock <IManagerLogger>();
            var mockConfiguration     = new Mock <IManagerConfiguration>();
            var mockDeviceUtils       = new Mock <IDeviceUtils>();
            var mockScreenshotService = new Mock <IScreenshotService>();

            mockScreenshotService.Setup(x => x.LoadScreenshotForOfflineDevice(device)).Throws(new Exception());

            var controller = new DevicesController(
                mockRepository.Object,
                mockLogger.Object,
                mockConfiguration.Object,
                mockDeviceUtils.Object,
                mockScreenshotService.Object,
                _externalProcesses);
            // Act
            var result = controller.GetDeviceScreenshotById(device.Id);

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

            Assert.Equal(500, viewResult.StatusCode);
        }
コード例 #3
0
        public void GetDeviceScreenshotById_DeviceLockedOffice()
        {
            var device = new Device(_device1.Id, _device1.Name, false, _device1.Type, DeviceStatus.LockedOffline);

            // Arrange
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(repo => repo.Find(device.Id))
            .Returns(device);

            var mockLogger            = new Mock <IManagerLogger>();
            var mockConfiguration     = new Mock <IManagerConfiguration>();
            var mockDeviceUtils       = new Mock <IDeviceUtils>();
            var mockScreenshotService = new Mock <IScreenshotService>();

            mockScreenshotService.Setup(x => x.LoadScreenshotForOfflineDevice(device))
            .Returns(new FileStreamResult(File.Create(Guid.NewGuid().ToString()), "text/html"));

            var controller = new DevicesController(
                mockRepository.Object,
                mockLogger.Object,
                mockConfiguration.Object,
                mockDeviceUtils.Object,
                mockScreenshotService.Object,
                _externalProcesses);
            // Act
            var result = controller.GetDeviceScreenshotById(device.Id);

            // Assert
            Assert.IsType <FileStreamResult>(result);
        }
コード例 #4
0
        public void GetDeviceScreenshotById_UnknownDeviceType()
        {
            var device = new Device(_device1.Id, _device1.Name, false, (DeviceType)99, DeviceStatus.Online);

            // Arrange
            var mockRepository = new Mock <IRepository <Device> >();

            mockRepository.Setup(repo => repo.Find(device.Id))
            .Returns(device);

            var mockLogger            = new Mock <IManagerLogger>();
            var mockConfiguration     = new Mock <IManagerConfiguration>();
            var mockDeviceUtils       = new Mock <IDeviceUtils>();
            var mockScreenshotService = new Mock <IScreenshotService>();

            mockScreenshotService.Setup(x => x.TakeScreenshotAndroidDevice(device)).Throws(new Exception());

            var controller = new DevicesController(
                mockRepository.Object,
                mockLogger.Object,
                mockConfiguration.Object,
                mockDeviceUtils.Object,
                mockScreenshotService.Object,
                _externalProcesses);

            // Act
            var result = controller.GetDeviceScreenshotById(device.Id);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.DoesNotContain(device.Id, controller.ScreenshotLocked);
        }
コード例 #5
0
        public void GetDeviceScreenshotById_DeviceNotFound()
        {
            // 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.GetDeviceScreenshotById(_device1.Id);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }