public async Task ValidationMappingStewardess_when_validate_pilot_OK_then_map() { var validator = new StewardessDTOValidator(); StewardessDTO correct = new StewardessDTO() { Id = 1, Surname = "sur" }; StewardessDTO incorrect = new StewardessDTO() { Id = 2, Name = "name" }; bool correctRes = validator.Validate(correct).IsValid; Assert.True(correctRes); var mapped = _mapper.Map <StewardessDTO, Stewardess>(correct); if (correctRes) { await _service.Post(mapped); } bool incorrectRes = validator.Validate(incorrect).IsValid; Assert.False(incorrectRes); var mappedIncorrect = _mapper.Map <StewardessDTO, Stewardess>(incorrect); if (incorrectRes) { await _service.Post(mapped); } }
public async Task <IActionResult> Update(int id, [FromBody] StewardessDTO 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 bool Update(int id, StewardessDTO obj) { var result = db.Stewardess.UpdateObject(id, _mapper.Map <Stewardess>(obj)); db.Save(); return(result); }
public void DeleteStewardess() { int id; var responseList = GetRequest(Url); var stList = JsonConvert.DeserializeObject <StewardessDTO[]>(responseList); if (stList.Length > 0) { id = stList.Last().Id; } else { var stewardess = new StewardessDTO { FirstName = "Kateryna", LastName = "Bila", DateOfBirth = new DateTime(1988, 4, 10), CrewId = 1 }; string output = JsonConvert.SerializeObject(stewardess); PostRequest(Url, output); var response = GetRequest(Url); var list = JsonConvert.DeserializeObject <StewardessDTO[]>(response); id = list.Last().Id; } DeleteRequest(Url + id); Assert.Throws <WebException>( () => GetRequest(Url + id)); }
public async Task UpdateEntityAsync(int id, StewardessDTO stewardessDTO) { var stewardess = await stewardessRepository.GetAsync(id); if (stewardess == null) { throw new ValidationException($"Flight with this number {id} not found"); } if (stewardessDTO.FirstName != null) { stewardess.FirstName = stewardessDTO.FirstName; } if (stewardessDTO.LastName != null) { stewardess.LastName = stewardessDTO.LastName; } if (stewardessDTO.BirthDate != DateTime.MinValue) { stewardess.BirthDate = stewardessDTO.BirthDate; } if (stewardessDTO.CrewId > 0) { stewardess.CrewId = stewardessDTO.CrewId; } await stewardessRepository.UpdateAsync(stewardess).ConfigureAwait(false); }
public void PutStewardess() { var stewardessPost = new StewardessDTO { FirstName = "Kateryna", LastName = "Bila", DateOfBirth = new DateTime(1988, 4, 10), CrewId = 1 }; var stewardessPut = new StewardessDTO { FirstName = "Isabella", LastName = "Bila", DateOfBirth = new DateTime(1988, 4, 10), CrewId = 1 }; string output = JsonConvert.SerializeObject(stewardessPost); PostRequest(Url, output); var responseList = GetRequest(Url); var stList = JsonConvert.DeserializeObject <StewardessDTO[]>(responseList); var id = stList.Last().Id; output = JsonConvert.SerializeObject(stewardessPut); PutRequest(Url + id, output); var response = GetRequest(Url + id); var st = JsonConvert.DeserializeObject <StewardessDTO>(response); Assert.IsInstanceOf <StewardessDTO>(st); Assert.IsNotNull(st.Id); Assert.IsNotNull(st.FirstName); Assert.AreEqual("Isabella", st.FirstName); Assert.IsNotNull(st.LastName); DeleteRequest(Url + id); }
public void UpdateEntity(int id, StewardessDTO stewardessDTO) { var stewardess = stewardessRepository.Get(id); if (stewardess == null) { throw new ValidationException($"Flight with this number {stewardessDTO.Id} not found"); } if (stewardessDTO.FirstName != null) { stewardess.FirstName = stewardessDTO.FirstName; } if (stewardessDTO.LastName != null) { stewardess.LastName = stewardessDTO.LastName; } if (stewardessDTO.BirthDate != DateTime.MinValue) { stewardess.BirthDate = stewardessDTO.BirthDate; } if (stewardessDTO.CrewId > 0) { stewardess.CrewId = stewardessDTO.CrewId; } stewardessRepository.Update(stewardess); }
public StewardessDTO AddStewardess(StewardessDTO stewardess) { Validation(stewardess); Stewardess modelStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess); return(mapper.Map <Stewardess, StewardessDTO>(unitOfWork.Stewardess.Create(modelStewardess))); }
private void CustomMapper(List <ExternalCrewDTO> external, out List <CrewDTO> crew) { crew = new List <CrewDTO>(); foreach (var item in external) { var stews = new List <StewardessDTO>(); foreach (var externalStew in item.stewardess) { var stewDto = new StewardessDTO { DateOfBirth = externalStew.birthDate, CrewId = externalStew.crewId, FirstName = externalStew.firstName, LastName = externalStew.lastName }; stews.Add(stewDto); } var crewDto = new CrewDTO { Id = item.id, Pilot = new PilotDTO { DateOfBirth = item.pilot[0].birthDate, Experience = item.pilot[0].exp, FirstName = item.pilot[0].firstName, LastName = item.pilot[0].lastName }, Stewardesses = new List <StewardessDTO>(stews) }; crew.Add(crewDto); } }
public void AddDeleteNewStewardessTest_Returns_CreatedResult_And_Stewardess_ShoudBe_AddedTo_Database_And_Then_ShouldBe_Deleted() { // Arrange MSSQLContext context = new MSSQLContext(); CrewsRepository crewsRepository = new CrewsRepository(); PilotsRepository pilotsRepository = new PilotsRepository(); StewardessesRepository stewardessesRepository = new StewardessesRepository(); CrewingUnitOfWork uow = new CrewingUnitOfWork(crewsRepository, pilotsRepository, stewardessesRepository, context); CrewingService service = new CrewingService(uow); StewardessesController controller = new StewardessesController(mapper.GetDefaultMapper(), service); // add act var newStewardessDTO = new StewardessDTO() { Birth = new DateTime(1985, 5, 12, 0, 0, 0), Name = "Masha", Surname = "Ivanova" }; var addResult = controller.AddStewardess(newStewardessDTO); // add assert Assert.IsInstanceOf <CreatedResult>(addResult); Assert.IsInstanceOf <StewardessDTO>((addResult as CreatedResult).Value); // delete act var addedStewardessDTO = (addResult as CreatedResult).Value as StewardessDTO; var deleteResult = controller.DeleteStewardess(addedStewardessDTO.Id); // delete assert Assert.IsInstanceOf <OkResult>(deleteResult); Assert.IsInstanceOf <NotFoundObjectResult>(controller.GetStewardess(addedStewardessDTO.Id)); }
public void Post([FromBody] StewardessDTO value) { if (ModelState.IsValid) { Service.Create(value); } }
public async Task <bool> UpdateObjectAsync(int id, StewardessDTO obj) { var result = db.Stewardess.Update(id, _mapper.Map <Stewardess>(obj)); await db.SaveAsync(); return(result); }
public void CreateEntity_Should_Create_stewardess_typeof_Stewardess() { // Arrange StewardessDTO stewardessDTO = new StewardessDTO { Id = 1, FirstName = "Anna", LastName = "Gohon", CrewId = 1, BirthDate = new DateTime(1998, 07, 12) }; Stewardess stewardess = new Stewardess { Id = 1, FirstName = "Anna", LastName = "Gohon", CrewId = 1, BirthDate = new DateTime(1998, 07, 12) }; var stewardessRepository = new FakeRepository <Stewardess>(); var stewardessService = new StewardessService(stewardessRepository); // Act stewardessService.CreateEntity(stewardessDTO); var result = stewardessRepository.Get(1); // Assert Assert.AreEqual(stewardess, result); }
private void Create_Click(object sender, RoutedEventArgs e) { var turple = RenderCreate(); var btnCreate = turple.Item1; var firstname = turple.Item2; var lastname = turple.Item3; var birthday = turple.Item4; btnCreate.Click += async(object sen, RoutedEventArgs evArgs) => { var pilot = new StewardessDTO() { FirstName = firstname.Text, LastName = lastname.Text, DateOfBirth = birthday.Date.Value.Date.ToString() }; try { await service.CreateAsync(pilot); } catch (Exception) { } stewardessesList.Add(pilot); UpdateList(); SingleItem.Children.Clear(); }; }
public void UpdateStewardess(StewardessDTO stewardess) { if (stewardess != null) { Stewardess updtStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess); unitOfWork.StewardessRepository.Insert(updtStewardess); } }
public void CreateStewardess(StewardessDTO stewardess) { if (stewardess != null) { Stewardess newStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess); unitOfWork.StewardessRepository.Create(newStewardess); } }
public bool AddObject(StewardessDTO obj) { if (obj != null) { db.Stewardess.Add(_mapper.Map <Stewardess>(obj)); return(true); } return(false); }
private void Validation(StewardessDTO stewardess) { var validationResult = validator.Validate(stewardess); if (!validationResult.IsValid) { throw new Exception(validationResult.Errors.First().ToString()); } }
public IActionResult Post([FromBody] StewardessDTO stewardess) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _service.AddObject(stewardess); return(result == true?StatusCode(200) : StatusCode(404)); }
public async Task <StewardessDTO> AddStewardess(StewardessDTO stewardess) { Validation(stewardess); Stewardess modelStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess); Stewardess result = await unitOfWork.Stewardess.Create(modelStewardess); await unitOfWork.SaveChangesAsync(); return(mapper.Map <Stewardess, StewardessDTO>(result)); }
public async Task <IActionResult> Put(int id, [FromBody] StewardessDTO stewardess) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _service.UpdateObjectAsync(id, stewardess); return(result == true?StatusCode(200) : StatusCode(500)); }
public IActionResult Put(int id, [FromBody] StewardessDTO stewardess) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _service.Update(id, stewardess); return(result == true?StatusCode(200) : StatusCode(500)); }
public IActionResult ModifyStewardess([FromBody] StewardessDTO stewardess) { if (!ModelState.IsValid) { return(BadRequest() as IActionResult); } var entity = service.UpdateStewardessInfo(mapper.Map <Stewardess>(stewardess)); return(entity == null?StatusCode(304) as IActionResult : Ok(mapper.Map <StewardessDTO>(entity))); }
public void Put(int id, [FromBody] StewardessDTO stewardess) { if (ModelState.IsValid) { Response.StatusCode = 200; stewardessService.UpdateStewardess(id, stewardess); } else { Response.StatusCode = 400; } }
public void AddStewardess_When_empty_surname_Then_throws_exception() { //assign StewardessDTO stewardess = new StewardessDTO() { Name = "Anna", Birthday = new DateTime(1998, 8, 21), }; //assert Assert.ThrowsAsync <Exception>(() => stewardessService.AddStewardess(stewardess)); }
public JsonResult Post([FromBody] StewardessDTO stewardess) { try { return(Json(stewardessService.AddStewardess(stewardess))); } catch (System.Exception ex) { HttpContext.Response.StatusCode = 400; return(Json(ex.Message)); } }
public JsonResult Put(int id, [FromBody] StewardessDTO stewardess) { try { return(Json(stewardessService.UpdateStewardess(id, stewardess))); } catch (System.Exception ex) { HttpContext.Response.StatusCode = 404; return(Json(ex.Message)); } }
public void CreateStewardess(StewardessDTO stewardess) { if (stewardess != null) { Stewardess newStewardess = mapper.Map <StewardessDTO, Stewardess>(stewardess); unit.StewardessesRepo.Insert(newStewardess); } else { throw new ArgumentNullException(); } }
public HttpResponseMessage Put(int id, [FromBody] StewardessDTO stewardess) { if (ModelState.IsValid && stewardess != null) { _service.Update <Stewardess>(id, Mapper.Map <StewardessDTO, Stewardess>(stewardess)); return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }
public void Post([FromBody] StewardessDTO stewardess) { if (ModelState.IsValid) { Response.StatusCode = 200; stewardessService.CreateStewardess(stewardess); } else { Response.StatusCode = 400; } }