Ejemplo n.º 1
0
        public async void DeleteAppliedReservationAsync_failed_to_unlock_device()
        {
            // Arrange
            var unlockedDevice = Device1;

            unlockedDevice.Available      = false;
            unlockedDevice.AppiumEndpoint = "";

            var mockRepository = new Mock <IRepository <ReservationApplied> >();

            mockRepository.Setup(mpr => mpr.Find(_reservationApplied1.Id)).Returns(_reservationApplied1);

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Put, $"{_httpLocalhost}/api/v1/device/{Device1.Id}")
            .Respond("application/json", JsonConvert.SerializeObject(unlockedDevice));
            mockHttp.When(HttpMethod.Get, $"{_httpLocalhost}/api/v1/device/{Device1.Id}")
            .Respond("application/json", JsonConvert.SerializeObject(Device1));

            var controller = new ReservationsAppliedController(mockRepository.Object,
                                                               new RestClient(_config.Object, new HttpClient(mockHttp), Logger), _appiumService, Logger,
                                                               _externalProcesses);

            // Act
            var result = await controller.DeleteAsync(_reservationApplied1.Id);

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

            Assert.Equal(500, viewResult.StatusCode);
            Assert.Equal("Failed to unlock device id: " + Device1.Id + " from reservation.", viewResult.Value);
        }
Ejemplo n.º 2
0
        public async void DeleteAppliedReservationAsync()
        {
            // Arrange
            var unlockedDevice = Device1;

            unlockedDevice.Available      = true;
            unlockedDevice.AppiumEndpoint = "";

            var mockRepository = new Mock <IRepository <ReservationApplied> >();

            mockRepository.Setup(mpr => mpr.Find(_reservationApplied1.Id)).Returns(_reservationApplied1);

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Put, $"{_httpLocalhost}/api/v1/device/{Device1.Id}")
            .Respond("application/json", JsonConvert.SerializeObject(unlockedDevice));
            mockHttp.When(HttpMethod.Get, $"{_httpLocalhost}/api/v1/device/{Device1.Id}")
            .Respond("application/json", JsonConvert.SerializeObject(Device1));

            var mockAppiumService = new Mock <IAppiumService>();

            mockAppiumService.Setup(appiumService => appiumService.StopAppiumForDeviceIdAsync(Device1.Id))
            .Returns(Task.FromResult(true));

            var controller = new ReservationsAppliedController(mockRepository.Object,
                                                               new RestClient(_config.Object, new HttpClient(mockHttp), Logger), mockAppiumService.Object, Logger,
                                                               _externalProcesses);

            // Act
            var result = await controller.DeleteAsync(_reservationApplied1.Id);

            // Assert
            Assert.IsType <OkResult>(result);
        }
Ejemplo n.º 3
0
        public async void DeleteAppliedReservationAsync_id_notFound()
        {
            // Arrange
            var mockRepository = new Mock <IRepository <ReservationApplied> >();

            mockRepository.Setup(mpr => mpr.Find(_reservationApplied1.Id)).Returns((ReservationApplied)null);

            var controller =
                new ReservationsAppliedController(mockRepository.Object, _restClient, _appiumService, Logger,
                                                  _externalProcesses);

            // Act
            var result = await controller.DeleteAsync(_reservationApplied1.Id);

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

            Assert.Equal("Reservation not found in database.", viewResult.Value);
        }