Пример #1
0
        public ActionResult AddVehicle(string vehicle, string type)
        {
            try
            {
                switch (type)
                {
                //Deserialize object myself since it can be multiple cases
                case "Truck":
                    Truck truck = JsonConvert.DeserializeObject <Truck>(vehicle);
                    _vehicleService.AddVehicle(truck);
                    break;

                case "Car":
                    Car car = JsonConvert.DeserializeObject <Car>(vehicle);
                    _vehicleService.AddVehicle(car);
                    break;

                case "Motorbike":
                    Motorbike motorbike = JsonConvert.DeserializeObject <Motorbike>(vehicle);
                    _vehicleService.AddVehicle(motorbike);
                    break;

                default:
                    return(BadRequest("Not Accepted Type"));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest("Error occurred :" + ex.Message));
            }
        }
Пример #2
0
        public void AddVehicleTest(Vehicle vehicle)
        {
            var             mockRep        = new Mock <IVehicleRepository>();
            IVehicleService vehicleService = new VehicleService(mockRep.Object);

            vehicleService.AddVehicle(vehicle);
            mockRep.Verify(x => x.Create(vehicle), Times.Once);
        }
Пример #3
0
 public IActionResult Create([Bind("ID,Model,Class,Year,Brand,Available")] Vehicle vehicle)
 {
     if (ModelState.IsValid)
     {
         _vehicleService.AddVehicle(vehicle);
         _vehicleService.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(vehicle));
 }
Пример #4
0
        public void AddVehiclerWithIDThrowsException()
        {
            var             moqRep         = new Mock <IVehicleRepository>();
            IVehicleService vehicleService = new VehicleService(moqRep.Object);

            Vehicle newVehicle = new Vehicle()
            {
                ID = 1
            };
            Vehicle newVehicle2 = new Vehicle()
            {
                ID = -1
            };

            Exception e  = Assert.Throws <InvalidDataException>(() => vehicleService.AddVehicle(newVehicle));
            Exception e2 = Assert.Throws <InvalidDataException>(() => vehicleService.AddVehicle(newVehicle2));

            Assert.Equal("Cannot add vehicle with ID!", e.Message);
            Assert.Equal("Cannot add vehicle with ID!", e2.Message);
        }
Пример #5
0
        public void AddVehicleWithoutTypeThworsException()
        {
            var             moqRep         = new Mock <IVehicleRepository>();
            IVehicleService vehicleService = new VehicleService(moqRep.Object);

            Vehicle newVehicle = new Vehicle()
            {
                UniqueID = "21341-a", Brand = "BMW", Type = null
            };
            Vehicle newVehicle2 = new Vehicle()
            {
                UniqueID = "21341-a", Brand = "BMW", Type = ""
            };



            Exception e  = Assert.Throws <InvalidDataException>(() => vehicleService.AddVehicle(newVehicle));
            Exception e2 = Assert.Throws <InvalidDataException>(() => vehicleService.AddVehicle(newVehicle2));

            Assert.Equal("Cannot add vehicle without type!", e.Message);
            Assert.Equal("Cannot add vehicle without type!", e2.Message);
        }
Пример #6
0
        public void AddMethod_ShouldThrowError_WhenNullIsPassedAsAParameter()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);
            //When

            //Then
            Action action = () => vehicleInventoryService.AddVehicle(null);

            action.Should().Throw <System.ArgumentNullException>()
            .WithMessage("The vehicle you are trying to add is null (Parameter 'vehicle')");
        }
Пример #7
0
        protected async Task HandleValidSubmit()
        {
            Vehicle result = null;

            if (Vehicle.VehicleId != 0)
            {
                result = await VehicleService.UpdateVehicle(Vehicle);
            }
            else
            {
                result = await VehicleService.AddVehicle(Vehicle);
            }
            if (result != null)
            {
                NavigationManager.NavigateTo("/");
            }
        }
Пример #8
0
        public void AddVehicle_ShouldAddVehicleToDatabase()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);
            //When
            var vehicle = new Vehicle()
            {
                Id = 1, Make = "Tesla", Model = "XXX", Year = 2022, VinNumber = "abcxyz123", MarketValue = 23000
            };

            vehicleInventoryService.AddVehicle(vehicle);
            var result = databaseContext.VehicleInventory.FirstOrDefault(s => s.Id == vehicle.Id);

            //Then
            result.Should().Be(vehicle);
        }
Пример #9
0
        public JsonResult AddVehicle(string manufacturer, string model, int year, string color, string category, string fuelType, string plate, string rate, IFormFile imageFile)
        {
            string location = "/Vehicle Images";
            string dbName   = null;

            dbName = _fileUploader.UploadFileAsync(imageFile, model, location).Result;

            if (dbName != null)
            {
                Manufacturer man = _manufacturerService.GetFromName(manufacturer);

                if (man == null)
                {
                    _manufacturerService.AddManufacturer(new Manufacturer
                    {
                        ManufacturerName = manufacturer
                    });

                    man = _manufacturerService.GetFromName(manufacturer);
                }

                Vehicle vehicle = new Vehicle
                {
                    Manufacturer = man,
                    Model        = model,
                    Year         = year,
                    Color        = color,
                    Category     = category,
                    FuelType     = fuelType,
                    PlateNumber  = plate,
                    Rate         = Double.Parse(rate),
                    ImageUrl     = dbName
                };

                _vehicleService.AddVehicle(vehicle);

                return(Json("Success"));
            }

            return(Json("Failure"));
        }
