public void Update_When_crewDto_is_null_Then_throw_NullBodyException() { CrewDto nullDto = null; int id = 1; Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto)); }
public void Initialize() { mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <CrewDto>(It.IsAny <Crew>())).Returns(new CrewDto()); ticketRepository = new Mock <IRepository <Crew> >(); mockUoW = new Mock <IUow>(); mockUoW.Setup(m => m.GetRepository <Crew>()).Returns(ticketRepository.Object); service = new Mock <BaseService>(mockUoW); crew = new CrewDto() { Id = 1, FlightAttendants = new List <FlightAttendant> { new FlightAttendant() { Id = 4, Birthday = new DateTime(), Name = "Monica", Surname = "Mancini" } }, Pilot = new Pilot() { Id = 1, Name = "Karlos", Surname = "Gonsales", Birthday = new DateTime(), Experience = 4 } }; mockSet = new Mock <DbSet <Crew> >(); //mockSet.As<Crew>().Setup(m => m.Id).Returns(crew.Id); //mockSet.As<Crew>().Setup(m => m.Pilot).Returns(crew.Pilot); //mockSet.As<Crew>().Setup(m => m.FlightAttendants).Returns(crew.FlightAttendants); }
public void Update_When_crewModel_is_valid_and_id_is_exist_Then_call_Update_method() { var validDto = new CrewDto { Pilot = new Pilot { FirstName = "Petro", LastName = "Boroda", Birthdate = new DateTime(1989, 10, 12), Experience = 4 }, Stewardesses = new List <Stewardesse> { new Stewardesse { FirstName = "Maria", LastName = "Alexandrovna", Birthdate = new DateTime(1990, 3, 1) } } }; int existId = 3; _service.Update(existId, validDto); A.CallTo(() => _repository.Update(A <int> ._, A <Crew> ._)).MustHaveHappened(); }
public void Make_Valid() { //arange CrewsService fs = new CrewsService(unitOfWork, mapper, validator); var expected = new Crew { Id = 1, DepartureId = 1 }; var DtoToMake = new CrewDto { Id = 1, DepartureId = 1 }; //act fs.MakeAsync(DtoToMake); var actual = (unitOfWork.Set <Crew>() as FakeRpository <Crew>).createdItem; //assert Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.DepartureId, actual.DepartureId); }
public void Make_UnValide() { //arange CrewsService fs = new CrewsService(unitOfWork, mapper, validator); var expected = new Crew { Id = 1, DepartureId = default(int) }; var DtoToMake = new CrewDto { Id = 1, DepartureId = default(int) }; //act fs.MakeAsync(DtoToMake); var actual = (unitOfWork.Set <Crew>() as FakeRpository <Crew>).createdItem; //assert Assert.IsNull(actual); }
public async Task Create(CrewDto item) { var newItem = _mapper.Map <CrewDto, Crew>(item); await _unitOfWork.Repository <Crew>().Create(newItem); await _unitOfWork.SaveAsync(); }
public async Task Update(CrewDto item) { var updItem = _mapper.Map <CrewDto, Crew>(item); await _unitOfWork.Repository <Crew>().Update(updItem); await _unitOfWork.SaveAsync(); }
public Crew MapCrew(CrewDto value) { return(new Crew { Id = value.ID, Pilot = unitOfWork.Pilots.Get(value.Pilot), Stewadresses = unitOfWork.Stewadresses.Get().Where(s => value.Stewadress.Contains(s.Id)).ToList() }); }
public IActionResult Get(int id) { CrewDto Crew = service.GetById(id); if (Crew == null) { return(NotFound()); } return(Ok(Crew)); }
public async Task Update_WhenCrewNull_ThenReturnExeption() { var Crews = new IFakeRepository <Crew>(); var context = new IFakeUnitOfFactory(); CrewDto CrewDto = null; CrewService service = new CrewService(context); CrewDto CrewDtoSaved = await service.Update(CrewDto); }
public async Task <IActionResult> Get(int id) { CrewDto Crew = await service.GetById(id); if (Crew == null) { return(NotFound()); } return(Ok(Crew)); }
public async Task <IActionResult> Put(int id, [FromBody] CrewDto entity) { var result = await _crewsSrvice.UpdateAsync(entity, id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public async Task <IActionResult> Post([FromBody] CrewDto entity) { var result = await _crewsSrvice.AddAsync(entity); if (result == null) { return(NotFound()); } return(Ok(result)); }
public IActionResult Put(int id, [FromBody] CrewDto value) { if (ModelState.IsValid) { var item = service.Update(value); if (item != null) { return(Ok(item)); } } return(BadRequest()); }
public void OnSelectedItem(object sender, RoutedEventArgs e) { SelectedItem = GetSelected(sender, e); if (SelectedItem != null) { TextId.Text = SelectedItem.Id.ToString(); TextName.Text = SelectedItem.Pilot.Name; TextStewardess1.Text = SelectedItem.Stewardesses.First().Id.ToString(); TextStewardess2.Text = SelectedItem.Stewardesses.Last().Id.ToString(); } }
public IActionResult Delete([FromBody] CrewDto crew) { try { service.Delete(crew); return(NoContent()); } catch (Exception) { return(NotFound()); } }
public CrewDto Update(Guid id, CrewDto crewDto) { var crew = mapper.Map <CrewDto, Crew>(crewDto); crew.Id = id; crew.Pilot = db.PilotRepositiry.Get(crewDto.PilotId); crew.Stewardesses = db.StewardessRepositiry.GetAll().Where(i => crewDto.StewardessesId.Contains(i.Id)).ToList(); db.CrewRepositiry.Update(crew); return(mapper.Map <Crew, CrewDto>(crew)); }
//----------------------------------------------------------------// public async Task <Crew> SaveMovieCrewAsync(CrewDto crewDto, Movie movie) { Task <People> t_people = SavePeopleAsync(crewDto.Id.ToString()); Department department = await SaveDepartmentAsync(crewDto.department); Job job = await SaveJobAsync(crewDto.job, department); Crew crew = new Crew(movie, await t_people, job); await _crewCommand.SaveOrUpdateAsync(crew); return(crew); }
public IActionResult Put(int id, [FromBody] CrewDto value) { if (ModelState.IsValid) { try { service.Update(value); } catch (Exception) { return(BadRequest()); } return(Ok()); } return(BadRequest()); }
public CrewDto Create(CrewDto crewDto) { var crew = mapper.Map <CrewDto, Crew>(crewDto); crew.Id = Guid.NewGuid(); crew.Pilot = db.PilotRepositiry.Get(crewDto.PilotId); crew.Stewardesses = db.StewardessRepositiry.GetAll().Where(i => crewDto.StewardessesId.Contains(i.Id)).ToList(); db.CrewRepositiry.Create(crew); db.SaveChanges(); return(mapper.Map <Crew, CrewDto>(crew)); }
public async Task <IActionResult> Delete([FromBody] CrewDto crew) { try { await service.Delete(crew); return(NoContent()); } catch (Exception ex) { return(NotFound(ex)); } }
public async Task <int> Create(CrewDto Crew) { var validationResult = validator.Validate(Crew); if (validationResult.IsValid) { return(await unit.Crew.Create(await mapper.MapCrew(Crew))); } else { throw new FluentValidation.ValidationException(validationResult.Errors); } }
public async Task <IActionResult> Post([FromBody] CrewDto crewDto) { try { var crewToReturn = await _crewService.AddEntityAsync(crewDto); return(CreatedAtRoute("GetCrew", new { id = crewToReturn.Id }, crewToReturn)); } catch (BadRequestException) { return(BadRequest()); } }
public async Task <IActionResult> Update([FromBody] CrewDto crew) { if (ModelState.IsValid) { await _service.Update(crew); return(Ok(crew)); } else { return(new BadRequestObjectResult(ModelState)); } }
public void Create(CrewDto Crew) { var validationResult = validator.Validate(Crew); if (validationResult.IsValid) { unit.Crew.Create(mapper.MapCrew(Crew)); } else { throw new ValidationException(validationResult.Errors); } }
public void Create_WhenDtoIsEmpty_ThenThrowValidExeption() { // Arrange var dto = new CrewDto() { }; var service = new CrewService(unitOfWorkFake, mapper, validator); // Act // Assert Assert.Throws <ValidationException>(() => service.Create(dto)); }
public async Task <IActionResult> Put([FromBody] CrewDto value) { if (ModelState.IsValid) { try { await Task.Run(() => service.Update(mapper.Map <CrewDto, Crew>(value))); await service.SaveChangesAsync(); } catch (Exception) { return(BadRequest()); } return(Ok()); } return(BadRequest()); }
public IActionResult Post([FromBody] CrewDto value) { try { service.Create(value); return(Ok()); } catch (ValidationException e) { return(BadRequest(e.Message)); } catch (Exception) { return(BadRequest()); } }
public IActionResult Put(int id, [FromBody] CrewDto Crew) { if (Crew == null) { ModelState.AddModelError("", "Не указаны данные для экипажа"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } service.Update(Crew); return(Ok(Crew)); }
public IActionResult Post([FromBody] CrewDto Crew) { if (Crew == null) { ModelState.AddModelError("", "Не указаны данные для экипажа"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } service.Create(Crew); return(Created("api/Crews", Crew)); }