public async Task <Vehicle> Build(CreateVehicleCommand command) { Vehicle vehicle; try { VehicleTypes type; VehicleBody body; Enum.TryParse <VehicleTypes>(command.Vehicle, out type); body = await _bodyHandler.Build(command.Body); switch (type) { case VehicleTypes.BMW: vehicle = new BMW(command.Id, body, command.Color); break; case VehicleTypes.Ford: vehicle = new Ford(command.Id, body, command.Color); break; default: vehicle = null; break; } } catch (Exception exception) { return(null); } return(vehicle); }
public async Task <IActionResult> CreateVehicle([FromBody] CreateVehicleCommand command) { if (command.Validate()) { Vehicle vehicle = await _vehicleManufactureService.Build(command); if (vehicle == null) { return(BadRequest()); } await _vehicleManufactureService.QualityTestRun(vehicle); VehicleReleaseResponse response = new VehicleReleaseResponse { Release = await _vehicleManufactureService.Release(vehicle) }; return(new ContentResult { Content = JsonConvert.SerializeObject(response), StatusCode = 200, ContentType = "json/application" }); } return(BadRequest()); }
public async Task <IActionResult> CreateVehicle(CreateVehicleCommand request) { try { var result = await Mediator.Send(request); return(Ok(result)); } catch (VehicleExistsException) { return(BadRequest($"The vehicle with Matrícula '{request.Matricula}' already exists.")); } catch (DriverNotExistsException) { return(BadRequest($"The driver with DNI '{request.Dni}' does not exists.")); } catch (VehiclesLimitException) { return(BadRequest($"The driver with DNI '{request.Dni}' cannot have more vehicles")); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <IActionResult> Create([FromBody] CreateVehicleCommand createVehicleCommand) { logger.LogInformation("start : "); var vehicle = await Mediator.Send(createVehicleCommand); logger.LogInformation("added " + vehicle.VehicleId); return(CreatedAtAction(nameof(Get), new { id = vehicle.VehicleId }, null)); }
public void Execute_ShouldCreateNewVehicle_WhenPassedCorrectCommand() { var executionResult = new CreateVehicleCommand().Execute(new List <string>() { "4", "2" }); Assert.AreEqual(1, Engine.Vehicles.Count()); }
public void Execute_ShouldCreateTheCorrectNumberOfTyres_WhenPassedCommand() { var executionResult = new CreateVehicleCommand().Execute(new List <string>() { "4", "2" }); Assert.AreEqual(4, Engine.Vehicles[1].Tyres.Count()); }
public async Task <ActionResult <VehicleViewModel> > CreateVehicle([FromBody] CreateVehicleCommand command) { var newId = await _Mediator.Send(command); var newVehicle = await _Mediator.Send(new GetVehicleQuery() { Id = newId }); return(StatusCode(201, newVehicle)); }
public async Task <IActionResult> Post([FromBody] CreateVehicleViewModel viewModel) { if (!viewModel.Validate()) { return(await ResponseBase(viewModel.Notifications)); } var command = new CreateVehicleCommand(viewModel.Chassis, viewModel.Color, viewModel.Type); var result = await mediator.SendCommandAsync(command); return(await ResponseBase(result)); }
public async Task TestVehicleManufactureService_GivenWith_Vehicle_ShouldReturn_BMW() { CreateVehicleCommand createVehicleCommand = new CreateVehicleCommand() { Id = Guid.NewGuid(), Vehicle = "BMW", Body = "Normal", Color = "Blue" }; Vehicle vehicle = await _sut.Build(createVehicleCommand); Assert.True(vehicle.GetType() == typeof(BMW)); }
public async Task TestVehicleManufactureService_GivenWith_Vehicle_AND_QualityTestRun_ShouldBe_QualityApproved() { CreateVehicleCommand createVehicleCommand = new CreateVehicleCommand() { Id = Guid.NewGuid(), Vehicle = "BMW", Body = "Normal", Color = "Blue" }; Vehicle vehicle = await _sut.Build(createVehicleCommand); await _sut.QualityTestRun(vehicle); Assert.True(vehicle.IsQualityApproved()); }
public async Task TestVehicleControllerShouldWork() { CreateVehicleCommand createVehicleCommand = new CreateVehicleCommand() { Id = Guid.NewGuid(), Vehicle = "Ford", Body = "Normal", Color = "Blue" }; _service.Setup(x => x.Build(createVehicleCommand)); await _controller.CreateVehicle(createVehicleCommand); _service.Verify(x => x.Build(It.Is <CreateVehicleCommand>(command => command.Id == createVehicleCommand.Id))); }
public Task <HttpResponseMessage> Post(CreateVehicleCommand vehicle) { HttpResponseMessage response = new HttpResponseMessage(); try { _service.Create(vehicle); response = Request.CreateResponse(HttpStatusCode.OK, new { name = vehicle.Model }); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); }
public async Task <IActionResult> CreateVehicle([FromBody] VehicleDTO vehicleDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createVehicleCommand = new CreateVehicleCommand(vehicleDTO); logger.Information($"Sending CreateVehicleCommand with parameters {vehicleDTO.ManufacturerName} {vehicleDTO.Model} {vehicleDTO.Generation}"); var createdVehicleId = await mediator.Send(createVehicleCommand); if (createdVehicleId.HasNoValue) { return(BadRequest($"Cannot create vehicle")); } return(Created("", createdVehicleId.Value)); }
public async Task TestVehicleManufactureService_GivenWith_Vehicle_ShouldReturn_ReleasedDetails() { CreateVehicleCommand createVehicleCommand = new CreateVehicleCommand() { Id = Guid.NewGuid(), Vehicle = "BMW", Body = "Normal", Color = "Blue" }; Vehicle vehicle = await _sut.Build(createVehicleCommand); await _sut.QualityTestRun(vehicle); string result = await _sut.Release(vehicle); Assert.False(result == "No Release date yet."); Assert.Contains("year", result); }
public async Task <IHttpActionResult> Post(Guid ownerId, CreateVehicleCommand vehicle) { var owner = await _context.Owners.FindAsync(ownerId); if (owner == null) { return(NotFound()); } var entity = Mapper.Map <Vehicle>(vehicle); entity.Id = Guid.NewGuid(); entity.OwnerId = owner.Id; _context.Vehicles.Add(entity); await _context.SaveChangesAsync(); return(CreatedAtRoute("Vehicles.GetById", new { id = entity.Id }, Mapper.Map <VehicleViewModel>(entity))); }
//public BaseResponse Create(CreateVehicleRequest vehicleRequest) //{ // CreateVehicleCommand vehicleCommand = new CreateVehicleCommand // { // Volume = vehicleRequest.Volume, // Capacity = vehicleRequest.Capacity, // Image = vehicleRequest.Image, // LicensePlate = vehicleRequest.LicensePlate, // TypeVehicle = vehicleRequest.TypeVehicle // }; // var result = _bus.SendCommand(vehicleCommand); // Task<object> status = result as Task<object>; // var isComplete = (bool)status.Result; // if (isComplete) // { // return new BaseResponse(ResponseCode.OK.ToString(), code: ResponseCode.OK); // } // return new BaseResponse(ResponseCode.Fail.ToString(), code: ResponseCode.Fail); // //if (_notifications.HasNotifications()) // //{ // // Console.Write("ae oi"); // // if(_notifications.GetNotifications().Any(x=>x.TypeNotification == TypeNotification.Success)) // // { // // response.Code = (int)ResponseCode.OK; // // var message = _notifications.GetNotifications().FirstOrDefault().Value ?? ""; // // response.Message = message as string; // // } // // if (_notifications.GetNotifications().Any(x => x.TypeNotification == TypeNotification.Fail)) // // { // // response.Code = (int)ResponseCode.Fail; // // var message = _notifications.GetNotifications().FirstOrDefault().Value ?? ""; // // response.Message = message as string; // // } // //} //} public Task <StatusResponse> Create(CreateVehicleRequests vehicleRequest) { try { var existCode = _vehicleService.checkExist(vehicleRequest.Code); if (existCode) { return(Task.FromResult(new StatusResponse { OK = false, Content = "Trùng code" })); } CreateVehicleCommand vehicleCommand = new CreateVehicleCommand { LicensePlate = vehicleRequest.LicensePlate, Code = vehicleRequest.Code, MaxLoad = vehicleRequest.MaxLoad, Name = vehicleRequest.Name, Note = vehicleRequest.Note, TypeID = vehicleRequest.TypeID, DriverID = vehicleRequest.DriverID }; var result = _bus.SendCommand(vehicleCommand); Task <object> status = result as Task <object>; var id = (VehicleModel)status.Result; return(Task.FromResult(new StatusResponse { OK = true, Content = id.Id.ToString() })); } catch (Exception ex) { return(Task.FromResult(new StatusResponse { OK = false, Content = ex.Message })); } }
static void Main(string[] args) { IVehicleStorage storage = JsonStorage.LoadFromFile("/home/joernneumeyer/vehicles"); CarDealer dealer = new CarDealer(storage); IMenuCommand cmd; Vehicle v = new Car(); v.Price = 200; v.Vendor = "Skoda"; v.LicensePlate = "ABC"; dealer.AddVehicle(v); v = new Truck(); v.Price = 300; v.Vendor = "MAN"; v.LicensePlate = "YTG"; dealer.AddVehicle(v); bool repeat = true; do { Console.WriteLine("Please select an option:"); Console.WriteLine("q: Quit"); Console.WriteLine("1: Add a new vehicle"); Console.WriteLine("2: List all available vehicles"); Console.WriteLine("3: Show number of available vehicles"); Console.WriteLine("4: Show total value of all vehicles"); // Console.WriteLine("5: Show price of vehicle by id"); Console.WriteLine("6: Increase all prices by percentage"); Console.WriteLine("7: Search for vehicle in price range"); string choice = Console.ReadLine(); switch (choice) { case "1": cmd = new CreateVehicleCommand(); break; case "2": cmd = new PrintVehiclesCommand(); break; case "3": cmd = new ShowNumberOfAllVehicles(); break; case "4": cmd = new ShowTotalValueOfAllVehicles(); break; case "6": cmd = new IncreasePricesCommand(); break; case "7": cmd = new SearchVehicleInPriceRangeCommand(); break; case "q": cmd = null; repeat = false; break; default: cmd = null; break; } if (cmd != null) { cmd.Execute(dealer); Console.Write("\r\n\r\nPress enter..."); Console.ReadLine(); Console.Clear(); } } while (repeat); }
public async Task <IActionResult> CreateVehicle([FromBody] CreateVehicleCommand input) { var isCreated = await _mediator.Send(input); return(Ok(isCreated)); }