示例#1
0
        public async Task DeleteAsync()
        {
            try
            {
                // Arrange
                VehicleController controller = new VehicleController();

                var result = await controller.Get();

                var vehicle = result.FirstOrDefault(e => e.Brand.Equals("Toyota") &&
                                                    e.Model.Equals("Corolla") &&
                                                    e.Price == 98750.7M);

                // Act
                await controller.Delete(vehicle.Id);

                result = await controller.Get();

                vehicle = result.FirstOrDefault(e => e.Brand.Equals("Toyota") &&
                                                e.Model.Equals("Corolla") &&
                                                e.Price == 98750.7M);

                // Assert
                Assert.IsNull(vehicle);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
示例#2
0
        public void DeleteVehicleTest()
        {
            //Arrange
            mockRepo.Setup(repo => repo.Vehicles.FindByCondition(r => r.vehicleId == It.IsAny <int>())).Returns(GetVehicles());
            mockRepo.Setup(repo => repo.Vehicles.Delete(GetVehicle()));
            //Act
            var controllerActionResult = vehicleController.Delete(It.IsAny <int>());

            //Assert
            Assert.NotNull(controllerActionResult);
        }
示例#3
0
        public async Task Vehicle_Delete_Existing_VehicleId()
        {
            //setup
            var VehicleId = 10;

            var position = _vehicle.FirstOrDefault(x => x.VehicleId == VehicleId);


            _vehicleRepository.Setup(x => x.GetById(VehicleId)).ReturnsAsync(_vehicle.FirstOrDefault(x => x.VehicleId == VehicleId));
            _vehicleRepository.Setup(x => x.Delete(VehicleId)).Callback(() => _vehicle.Remove(position));

            //Act
            var result = await _controller.Delete(VehicleId);

            //Assert
            var okObjectResult = result as OkObjectResult;

            Assert.Null(okObjectResult);

            Assert.Null(_vehicle.FirstOrDefault(x => x.VehicleId == VehicleId));
        }
        public void DeleteVehicle_ShouldDeleteVehicleInDatabase()
        {
            Vehicle v = new Vehicle {
                Id = 3, Year = 2013, Make = "Ferrari3", Model = "XXXL"
            };
            var controller             = new VehicleController(new MockVehiclePersistent());
            HttpRequestMessage request = new HttpRequestMessage();

            controller.Request = request;
            var result = controller.Delete(3);

            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void Delete_NotFound_BadRequest()
        {
            var controller = new VehicleController(new VehicleService(_vehicleRepositoryMock.Object), _mapper);

            string chassi = "0000000004G117974";

            _vehicleRepositoryMock.Setup <Task <Vehicle> >(x => x.FindByIdAsync(chassi))
            .Returns(Task.FromResult <Vehicle>(_mockVehicle.FirstOrDefault(x => x.Chassi == chassi)));

            var response = controller.Delete(chassi);
            var result   = response as BadRequestObjectResult;

            Assert.NotNull(result);

            Assert.Equal(400, result.StatusCode);
        }
示例#6
0
        public async void Delete_Errors()
        {
            VehicleControllerMockFacade mock = new VehicleControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            VehicleController controller = new VehicleController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
示例#7
0
        public void DeleteVehicleTest()
        {
            VehicleDTO vehicle = CreateVehicle();
            UserDTO    user    = createUserDTO();
            Guid       token   = Guid.NewGuid();

            var mockUserService = new Mock <UserService>();

            mockUserService.Setup(us => us.GetUserLoggedIn(token)).Returns(user);
            var mockVehicleService = new Mock <VehicleService>();

            mockVehicleService.Setup(vs => vs.DeleteVehicle("TEST1234")).Verifiable();

            VehicleController vehicleController = new VehicleController(mockUserService.Object, mockVehicleService.Object, null);

            vehicleController.Request = createUserControllerRequest();
            addTokenHeaderToRequest(vehicleController.Request, token);

            ResponseMessageResult response = (ResponseMessageResult)vehicleController.Delete("TEST1234");

            Assert.AreEqual(HttpStatusCode.OK, response.Response.StatusCode);
        }
示例#8
0
        public void ApiDeleteVehicleTest_ReturnsOkay()
        {
            // Arrange
            var repo = new VehiclesRepository();

            controller = new VehicleController(repo)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };
            VehiclesRepository.Vehicles.Add(new Vehicle()
            {
                Make  = "Honda",
                Model = "HRV",
                Year  = 2015
            });

            // Act
            IHttpActionResult actionResult = controller.Delete(1);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
示例#9
0
        public void DeleteTestReturn200()
        {
            var result = vehicleController.Delete(2);

            Assert.IsInstanceOf <NoContentResult>(result);
        }