Пример #10
0
        private void button14_Click(object sender, EventArgs e)
        {
            var addVehicle = GetVehicleFromAddScreen();

            if (addVehicle == null)
            {
                MessageBox.Show("Sprawdź czy wymagane pola są wypełnione poprawnymi danymi!");
                return;
            }
            var isAdd = VehicleService.AddVehicle(addVehicle);

            if (isAdd)
            {
                MessageBox.Show("Dodano pojazd.");
                ClearVehicleFromAddScreen();
            }
            else
            {
                MessageBox.Show("Błąd dodania pojazdu!");
            }
        }
Пример #11
0
        public void AddVehicle_Success_Test()
        {
            // Arrange
            VehicleDTO dto = SampleVehicleDTO(1);

            // create mock for repository
            var mock = new Mock <IVehicleRepository>();

            mock.Setup(s => s.AddVehicle(Moq.It.IsAny <R_Vehicle>())).Returns(1);

            // service
            VehicleService vehicleService = new VehicleService();

            VehicleService.Repository = mock.Object;

            // Act
            int id = vehicleService.AddVehicle(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.VehicleId);
        }
Пример #12
0
        public void AddVehicle_adds_the_vehicle_with_properties()
        {
            //given
            var sut = new VehicleService(vehicleStrategyContext, dbService, vehicleConverter);

            JObject carObject = JObject.FromObject(new Car()
            {
                Make     = "JEEP",
                Id       = 1,
                Model    = "Grand Cherokee",
                Doors    = 5,
                Wheels   = 6,
                BodyType = "SUV",
                Engine   = "1000CC"
            });

            //when
            var result = sut.AddVehicle(carObject);

            //then
            Assert.IsAssignableFrom <string>(result.Result);
        }
Пример #13
0
        public ActionResult AddNewVehicle(AddVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var vehicle = new VehicleMD();
                vehicle.Type        = model.Type;
                vehicle.Number      = model.Number;
                vehicle.CompanyId   = Convert.ToInt32(User.Identity.GetUserId());
                vehicle.CreatedById = Convert.ToInt32(User.Identity.GetUserId());
                vehicle.CreatedDate = DateTime.Now;

                var result = _vehicleService.AddVehicle(vehicle);
                if (result.HasErrors)
                {
                    model.HasErrorMessage = result.HasErrors;
                    model.MessageType     = result.ResultMessages.FirstOrDefault().MessageType;
                    model.Message         = result.ResultMessages.FirstOrDefault().Message;
                    return(View(model));
                }
            }
            return(View());
        }
Пример #14
0
        public async void AddVehicle()
        {
            var repo = new Mock <IVehicleRepository>();
            var uow  = new Mock <IUnitOfWork>();

            string registration = "AA11AA";
            string vin          = "123456789AAAAAAAA";
            string entranceDate = "27/01/1978";
            string vehicleType  = "vehicleType1";


            var vehicle = new Vehicle(registration, vin, entranceDate, vehicleType);

            var vehicleDTO = new VehicleDTO(vehicle.Id.AsGuid(), registration, vin, entranceDate, vehicleType);

            repo.Setup(_ => _.AddAsync(vehicle)).ReturnsAsync(vehicle);

            var service = new VehicleService(repo.Object, uow.Object);

            var actual = await service.AddVehicle(vehicleDTO);

            Assert.Equal(vehicleDTO, actual);
        }
Пример #15
0
        public void AddVehicle_adds_the_vehicle_with_properties()
        {
            //given
            moqVehicleConverter.Setup(m => m.Convert(It.IsAny <JObject>())).Returns(new Car());
            moqDbService.Setup(m => m.AddVehicle(It.IsAny <Vehicle>())).Returns(Task.FromResult <string>("success"));

            var     sut       = new VehicleService(moqVehicleStrategyContext.Object, moqDbService.Object, moqVehicleConverter.Object);
            JObject carObject = JObject.FromObject(new Car()
            {
                Make     = "JEEP",
                Id       = 1,
                Model    = "Grand Cherokee",
                Doors    = 5,
                Wheels   = 6,
                BodyType = "SUV",
                Engine   = "1000CC"
            });

            //when
            var result = sut.AddVehicle(carObject);

            //then
            Assert.IsAssignableFrom <string>(result.Result);
        }
