public void AddDeletePlane_Returns_CreatedResult_And_Plane_ShoudBe_AddedTo_Database_And_Then_ShouldBe_Deleted() { // Arrange MSSQLContext context = new MSSQLContext(); PlaneTypesRepository planeTypesRepository = new PlaneTypesRepository(); PlanesRepository planesRepository = new PlanesRepository(); AircraftUnitOfWork uow = new AircraftUnitOfWork(planesRepository, planeTypesRepository, context); AircraftService service = new AircraftService(uow); PlanesController controller = new PlanesController(mapper.GetDefaultMapper(), service); // add act var newPlaneDTO = new PlaneDTO() { Lifetime = new TimeSpan(200, 0, 0, 0, 0), Name = "Bf-109g", ReleaseDate = new DateTime(1941, 1, 1, 0, 0, 0), FlightHours = 560, LastHeavyMaintenance = DateTime.Now, PlaneTypeId = 1 }; var addResult = controller.AddPlane(newPlaneDTO); // add assert Assert.IsInstanceOf <CreatedResult>(addResult); Assert.IsInstanceOf <PlaneDTO>((addResult as CreatedResult).Value); // delete act var addedPlaneDTO = (addResult as CreatedResult).Value as PlaneDTO; var deleteResult = controller.DeletePlane(addedPlaneDTO.Id); // delete assert Assert.IsInstanceOf <OkResult>(deleteResult); Assert.IsInstanceOf <NotFoundObjectResult>(controller.GetPlane(addedPlaneDTO.Id)); }
public void CreateEntity_Should_Create_plane_typeof_Plane() { // Arrange PlaneDTO planeDTO = new PlaneDTO { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; Plane plane = new Plane { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; var planeRepository = new FakeRepository <Plane>(); var planeService = new PlaneService(planeRepository); // Act planeService.CreateEntity(planeDTO); var result = planeRepository.Get(1); // Assert Assert.AreEqual(plane, result); }
//will write the departuring details to DB private void OnPlaneDeparturing(object sender, EventArgs e) { PlaneDTO plane = sender as PlaneDTO; //write the new departuring to DB: DepartureRepository.AddDeparture(plane.PlaneId); }
private void Create_Click(object sender, RoutedEventArgs e) { var turple = RenderCreate(); var btnCreate = turple.Item1; var name = turple.Item2; var timespan = turple.Item3; var createdat = turple.Item4; var types = turple.Item5; btnCreate.Click += async(object sen, RoutedEventArgs evArgs) => { var plane = new PlaneDTO() { Name = name.Text, LifeTime = timespan.Text, Created = createdat.Date.Value.Date.ToString(), TypePlaneId = ((PlaneTypeDTO)types.SelectedItem).Id }; try { await service.CreateAsync(plane); } catch (Exception) { } planesList.Add(plane); UpdateList(); SingleItem.Children.Clear(); }; }
public void UpdateEntity_Should_Update_plane_typeof_Plane() { // Arrange PlaneDTO planeDTO = new PlaneDTO { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; Plane plane = new Plane { Id = 1, ReleaseDate = new DateTime(2018, 07, 12), Name = "TY-143", PlaneTypeId = 1, Lifetime = new DateTime(2020, 07, 12) - new DateTime(2018, 07, 12) }; var planeRepository = A.Fake <IRepository <Plane> >(); A.CallTo(() => planeRepository.Get(A <int> ._)).Returns(new Plane { Id = 1 }); var planeService = new PlaneService(planeRepository); //Act planeService.UpdateEntity(1, planeDTO); var result = planeRepository.Get(1); // Assert Assert.AreEqual(plane, result); }
public async Task <IActionResult> OnPostCreatePlane() { string respone = "True"; MemoryStream stream = new MemoryStream(); Request.Body.CopyTo(stream); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { string requestBody = reader.ReadToEnd(); if (requestBody.Length > 0) { var obj = JsonConvert.DeserializeObject <PlaneDTO>(requestBody); if (obj != null) { PlaneDTO plane = new PlaneDTO(); // plane.PlaneId = obj.PlaneId; plane.SeatNum = obj.SeatNum; plane.MakerId = obj.MakerId.Substring(0, 3); await _services.addPlaneAsync(plane); } } } return(new JsonResult(respone)); }
public void UpdateEntity(int id, PlaneDTO planeDTO) { var plane = planeRepository.Get(id); if (plane == null) { throw new ValidationException($"Plane with this id {planeDTO.Id} not found"); } if (planeDTO.PlaneTypeId > 0) { plane.PlaneTypeId = planeDTO.PlaneTypeId; } if (planeDTO.Name != null) { plane.Name = planeDTO.Name; } if (planeDTO.Lifetime != TimeSpan.Parse("00:00:00")) { plane.Lifetime = planeDTO.Lifetime; } if (planeDTO.ReleaseDate != DateTime.MinValue) { plane.ReleaseDate = planeDTO.ReleaseDate; } planeRepository.Update(plane); }
public async Task UpdateEntityAsync(int id, PlaneDTO planeDTO) { var plane = await planeRepository.GetAsync(id); if (plane == null) { throw new ValidationException($"Plane with this id {id} not found"); } if (planeDTO.PlaneTypeId > 0) { plane.PlaneTypeId = planeDTO.PlaneTypeId; } if (planeDTO.Name != null) { plane.Name = planeDTO.Name; } if (planeDTO.Lifetime != TimeSpan.Parse("00:00:00")) { plane.Lifetime = planeDTO.Lifetime; } if (planeDTO.ReleaseDate != DateTime.MinValue) { plane.ReleaseDate = planeDTO.ReleaseDate; } await planeRepository.UpdateAsync(plane).ConfigureAwait(false); }
public async Task <IActionResult> Update(int id, [FromBody] PlaneDTO item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { item.Id = id; await service.GetById(id); await service.Update(item); await service.SaveChanges(); return(Ok(item)); } catch (NotFoundException e) { return(NotFound(e.Message)); } catch (Exception) { return(BadRequest()); } }
public void PlaneCreate() { PlaneService planeService = new PlaneService(unitOfWork); PlaneDTO planeDTO = new PlaneDTO() { Name = "test", Made = new DateTime(1, 2, 3), Exploitation = new TimeSpan(0, 1, 2), Type = new PlaneTypeDTO() { Model = "test", CarryCapacity = 12, Places = 15 } }; planeService.CreatePlane(planeDTO); Plane plane = fakePlaneRepository.Get(1); Assert.AreEqual(plane.Name, planeDTO.Name); Assert.AreEqual(plane.Made, planeDTO.Made); Assert.AreEqual(plane.Exploitation, planeDTO.Exploitation); Assert.AreEqual(plane.Type.Model, planeDTO.Type.Model); Assert.AreEqual(plane.Type.CarryCapacity, planeDTO.Type.CarryCapacity); Assert.AreEqual(plane.Type.Places, planeDTO.Type.Places); }
public async Task <IActionResult> ModifyPlane(long id, [FromBody] PlaneDTO plane) { if (!ModelState.IsValid) { return(BadRequest() as IActionResult); } if (!plane.PlaneTypeId.HasValue) { return(BadRequest("Plane type have to be defined!") as IActionResult); } var targetType = await service.GetPlaneTypeInfoAsync(plane.PlaneTypeId.Value); if (targetType == null) { return(NotFound($"Plane type with id = {plane.PlaneTypeId} not found!Plane not added!")); } var mPlane = mapper.Map <Plane>(plane); mPlane.Type = targetType; var entity = await service.ModifyPlaneInfoAsync(id, mPlane); return(entity == null?StatusCode(304) as IActionResult : Ok(mapper.Map <PlaneDTO>(entity))); }
//will write the arriving details to DB private void OnPlaneArriving(object sender, EventArgs e) { PlaneDTO plane = sender as PlaneDTO; //write the new arrival to DB: ArrivalRepository.AddArrival(plane.PlaneId); }
private void FCServiceProxy_OnAirportChanged(object sender, AirportEventArgs e) { StationZeroPlane = null; StationOnePlane = null; StationTwoPlane = null; StationThreePlane = null; StationFourPlane = null; StationFivePlane = null; StationSixPlane = null; StationSevenPlane = null; StationEightPlane = null; Airport = new ObservableCollection <PlaneDTO>(e.ChangedAirport.Planes); foreach (var plane in Airport) { switch (plane.StationId) { case 0: StationZeroPlane = plane; continue; case 1: StationOnePlane = plane; continue; case 2: StationTwoPlane = plane; continue; case 3: StationThreePlane = plane; continue; case 4: StationFourPlane = plane; continue; case 5: StationFivePlane = plane; continue; case 6: StationSixPlane = plane; continue; case 7: StationSevenPlane = plane; continue; case 8: StationEightPlane = plane; continue; default: continue; } } // throw new NotImplementedException(); }
//each tick the simualtor send simulation to the server: private void SimulatorTimer_Elapsed(object sender, ElapsedEventArgs e) { PlaneDTO plane = Simulate(); //send simulation to server : proxy.SendSimulation(new SimulationRequest { SimulatedPlane = plane }); }
public void AddPlane(PlaneDTO planeDTO) { using (var context = new FlightControlDBContext()) { Plane plane = ConvertToModel(planeDTO); context.Planes.Add(plane); context.SaveChanges(); } }
public void ChangePlaneStatus(PlaneDTO planeDTO) { using (var context = new FlightControlDBContext()) { Plane plane = ConvertToModel(planeDTO); context.Entry(plane).State = EntityState.Modified; context.SaveChanges(); } }
//simulate an arrival plane: private PlaneDTO SimulateArrival() { //randomizing plane PlaneDTO randomPlane = new PlaneDTO { PlaneId = rnd.Next(1, 100000), CompanyName = RandomCompanyNames[rnd.Next(0, RandomCompanyNames.Count)], StationId = 8 }; // PlanesParking.Add(randomPlane); return(randomPlane); }
private Plane ConvertToModel(PlaneDTO planeDTO) { if (planeDTO != null) { return(new Plane { PlaneId = planeDTO.PlaneId, StationId = planeDTO.StationId, CompanyName = planeDTO.CompanyName, State = planeDTO.State }); } return(null); }
/// <summary> ///telling to simulator about parked plane so he can simulate that departure (some time after) /// </summary> /// <param name="sender">parked plane</param> /// <param name="e">empty</param> private void OnPlaneParked(object sender, EventArgs e) { if (simulatorCallback != null) { PlaneDTO plane = sender as PlaneDTO; simulatorCallback.OnPlaneParked(new OnPlaneParkedRequest { ParkedPlane = plane }); } }
public void PostPlaneTestBadResult_when_post_Bad_then_HttpBAD() { PlaneDTO plane = new PlaneDTO() { ReleaseDate = new DateTime(2018, 9, 9), }; Assert.AreEqual(new HttpResponseMessage(HttpStatusCode.BadRequest).StatusCode, _controller.Post(plane).StatusCode); }
//simulate a departure plane: private PlaneDTO SimulateDeparture() { if (PlanesParking.Count != 0) { PlaneDTO randomPlane = PlanesParking[rnd.Next(0, PlanesParking.Count)]; PlanesParking.Remove(randomPlane); //removing plane from the parkingPlanes list return(randomPlane); } return(null); }
public HttpResponseMessage Put(int id, [FromBody] PlaneDTO plane) { if (ModelState.IsValid && plane != null) { _service.Update <Plane>(id, Mapper.Map <PlaneDTO, Plane>(plane)); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }
public async Task <IActionResult> OnGetEditPlane(string id) { var plane = await _unitofwork.Planes.GetByAsync(id); PlaneDTO planeDTO = new PlaneDTO(); planeDTO.PlaneId = plane.PlaneId; planeDTO.SeatNum = plane.SeatNum; planeDTO.MakerId = plane.MakerId; return(Content(JsonConvert.SerializeObject(planeDTO))); // return new JsonResult(planeDTO); }
public void UpdatePlane(PlaneDTO value) { if (value != null) { Plane newPlane = mapper.Map <PlaneDTO, Plane>(value); unitOfWork.DepartureRepository.GetBy(p => p.PlaneItem.Id.Equals(value.Id)).ForEach(c => c.PlaneItem = newPlane); } else { throw new ArgumentNullException(); } }
public void Post([FromBody] PlaneDTO plane) { if (ModelState.IsValid) { Response.StatusCode = 200; planeService.CreatePlane(plane); } else { Response.StatusCode = 400; } }
public void Put(int id, [FromBody] PlaneDTO plane) { if (ModelState.IsValid) { Response.StatusCode = 200; planeService.UpdatePlane(id, plane); } else { Response.StatusCode = 400; } }
public async Task <IActionResult> Get(int id) { PlaneDTO temp = await planeService.GetPlaneById(id); if (temp != null) { return(Ok(temp)); } else { return(BadRequest()); } }
public async Task <IActionResult> Post([FromBody] PlaneDTO value) { var validationResult = await _planeModelValidator.ValidateAsync(value); if (!validationResult.IsValid) { throw new BadRequestException(validationResult.Errors); } var entity = await _planeService.CreateAsync(value); return(Json(entity)); }
//removing planes from airport that already departured: private void RemoveDeparturedPlanesFromAirport(AirportDTO airport) { for (int i = 0; i < airport.Planes.Count; i++) { PlaneDTO plane = airport.Planes[i]; //if the plane already left the airport if (StationsInfoService.IsInAir(plane.StationId)) { //remove the plane from the airport: airport.Planes.Remove(plane); } } }
//plane can start arrival/landing only if sations 0,1,2,3,7,4 are empty(4-can start parking) public static bool IsClearForLanding(AirportDTO airport) { // same rules as IsClearForDeparture with the exception of station 4 if (AirportFieldValidator.IsClearForDeparturing(airport)) // if all is true, then can check station 4 { PlaneDTO plane = airport.Planes.FirstOrDefault(p => StationsInfoService.IsAttendingToPark(p.StationId)); if (plane == null) //no { return(true); } } return(false); }