public async Task cListTrucks()
        {
            ActionResult <IEnumerable <Vehicle> > actionresult = await _controller.GetVehicle();

            dbTrucks = ((List <Vehicle>)actionresult.Value);
            if (dbTrucks.Count == 2)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
        public void Get_WhenCalled_ReturnsOkResult()
        {
            _controller = new VehiclesController(_context);
            // Act
            var okResult = _controller.GetVehicle();

            // Assert
            Assert.IsType <OkObjectResult>(okResult);
        }
        public void GetById()
        {
            // Arrange
            VehiclesController controller = new VehiclesController(new VehicleRepository());

            // Act & Assert
            try
            {
                // Test invalid id
                Vehicle result = controller.GetVehicle(0);
                Assert.IsNull(result);
            }
            catch (HttpResponseException)
            {
                // Test valid id
                Vehicle result = controller.GetVehicle(1);
                Assert.AreEqual(1, result.Id);
            }
        }
 public async Task <IActionResult> About()
 {
     using (var db = new postgresContext())
     {
         //Tood IVehicle
         VehiclesController vehicle = new VehiclesController(db);
         VehicleList = await vehicle.GetVehicle();
     }
     return(View(VehicleList));
 }
示例#5
0
        public async Task Test4()
        {
            var mapper               = new Mock <IMapper>();
            var repository           = new Mock <IVehicleRepository>();
            var unitOfWork           = new Mock <IUnitOfWork>();
            IVehicleRepository _repo = new MockVehicleRepository();

            var _test   = new VehiclesController(mapper.Object, _repo, unitOfWork.Object);
            var vehicle = await _test.GetVehicle(-1);

            vehicle.Should().BeOfType <NotFoundResult>();
        }
示例#6
0
        public async Task Test2()
        {
            var mapper               = new Mock <IMapper>();
            var repository           = new Mock <IVehicleRepository>();
            var unitOfWork           = new Mock <IUnitOfWork>();
            IVehicleRepository _repo = new MockVehicleRepository();

            var _test   = new VehiclesController(mapper.Object, _repo, unitOfWork.Object);
            var vehicle = await _test.GetVehicle(1);

            Assert.IsInstanceOf <ObjectResult>(vehicle);

            var objectResponse = vehicle as ObjectResult;

            Assert.AreEqual(200, objectResponse.StatusCode);
        }
        public async Task GetVehicle_WhenCalled_ReturnsOkResult()
        {
            // Arrange
            var id = "ab2bd817";

            _mockVehicleRepository.Setup(repo => repo.GetVehicleAsync(id))
            .ReturnsAsync((new Vehicle
            {
                Id = "ab2bd817"
            }));

            // Act
            var result = await _controller.GetVehicle(id);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result.Result);
        }
示例#8
0
        public async Task GetAVehicle()
        {
            VehiclesController vc     = new VehiclesController();
            Random             random = new Random();

            Vehicle[] vehicles = vc.GetVehicles().ToArray <Vehicle>();

            if (vehicles.Length > 0)
            {
                var vehicleResult = await vc.GetVehicle(vehicles[random.Next(0, vehicles.Length - 1)].LicensePlateID);



                Assert.IsNotNull(vehicleResult);
                Assert.IsNotInstanceOfType(vehicleResult, typeof(NotFoundResult));
                Assert.IsInstanceOfType(vehicleResult, typeof(OkNegotiatedContentResult <Vehicle>));
            }
        }
示例#9
0
        public async Task checkOutVehicle()
        {
            VehiclesController vc     = new VehiclesController();
            Random             random = new Random();

            Vehicle[] vehicles = vc.GetVehicles().ToArray <Vehicle>();
            if (vehicles.Length > 0)
            {
                Vehicle vehicle = vehicles[random.Next(0, vehicles.Length - 1)];

                IHttpActionResult checkOutResult = await vc.checkOutVehicle(vehicle.LicensePlateID);

                IHttpActionResult afterCheckOutVheicle = await vc.GetVehicle(vehicle.LicensePlateID);

                Assert.IsNotNull(checkOutResult);
                Assert.IsInstanceOfType(checkOutResult, typeof(OkNegotiatedContentResult <Vehicle>));
                Assert.IsNotNull((checkOutResult as OkNegotiatedContentResult <Vehicle>).Content);

                Assert.IsInstanceOfType(afterCheckOutVheicle, typeof(NotFoundResult));
            }
        }
        public async Task GetVehicle_WithMatchingResult_ReturnsOneVehicle()
        {
            // Arrange
            var mockRepository = new Mock <IDataRepository <Vehicle> >();

            mockRepository.Setup(repository => repository.FindAsync(It.IsAny <int>()))
            .Returns <int>((id) => searchVehicle(id));

            var controller = new VehiclesController(null, mockRepository.Object);

            // Act
            var response = await controller.GetVehicle(1);

            // Assert
            response.Result.Should().BeOfType <OkObjectResult>();
            var okResult = response.Result as OkObjectResult;

            okResult.Value.Should().BeOfType <Vehicle>();
            var vehicle = okResult.Value as Vehicle;

            vehicle.Model.Should().Be("Ferrari");
        }
示例#11
0
        public async void QueryVehicleIdX_ReturnsCorrectVehicle(int id)
        {
            // Arrange
            var mockRepo = new Mock <IVehicleCatalogRepository>();

            mockRepo.Setup(repo => repo.GetVehicle(id))
            .Returns(Task.FromResult <Vehicle>(new Vehicle()
            {
                Id = id, Value = 10000.00M, BrandId = 1, ModelId = 1, YearModel = 1998, Fuel = "Gasoline"
            }));
            var mapper     = _dependencyFixture.ServiceProvider.GetService <IMapper>();
            var logger     = Mock.Of <ILogger <VehiclesController> >();
            var controller = new VehiclesController(mockRepo.Object, mapper, logger);

            // Act
            var result = await controller.GetVehicle(id);

            // Assert
            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <VehicleForDetail>(okResult.Value);
            var topVehicle  = returnValue.value;

            Assert.Equal("R$ 10.000,00", topVehicle);
        }