public void ShouldDeleteClient() { vehicleRepositoryMock.Setup(x => x.Find(It.IsAny <int>())).Returns(new Vehicle { Id = 1 }); var response = vehicleService.Delete(1); vehicleRepositoryMock.Verify(x => x.Delete(It.IsAny <Vehicle>()), Times.Once); repositoryMock.Verify(x => x.Save(), Times.Once); Assert.False(response.HasErrors()); Assert.AreEqual(response.Messages.Count(x => x.Code == Constants.VEHICLE_DELETED), 1); }
public async void Delete_InvalidReturnsBadRequest() { // arrange var vehicle = context.Vehicles.First(); ICommandFactory <Vehicle> commandFactory = new CommandFactory <Vehicle>(); var validationServiceMoq = new Mock <IValidationService>(); validationServiceMoq.Setup(x => x.IsValidDelete(It.IsAny <Vehicle>())) .ReturnsAsync(false); var makeServiceMoq = new Mock <IMakeService>(); makeServiceMoq.Setup(x => x.Get(It.IsAny <string>())) .ReturnsAsync(new Result <Make>(ResultCode.Success, context.Makes.First())); var modelServiceMoq = new Mock <IModelService>(); modelServiceMoq.Setup(x => x.Get(It.IsAny <string>())) .ReturnsAsync(new Result <Model>(ResultCode.Success, context.Models.First())); var sut = new VehicleService(context, commandFactory, validationServiceMoq.Object, makeServiceMoq.Object, modelServiceMoq.Object); // act var result = await sut.Delete(vehicle.Id); // assert Assert.Equal(ResultCode.BadRequest, result); }
public async Task <IHttpActionResult> Delete(int Id) { try { if (Id <= 0) { return(BadRequest("El Id de vehiculo debe ser mayor que 0")); } using (VehicleService Service = new VehicleService()) { if (await Service.Delete(Id)) { return(Ok()); } else { return(BadRequest("No se encontro el Id de vehiculo")); } } } catch (Exception ex) { return(new HttpActionResult(HttpStatusCode.InternalServerError, ex.Message)); } }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IVehicleService, IVehicleRepository>(); var model = new ApiVehicleServerRequestModel(); var validatorMock = new Mock <IApiVehicleServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new VehicleService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALVehicleMapperMock, mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock, mock.DALMapperMockFactory.DALVehicleOfficerMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehicleDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public override object HandleCommand() { bool result = false; switch (DataPacket.Command.TypeData) { case TypeData.Employee: EmployeeService employeeService = new EmployeeService(); result = employeeService.Delete(DataPacket.Data as string); break; case TypeData.AdministrativeEmployee: AdministrativeEmployeeService administrativeEmployeeService = new AdministrativeEmployeeService(); result = administrativeEmployeeService.Delete(DataPacket.Data as string); break; case TypeData.Route: RouteService routeService = new RouteService(); result = routeService.Delete(DataPacket.Data as string); break; case TypeData.Vehicle: VehicleService vehicleService = new VehicleService(); result = vehicleService.Delete(DataPacket.Data as string); break; case TypeData.Ticket: TransportFormService transportFormService = new TransportFormService(); result = transportFormService.DeleteTicket(DataPacket.Data as string); break; } return(result ? ServerAnswer.SuccessfullyRemoved : ServerAnswer.DeletionFailed); }
public void DeleteVehicle() { var vehicle = vehicleService.GetByChassis(12345); vehicleService.Delete(vehicle.Id); var vehicleRetrieve = vehicleService.GetByChassis(12345); Assert.IsNull(vehicleRetrieve); }
public void DeleteTest() { using (VehicleService service = new VehicleService()) { List <VehicleModel> ListVehicle = service.Get().Result; bool Ok = service.Delete(ListVehicle[0].Id).Result; Assert.IsTrue(Ok); } }
public ActionResult ConfirmDelete(string id) { int i = 0; i = vehicleService.Delete(id); if (i != 0) { TempData["message"] = "Successfully Deleted"; } return(RedirectToAction("AllVehicle", "Vehicle")); }
public IActionResult Delete(int id) { _authorizer.RequireVehicleAutorization( id, _httpContextAccessor.HttpContext.User.Claims.Single(c => c.Type == UserClaimTypes.CompanyId).Value ); _vehicleService.Delete(id); _databaseManager.Commit(); return(RedirectToAction("Index")); }
public IActionResult DeleteVehicle([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _vehicleService.Delete(id); return(Ok()); }
public void Delete() { try { VehicleService vehicleService = new VehicleService(); vehicleService.Delete(this); } catch (Exception ex) { throw (ex); } }
public ActionResult Delete(int id, IFormCollection collection) { try { VehicleService.Delete(id); return(RedirectToAction(nameof(Index))); } catch { var item = VehicleService.GetDetail(id); return(View(item)); } }
public ActionResult Delete(Vehicle vehicle) { try { Response resp = VehicleService.Delete(vehicle.Id); ViewBag.Response = resp; DropdownViewBag(); return(RedirectToAction("Index")); } catch { DropdownViewBag(); return(RedirectToAction("Index")); } }
public async Task <IActionResult> Delete(Guid VehicleID) { var vehicle = await vehicleService.GetVehicles().Where(w => w.VehicleId.Equals(VehicleID)).FirstOrDefaultAsync(); if (vehicle == null) { return(RedirectToAction("Index", new IndexViewModel() { Message = "Invalid ID" })); } await vehicleService.Delete(VehicleID); return(RedirectToAction("Index")); }
public async Task Delete_WhenDeleteAVehicle_ShouldNotExistsInDB() { _dbContext.Vehicles.Add(new Vehicle { Description = "VW Golf", PricePerDay = 10 }); _dbContext.Vehicles.Add(new Vehicle { Description = "Ford Focus", PricePerDay = 12 }); await _dbContext.SaveChangesAsync(); var deletedVehicleDto = await _sut.Delete(2); deletedVehicleDto.Description.Should().Be("Ford Focus"); deletedVehicleDto.PricePerDay.Should().Be(12); var Vehicles = await _dbContext.Vehicles.ToListAsync(); Vehicles.Should().HaveCount(1); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IVehicleService, IVehicleRepository>(); var model = new ApiVehicleServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new VehicleService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VehicleModelValidatorMock.Object, mock.DALMapperMockFactory.DALVehicleMapperMock, mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock, mock.DALMapperMockFactory.DALVehicleOfficerMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.VehicleModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehicleDeletedNotification>(), It.IsAny <CancellationToken>())); }
public void DeleteVehicle() { vehicleService.Delete(2); Assert.AreEqual(1, db.Vehicles.Count()); }
static void Delete() { try { string consoleInput; Console.Clear(); Vehicle vehicle = new Vehicle(); vehicle.Chassis = new Chassis(); Console.WriteLine("DELETE A VEHICLE"); Trace.TraceInformation("User entered the Delete option"); Console.WriteLine(""); Console.WriteLine("Please input the Chassis Number:"); consoleInput = Console.ReadLine(); while (!uint.TryParse(consoleInput, out uint result)) { Console.WriteLine("Not a valid number, try again:"); consoleInput = Console.ReadLine(); } vehicle = vehicleService.GetByChassis(Convert.ToUInt32(consoleInput)); if (vehicle == null) { Console.WriteLine("There is no Vehicle with such a Chassis Number, please try again"); Console.ReadLine(); Console.Clear(); Menu(); } else { Console.WriteLine(""); Console.WriteLine("Are you sure you want to delete this vehicle? input yes or no"); consoleInput = Console.ReadLine(); while (string.IsNullOrWhiteSpace(consoleInput)) { Console.WriteLine("Are you sure you want to delete this vehicle? input yes or no"); consoleInput = Console.ReadLine(); } bool valid = false; bool delete = false; while (!valid) { switch (consoleInput) { case "yes": valid = true; delete = true; break; case "no": valid = true; delete = false; break; default: Console.WriteLine("Are you sure you want to delete this vehicle? input yes or no"); consoleInput = Console.ReadLine(); break; } } if (delete) { Trace.TraceInformation("User will delete the vehiche:"); Trace.TraceInformation(" Chassis Number: {0}", vehicle.Chassis.Number); Trace.TraceInformation(" Chassis Series: {0}", vehicle.Chassis.Series); Trace.TraceInformation(" Type: {0}", vehicle.VehicleType.Name); Trace.TraceInformation(" Color: {0}", vehicle.Color); vehicleService.Delete(vehicle.Id); Console.WriteLine("Vehicle deleted successfully! Please hit Enter to continue."); Trace.TraceInformation("Vehicle deleted successfully"); Console.ReadLine(); Console.Clear(); Menu(); } else { Console.Clear(); Menu(); } } } catch (Exception ex) { Console.WriteLine("There was an error while deleting vehicle. Please check log files"); Trace.TraceInformation("error while deleting vehicle: {0}", ex.Message); Console.ReadLine(); Console.Clear(); Menu(); } }
public void Delete(int id) { VehicleService.Delete(id); }