コード例 #1
0
        public async Task GetVehicles_AllVehicles_RetrunStatusCodeOK()
        {
            // Arrange
            var vehicleResponse = new List <VehicleResponse>
            {
                new VehicleResponse
                {
                    Id          = Guid.NewGuid(),
                    VehicleId   = 1,
                    Number      = "A-001",
                    Model       = "Honda City",
                    Description = "Blue Color"
                }
            };

            vehiclesService.GetVehicleListAsync().Returns(Task.FromResult(vehicleResponse));

            // Act
            var actionResult = await vehiclesController.GetVehicles();

            var objectResult = actionResult as OkObjectResult;

            //Assert
            Assert.NotNull(objectResult);
            Assert.Equal((int)System.Net.HttpStatusCode.OK, objectResult.StatusCode);
        }
コード例 #2
0
        public async void QueryVehicleList_ReturnsVehiclesAscendingByValue(int modelId)
        {
            // Arrange
            var mockRepo = new Mock <IVehicleCatalogRepository>();

            mockRepo.Setup(repo => repo.GetVehicles(modelId))
            .Returns(Task.FromResult <IEnumerable <Vehicle> >(new List <Vehicle>()
            {
                new Vehicle()
                {
                    Id = 1, Value = 15488.45M, BrandId = 1, ModelId = modelId, YearModel = 1998, Fuel = "Gasoline"
                },
                new Vehicle()
                {
                    Id = 2, Value = 18484.54M, BrandId = 1, ModelId = modelId, YearModel = 1996, Fuel = "Gasoline"
                },
                new Vehicle()
                {
                    Id = 3, Value = 10000.00M, BrandId = 1, ModelId = modelId, YearModel = 1997, Fuel = "Gasoline"
                },
            }.OrderBy(o => o.Value)));
            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.GetVehicles(modelId);

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

            Assert.Equal("R$ 10.000,00", topVehicle);
        }
コード例 #3
0
        public static string GetcarTripsPdfUrl(PdfModel pdfModel)
        {
            var carguidesController = new CarguidesController();
            var vehicleController   = new VehiclesController();
            var carTrips            = carguidesController.GetCarguidesByVehicleId(pdfModel.VehicleId);
            var vehicle             = vehicleController.GetVehicles().FirstOrDefault(x => x.VehicleId == pdfModel.VehicleId);
            var url = buildpdf(carTrips, vehicle, pdfModel.FromDate, pdfModel.ToDate);

            return(url);
        }
コード例 #4
0
 public async Task IsPrime_InputIs1_ReturnFalseAsync()
 {
     Task.Run(async() =>
     {
         // Actual test code here.
         var VehiclesResult      = await controller.GetVehicles();
         List <Vehicle> Vehicles = VehiclesResult.Value.ToList();
         Assert.AreEqual(57, Vehicles.Count());
     }).GetAwaiter().GetResult();
 }
コード例 #5
0
        public async Task GetVehicles_ExceptionThrown_ShouldLog(
            Exception exception,
            [Frozen] ILogger <VehiclesController> logger,
            [Frozen] IVehicleService vehicleService,
            VehiclesController sut)
        {
            vehicleService.GetAllAsync().Throws(exception);

            await sut.GetVehicles();

            logger.Received().LogError(exception.ToString());
        }
コード例 #6
0
        public void GetAllVehicles()
        {
            VehiclesController    vc       = new VehiclesController();
            IEnumerable <Vehicle> vehicles = vc.GetVehicles();


            // Assert.AreEqual<int>(2, vehicles.ToArray().Length);
            foreach (Vehicle v in vehicles)
            {
                Assert.IsNotNull(v);
                Assert.AreNotEqual <string>("Default", v.Name);
            }
        }
