public void WhenVehicleAdded_ThenPersists() { int userId = this.defaultTestUser.UserId; var repository = new VehicleRepository(); Vehicle vehicle1 = new Vehicle { Name = "Vehicle1" }; Vehicle vehicle2 = new Vehicle { Name = "Vehicle2" }; repository.Create(userId, vehicle1); repository.Create(userId, vehicle2); // I use a new context and repository to verify the data was stored var repository2 = new VehicleRepository(); var retrievedVehicles = repository2.GetVehicles(userId); Assert.NotNull(retrievedVehicles); List <Vehicle> actualList = new List <Vehicle>(retrievedVehicles); Assert.Equal(2, actualList.Count); Assert.Equal(vehicle1.Name, actualList[0].Name); Assert.Equal(vehicle2.Name, actualList[1].Name); }
public async void Should_RequestSuccessful_Model() { var data = new List <Vehicle> { new Vehicle { Plate = "ABC1111" }, new Vehicle { Plate = "ABC2222" }, new Vehicle { Plate = "ABC3333" }, }.AsQueryable(); var mockSet = new Mock <DbSet <Vehicle> >(); mockSet.As <IQueryable <Vehicle> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Vehicle> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Vehicle> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Vehicle> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <IVehicleContext>(); mockContext.Setup(c => c.Vehicles).Returns(mockSet.Object); var repo = new VehicleRepository(mockContext.Object); var d = await repo.Get(); Assert.Equal(3, d.Count); Assert.Equal("ABC1111", d[0].Plate); Assert.Equal("ABC2222", d[1].Plate); Assert.Equal("ABC3333", d[2].Plate); }
public static void Load() { try { using (VehicleRepository db = new VehicleRepository()) { List <VehicleEF> vehs = db.vehicles.Include(v => v.entity).Include(i => i.entity.items).ToList(); foreach (VehicleEF v in vehs) { Game.Vehicle gv = new Game.Vehicle(v); SharpBridge.Vehicle spawn = SharpBridge.Entities.createVehicle(v.model, gv.GetStoredPos(), gv.GetStoredRot(), gv.vehicle.color, gv.vehicle.color, gv.vehicle.color, gv.vehicle.color, 1); Game.VehiclesManager.Add(spawn.getId(), gv); } } } catch (DbUpdateException e) { Console.WriteLine(e.ToString()); SharpBridge.Log.Write(e.ToString()); } }
public void WhenVehicleModifiedInSameContext_ThenPersistsChange() { int userId = this.defaultTestUser.UserId; var repository = new VehicleRepository(); Vehicle vehicle = new Vehicle { Name = "Vehicle", UserId = userId }; repository.Create(userId, vehicle); // I use a new context and repository to verify the data was stored var repositoryForUpdate = new VehicleRepository(); var retrievedVehicle = repositoryForUpdate.GetVehicles(userId).First(); retrievedVehicle.Name = "Updated Vehicle Name"; repositoryForUpdate.Update(retrievedVehicle); int updatedVehicleId = retrievedVehicle.VehicleId; var repositoryForVerify = new VehicleRepository(); var updatedVehicle = repositoryForVerify.GetVehicle(userId, updatedVehicleId); Assert.Equal("Updated Vehicle Name", updatedVehicle.Name); }
public void Save_GivenNullItem_ShouldThrowArgumentNullException() { Vehicle nullVehicle = null; var sut = new VehicleRepository(); Should.Throw <ArgumentNullException>(() => sut.Save(nullVehicle)); }
protected void btnSave_Click(object sender, EventArgs e) { int givenID = Parsers.ParseInt(txtVehicleID.Value); if (givenID > 0) { VehicleRepository vr = new VehicleRepository(); Vehicle vehicle = vr.Get(givenID); if (vehicle != null) { // Update the vehicle object vehicle.Name = txtVehicleName.Text.Trim(); vehicle.Description = txtDescription.Text.Trim(); vehicle.IsInService = chkActive.Checked; vehicle.Plate = txtVehiclePlate.Text.Trim(); vehicle.VIN = txtVehicleVIN.Text.Trim(); // Send the updated vehicle object back to the database vr.Update(vehicle); // Redirect RedirectToViewPage(vehicle.ID); } } }
public ActionResult AddNew(Vehicle vehicle) { vehicle.createddate = DateTime.Now; vehicle.companyid = 0; vehicle.descrition = ""; vehicle.manufacturername = ""; vehicle.manufactureryear = DateTime.Now; vehicle.modifydate = DateTime.Now; vehicle.rcbookcopypath = vehicle.rcbookcopypath == "" ? "NA" : vehicle.rcbookcopypath; vehicle.registrationdate = DateTime.Now; vehicle.userid = this.UserId; vehicle.vehicleid = 0; string msg = "Error process request, please try after some time."; if (ModelState.IsValid) { VehicleRepository vehicleRepository = new VehicleRepository(this.UserId); var v = vehicleRepository.VehicleRegistration(vehicle, out msg).Response; if (v.vehicleid > 0) { UploadRCPhoto(vehicle, v.vehicleid); return(Json(new { success = true, responseText = msg }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false, responseText = msg }, JsonRequestBehavior.AllowGet)); }
public void GetByIdTestFail() { var vehiclerepo = new VehicleRepository(vehiclecontextmock.Object); var vehicleobj = vehiclerepo.GetById(10); Assert.IsNull(vehicleobj); }
// GET: QTTrucks public ActionResult Index() { VehicleRepository vehicleRepository = new VehicleRepository(this.UserId); var vl = vehicleRepository.GetVehicleListByUserId(this.UserId); return(View(vl.Response)); }
public ActionResult Edit(long Id) { VehicleRepository vehicleRepository = new VehicleRepository(this.UserId); var vehicle = vehicleRepository.GetVehicleById(Id).Response; return(View(vehicle)); }
public IActionResult Add(Vehicle vehicle) { if (vehicle.Type.Equals("1")) { vehicle.Type = "Otomobil"; } else if (vehicle.Type.Equals("2")) { vehicle.Type = "Kamyonet"; } else if (vehicle.Type.Equals("3")) { vehicle.Type = "Kamyon"; } else if (vehicle.Type.Equals("4")) { vehicle.Type = "Otobüs"; } else if (vehicle.Type.Equals("5")) { vehicle.Type = "Motosiklet"; } VehicleRepository.AddVehicle(vehicle); return(RedirectToAction("Index")); }
public UnitOfWork(VehicleDbContext context) { _context = context; Vehicles = new VehicleRepository(_context); VehicleOwners = new VehicleOwnersRepository(_context); }
public async Task <ActionResult> GetRegisterVehicles() { var userId = User.Identity.GetUserId(); var vehicles = await VehicleRepository.GetVehiclesByUserId(userId); return(View(vehicles)); }
public void CanAddVehicle() { AddVehicleObject vehicle = new AddVehicleObject() { VIN = "1GC0KXCG9DF173160", Interior = "White", Transmission = "Automatic", Mileage = "11223", MSRP = 12000, SalePrice = 10455, Color = "Black", BodyStyle = "Sedan", Description = "Nice well maintained and hardly driven car", Make = "Dodge", Model = "Charger", Type = "Used", Year = 2001 }; var repo = new VehicleRepository(); repo.AddVehicle(vehicle); // Now check in the DB if the record was added }
public async Task <List <VehicleResource> > GetFeatures(VehicleQueryResource filterResource) { var filter = Mapper.Map <VehicleQueryResource, VehicleQuery>(filterResource); var vehicles = await VehicleRepository.GetAll(filter); return(Mapper.Map <List <Vehicle>, List <VehicleResource> >(vehicles)); }
public void GetAllTestFail() { var vehiclerepo = new VehicleRepository(vehiclecontextmock.Object); var vehiclelist = vehiclerepo.GetAll(); Assert.AreNotEqual(2, vehiclelist.Count()); }
public async Task <IActionResult> UpdateVehicle(int id, [FromBody] SaveVehicleResource vehicleResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var vehicle = await VehicleRepository.GetVehicle(id); if (vehicle == null) { return(NotFound()); } Mapper.Map <SaveVehicleResource, Vehicle>(vehicleResource, vehicle); vehicle.LastUpdate = DateTime.Now; await UnitOfWork.CompleteAsync(); vehicle = await VehicleRepository.GetVehicle(vehicle.Id); var result = Mapper.Map <Vehicle, VehicleResource>(vehicle); return(Ok(result)); }
public dynamic GetAllVehicle() { VehicleRepository repo = new VehicleRepository(); var listVehicle = repo.GetAll(); return(listVehicle); }
public void SubscribeToRecyclingterDeletedQueue() { _connection = _factory.CreateConnection(); _channel = _connection.CreateModel(); _channel.QueueDeclare(DeletedQueueName, true, false, false, null); _channel.BasicQos(0, 1, false); var consumer = new EventingBasicConsumer(_channel); _channel.BasicConsume(DeletedQueueName, false, consumer); consumer.Received += async(ch, ea) => { var message = (RecyclingCenter)ea.Body.DeSerialize(typeof(RecyclingCenter)); var repository = new VehicleRepository(); var vehicles = await repository.GetAllVehicles(message.Id); foreach (var vehicle in vehicles) { await repository.DeleteVehicle(vehicle.Id); } _channel.BasicAck(ea.DeliveryTag, false); }; }
public void ScheduleTestsAllInOneMethod() { using (TransactionScope scope = new TransactionScope()) { var fixture = new Fixture(); IVehicleRepository vRep = new VehicleRepository(); var autoVehicle = fixture.Create <Vehicle>(); vRep.Save(autoVehicle); ITaskRepository tRep = new TaskRepository(); var autoTask = fixture.Create <DAL.Models.Task>(); tRep.Save(autoTask); IScheduleRepository sRep = new ScheduleRepository(); var autoSchedule = fixture.Create <Schedule>(); autoSchedule.Vehicle = autoVehicle; autoSchedule.Task = autoTask; autoSchedule.VehicleId = autoVehicle.VehicleId; autoSchedule.TaskId = autoTask.TaskId; sRep.Save(autoSchedule); var insertedSchedule = sRep.GetById(autoSchedule.ScheduleId); Assert.AreEqual(insertedSchedule.Vehicle.Make, autoSchedule.Vehicle.Make); Assert.AreEqual(insertedSchedule.Vehicle.VehicleType.VehicleTypeName, autoSchedule.Vehicle.VehicleType.VehicleTypeName); Assert.AreEqual(insertedSchedule.Task.TaskName, autoSchedule.Task.TaskName); IEnumerable <Schedule> sList = sRep.GetAll().Where(sc => sc.ScheduleId == autoSchedule.ScheduleId);; Assert.AreEqual(sList.Count(), 1); sRep.Delete(autoSchedule); var deletedSchedule = sRep.GetById(autoSchedule.ScheduleId); Assert.IsNull(deletedSchedule); } }
public async Task <IActionResult> AddVehicle(VehicleModel vehicle) { Title = "Add Vehicle"; if (ModelState.IsValid) { if (vehicle.vehiclePhoto != null) { string folder = "vehicles/"; folder += Guid.NewGuid().ToString() + vehicle.vehiclePhoto.FileName; string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder); await vehicle.vehiclePhoto.CopyToAsync(new FileStream(serverFolder, FileMode.Create)); vehicle.vehicleURI = folder; } await Db.Connection.OpenAsync(); var query = new VehicleRepository(Db); bool IsSuccess = await query.AddNewVehicle(vehicle); if (IsSuccess) { return(RedirectToAction(nameof(AddVehicle), new { IsSuccess })); } } ViewBag.IsSuccess = false; ViewBag.fuelType = getFuelType(); return(View()); }
public Rezerv CancelRezervVehicle(Rezerv rezervVehicle) { Rezerv rezerv = null; try { VehicleRepository vehicleRepository = new VehicleRepository(); Vehicle vehicle = vehicleRepository.SelectedByNumber(rezervVehicle.vehiclenumber); if (vehicle == null) { throw new Exception("CustomerBisuness::RentVehicle: Vehcile Is Not Found! \n"); } //Rezerv Update RezervRepository rezervRepository = new RezervRepository(); rezervVehicle.isactive = 0; rezervRepository.Update(rezervVehicle); //Rezerv Get rezerv = rezervRepository.SelectedByVehicleAndMember(rezervVehicle.vehiclenumber, rezervVehicle.membernumber); //Vehicle Update vehicle.istaken = 0; vehicleRepository.Update(vehicle); } catch (Exception ex) { throw new Exception("CustomerBisuness::RentVehicle: Error occured.\n", ex); } return(rezerv); }
public ActionResult GetAllVehicls() { using (VehicleRepository scoterRepo = new VehicleRepository()) { return(Json(scoterRepo.getAllForDash())); } }
public HomeController(ReservationRepository reservationRepo, VehicleRepository vehicleRepo, UserManager <ApplicationUser> userMgr, SignInManager <ApplicationUser> signInMgr) { _reservationRepository = reservationRepo; _vehicleRepository = vehicleRepo; _userManager = userMgr; _signInManager = signInMgr; }
public IVehicleServiceProvider GetServiceProvider(OrderType orderType) { IVehicleServiceProvider provider = null; IVehicleRepository vehicleRepository = new VehicleRepository(); switch (orderType) { case OrderType.Buy: provider = new PurchaseServiceProvider(vehicleRepository); break; case OrderType.Rent: provider = new RentServiceProvider(vehicleRepository); break; case OrderType.TestDrive: provider = new TestDriveServiceProvider(vehicleRepository); break; case OrderType.Maintainance: provider = new MaintainanceServiceProvider(vehicleRepository); break; default: throw new InvalidOrderException(Constants.ErrorMessage.InvalidOrder); } return(provider); }
public IHttpActionResult DVehicle(Vehicle Vehicle) { Vehicle vch = new VehicleRepository().FirstOrDefault(c => c.Id == Vehicle.Id); new VehicleRepository().Delete(Vehicle.Id); return(Ok()); }
public async Task VehicleRepository_NonExistent_Test() { var repository = new VehicleRepository(_context); repository.Get("1").ShouldThrow(typeof(KeyNotFoundException)); repository.Delete("1").ShouldThrow(typeof(KeyNotFoundException)); repository.Update("1", new Vehicle()).ShouldThrow(typeof(KeyNotFoundException)); }
public HomeController(UserManager <AppUser> userMgr, ReservationContactRepository rcr, ReservationRepository rp, ViewModelSesssionService vmss, VehicleRepository vrepo) { _userManager = userMgr; _reservationContactRepo = rcr; _reservationRepo = rp; _sessionService = vmss; _vehicleRepo = vrepo; }
public IHttpActionResult GetByArea(AreaModel areaModel) { using (VehicleRepository vehiclesRepo = new VehicleRepository()) { return(Ok(vehiclesRepo.GetAvilable())); } // return Ok(new { IsDone = true, Messages = areaModel.farLeft.lat }); }
public UnitOfWork(RaceManagerDbContext context) { _context = context; Races = new RaceRepository(_context); Drivers = new DriverRepository(_context); Vehicles = new VehicleRepository(_context); Users = new UserRepository(_context); }
public void WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection() { var repository = new VehicleRepository(); IEnumerable<Vehicle> actual = repository.GetVehicles(this.defaultTestUser.UserId); Assert.NotNull(actual); List<Vehicle> actualList = new List<Vehicle>(actual); Assert.Equal(0, actualList.Count); }
public void WhenVehicleAdded_ThenUpdatesRepository() { var repository = new VehicleRepository(); var initialCount = repository.All().Count(); var vehicle = new Vehicle {Name = "Vehicle"}; repository.Create(defaultTestUser.UserId, vehicle); var actualList = new VehicleRepository().All().ToList(); Assert.Equal(initialCount + 1, actualList.Count); Assert.Equal(vehicle.Name, actualList[initialCount].Name); }
private void InitializeFixture() { defaultTestUser = new User() { AuthorizationId = "TestAuthorizationId", DisplayName = "DefaultTestUser" }; var userRepository = new UserRepository(); userRepository.Create(defaultTestUser); int userId = defaultTestUser.UserId; var vehicleRepository = new VehicleRepository(); defaultVehicle = new Vehicle() { Name = "Test Vehicle" }; vehicleRepository.Create(defaultTestUser.UserId, defaultVehicle); }
public void WhenVehicleAdded_ThenPersists() { int userId = this.defaultTestUser.UserId; var repository = new VehicleRepository(); Vehicle vehicle1 = new Vehicle {Name = "Vehicle1"}; Vehicle vehicle2 = new Vehicle {Name = "Vehicle2"}; repository.Create(userId, vehicle1); repository.Create(userId, vehicle2); // I use a new context and repository to verify the data was stored var repository2 = new VehicleRepository(); var retrievedVehicles = repository2.GetVehicles(userId); Assert.NotNull(retrievedVehicles); List<Vehicle> actualList = new List<Vehicle>(retrievedVehicles); Assert.Equal(2, actualList.Count); Assert.Equal(vehicle1.Name, actualList[0].Name); Assert.Equal(vehicle2.Name, actualList[1].Name); }
public void WhenVehicleDeleted_ThenPersists() { int userId = this.defaultTestUser.UserId; var repository = new VehicleRepository(); Vehicle vehicle1 = new Vehicle {Name = "Vehicle1"}; repository.Create(userId, vehicle1); var retrievedVehicles = repository.GetVehicles(userId); Assert.Equal(1, retrievedVehicles.Count()); repository.Delete(retrievedVehicles.First().VehicleId); // I use a new context and repository to verify the vehicle was deleted var repository2 = new VehicleRepository(); var verifyVehicles = repository2.GetVehicles(userId); Assert.NotNull(retrievedVehicles); Assert.Equal(0, verifyVehicles.Count()); }
public void WhenGettingOtherUsersVehicle_ThenReturnsNull() { int userId = defaultTestUser.UserId; var repository = new VehicleRepository(); const int unknownId = 4200; var vehicle = new Vehicle {Name = "Vehicle"}; repository.Create(userId, vehicle); var repositoryForVerify = new VehicleRepository(); Assert.Null(repositoryForVerify.GetVehicle(unknownId, vehicle.VehicleId)); }
public void WhenVehicleModifiedInSameContext_ThenPersistsChange() { int userId = this.defaultTestUser.UserId; var repository = new VehicleRepository(); Vehicle vehicle = new Vehicle {Name = "Vehicle", UserId = userId}; repository.Create(userId, vehicle); // I use a new context and repository to verify the data was stored var repositoryForUpdate = new VehicleRepository(); var retrievedVehicle = repositoryForUpdate.GetVehicles(userId).First(); retrievedVehicle.Name = "Updated Vehicle Name"; repositoryForUpdate.Update(retrievedVehicle); int updatedVehicleId = retrievedVehicle.VehicleId; var repositoryForVerify = new VehicleRepository(); var updatedVehicle = repositoryForVerify.GetVehicle(userId, updatedVehicleId); Assert.Equal("Updated Vehicle Name", updatedVehicle.Name); }
public void WhenVehicleAdded_ThenUpdatesVehicleId() { const int userId = 999; var repository = new VehicleRepository(); var vehicle = new Vehicle {Name = "Vehicle"}; repository.Create(userId, vehicle); var retrievedVehicles = repository.GetVehicles(userId); Assert.NotNull(retrievedVehicles); var actualList = new List<Vehicle>(retrievedVehicles); Assert.Equal(1, actualList.Count); Assert.Equal(vehicle.VehicleId, actualList[0].VehicleId); }