Пример #16
0
        private async void Create_Button(object sender, RoutedEventArgs e)
        {
            var VehicleAddModel = new AddVehicle
            {
                temp     = int.Parse(TempTextBox.Text),
                humidity = int.Parse(HumidTextBox.Text),
            };
            //var newLocation = new Location
            //{

            //     latitude = int.Parse(LatTextBox.Text),
            //     longitude = int.Parse(LongTextBox.Text),
            // };
            var addVehicleResponse = await VehicleService.AddVehicle(VehicleAddModel);

            //var addVehicleLocation = await VehicleService.AddLocation(newLocation);
            if (addVehicleResponse != null)
            {
                MessageBox.Show($"New Vehicle Record has been added.");
            }
            GetAllVehiclesTemp();
            GetAllVehiclesHumid();
            GetAllVehiclesLocation();
        }
Пример #17
0
        public void Register()
        {
            Console.Clear();

            Console.WriteLine("<------REGISTER------>");
            User user = new User();

            user.Email = commonMethods.ReadString("Enter your email : ");
            bool isValidEmail = commonMethods.IsValidEmail(user.Email);

            while (!isValidEmail)
            {
                user.Email   = commonMethods.ReadString("Please enter a valid email : ");
                isValidEmail = commonMethods.IsValidEmail(user.Email);
            }
            bool isExistingUser = userService.IsExistingUser(user.Email);

            if (isExistingUser)
            {
                Console.WriteLine("You already have an account with us!!");
                int Choice = commonMethods.ReadInt("Do you want to login to that account : 1. Yes 2. No >> ");
                TakeAction(Choice);
            }

            user.Id   = Guid.NewGuid().ToString();
            user.Name = commonMethods.ReadString("Enter your name : ");

            user.PhoneNumber = commonMethods.ReadString("Enter your Phone Number : ");
            bool isValidPhoneNumber = commonMethods.IsValidPhoneNumber(user.PhoneNumber);

            while (!isValidPhoneNumber)
            {
                user.PhoneNumber   = commonMethods.ReadString("Please enter a valid phone number : ");
                isValidPhoneNumber = commonMethods.IsValidPhoneNumber(user.PhoneNumber);
            }
            user.Address = commonMethods.ReadString("Enter your address : ");
            int gender = commonMethods.ReadInt("Please choose your Gender : 1. Female 2. Male >> ");

            if (gender == 1)
            {
                user.Gender = (Gender)0;
            }
            else
            {
                user.Gender = (Gender)1;
            }
            user.Password = commonMethods.ReadString("Enter your Password : "******"Re-enter your password : "******"Your password and re-enter password did not match!!");
                Console.WriteLine("Re-enter your password");
                user.Password   = commonMethods.ReadString("Enter your Password : "******"Re-enter your password : "******"Do you want to add your vehicle : 1. Yes 2. No >> ");

            if (addVehicle == 1)
            {
                IVehicleService vehicleService = new VehicleService();
                Vehicle         vehicle        = new Vehicle();
                vehicle.UserId = user.Id;
                vehicle.Model  = commonMethods.ReadString("Enter your Vehicle Model : ");
                vehicle.Number = commonMethods.ReadString("Enter your Vehicle Number : ");
                vehicleService.AddVehicle(vehicle);
            }

            currentUser = user;
            Console.WriteLine("Registration successful!!");
            commonMethods.FurtherAction(1);
        }
Пример #18
0
        private void LoadVehiclesImportsBtns()
        {
            int count = 0;

            foreach (var item in this.importerService.AllOfType <IVehicleImportOffline>())
            {
                Button button = CreateButton();
                button.Name     = item.Name;
                button.Text     = item.Name;
                button.Location = count == 0 ? new System.Drawing.Point(436, 178) : new System.Drawing.Point(436, 215);
                count++;

                button.Click += (sender, e) =>
                {
                    try
                    {
                        var vehicles         = item.ImportVehicles();
                        var importedVehicles = 0;
                        foreach (var vehicle in vehicles)
                        {
                            vehicleService.AddVehicle(vehicle);
                            importedVehicles++;

                            UserDTO user = new UserDTO();
                            user.UserName = this.userLogged.FullName;
                            LogEvent log = new VehicleImportEvent(user, vehicle);
                            VehicleTrackingLog.GetInstance().WriteEvent(log);
                            this.logs.LoadLogs();
                        }
                        MessageBox.Show("Se han importado " + importedVehicles + " vehículos");
                        this.init();
                    }
                    catch (VehicleNullAttributesException)
                    {
                        MessageBox.Show(
                            "Los vehiculos que se intentan importar no tienen todos los datos",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    } catch (VehicleVinDuplicatedException)
                    {
                        MessageBox.Show(
                            "Se encontraron vehículos ya registrados",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (JsonReaderException)
                    {
                        MessageBox.Show(
                            "El archivo no tiene un formato de json correcto",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show(
                            "El archivo no tiene un formato de xml correcto",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (ArgumentException)
                    {
                        // No se hace nada, ya que se cierra el importador de archivos
                    }
                };
                this.Controls.Add(button);
            }
        }