コード例 #7
0
        public async Task GetVehicles_FetchedListOfVehicles_Returns200WithVehicles(
            IEnumerable <VehicleViewModel> vehicles,
            [Frozen] IVehicleService vehicleService,
            VehiclesController sut)
        {
            vehicleService.GetAllAsync().Returns(vehicles);

            var result = (await sut.GetVehicles()) as OkObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status200OK);
            var vehiclesResult = result.Value as IEnumerable <VehicleViewModel>;

            vehiclesResult.Should().NotBeNull();
            vehiclesResult.Should().BeEquivalentTo(vehicles);
        }
コード例 #8
0
        public async Task GetVehicles_ExceptionThrown_Returns500(
            [Frozen] IVehicleService vehicleService,
            VehiclesController sut)
        {
            vehicleService.GetAllAsync().Throws(new Exception());

            var result = (await sut.GetVehicles()) as ObjectResult;

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status500InternalServerError);
            var errorInfo = result.Value as ErrorInfo;

            errorInfo.Should().NotBeNull();
            errorInfo.Type.Should().Be(ErrorType.UnhandledError);
            errorInfo.Messages.Should().BeEquivalentTo("Error fetching vehicles from storage.");
        }
コード例 #9
0
        public async Task GetVehicles_WhenCalled_ReturnsOkResult()
        {
            // Arrange
            _mockVehicleRepository.Setup(service => service.GetVehiclesAsync()).ReturnsAsync(
                new List <Vehicle>
            {
                new Vehicle(),
                new Vehicle()
            }
                );

            // Act
            var result = await _controller.GetVehicles();

            // Assert
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result.Result);
        }
コード例 #10
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>));
            }
        }
コード例 #11
0
        public async void VehiclesController_GetVehicles()
        {
            // Arrange (DB schema)
            try
            {
                // TODO: UseModel to override OnModelCreating
                var options = new DbContextOptionsBuilder <NMTFleetManagerContext>()
                              .UseSqlite(connection)
                              .Options;

                using (context = new NMTFleetManagerContext(options))
                {
                    context.Database.OpenConnection();
                    context.Database.EnsureCreated();
                }

                // Seed data into the context
                using (context = new NMTFleetManagerContext(options))
                {
                    SeedCollection seedCollection = SeedData.Seed();
                    context.Vehicles.AddRange(seedCollection.Vehicles);
                    context.SaveChanges();
                }

                // Assert
                using (context = new NMTFleetManagerContext(options))
                {
                    int expected = 5;
                    vehiclesController = new VehiclesController(context);
                    var actionResult = await vehiclesController.GetVehicles();

                    var okResult = actionResult.Result as OkObjectResult;
                    var vehicles = okResult?.Value as IEnumerable <Vehicle>;

                    var actual = vehicles.Count();

                    Assert.Equal(expected, actual);
                }
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #12
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));
            }
        }
コード例 #13
0
        public void GetVehicles_WithTwoVehicles_ReturnsTwoVehicles()
        {
            // Arrange
            var mockRepository = new Mock <IDataRepository <Vehicle> >();

            mockRepository.Setup(repository => repository.ToList())
            .Returns(() => { return(this.vehicles); });
            var controller = new VehiclesController(null, mockRepository.Object);

            // Act
            var response = controller.GetVehicles();

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

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

            vehicles.Count.Should().Be(2);
        }
コード例 #14
0
        public void GetVehicles_WithReturnOkResult()
        {
            //Arrange
            FilterVehicles filterVehicle = new FilterVehicles()
            {
                CustomerID  = 1,
                IsConnected = 1
            };
            var mockIMapper = new Mock <IMapper>();

            var mockIVehicleService = new Mock <IVehicleService>();

            mockIVehicleService.Setup(p => p.GetAll());
            VehiclesController vehiclesController = new VehiclesController(mockIVehicleService.Object, mockIMapper.Object);

            //Act
            var sut      = vehiclesController.GetVehicles(filterVehicle);
            var okResult = sut as OkObjectResult;

            //Assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
        }