public async Task Update(PilotDto item) { var updItem = _mapper.Map <PilotDto, Pilot>(item); await _unitOfWork.Repository <Pilot>().Update(updItem); await _unitOfWork.SaveAsync(); }
public void Put_When_requested_with_not_valid_body_Then_return_response_with_status_code_400() { var notValidPilotDto = new PilotDto { FirstName = "M", LastName = "Solomko", Birthdate = new DateTime(2020, 1, 21), Experience = -3 }; var existedId = _context.Pilots .FirstOrDefault(p => p.FirstName == "Mihail").Id; HttpWebResponse result = new HttpWebResponse(); try { PutMethod(notValidPilotDto, out HttpWebResponse response, _baseUrl + existedId); } catch (WebException ex) { result = ex.Response as HttpWebResponse; } Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public void Update_When_pilotDto_is_null_Then_throw_NullBodyException() { PilotDto nullDto = null; int id = 1; Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto)); }
public void Update_Valid() { //arange PilotsService service = new PilotsService(unitOfWork, mapper, validator); var expected = new Pilot { Id = 1, CrewId = 1, FirstName = "Ivan", LastName = "Ivanov", Experience = 3, Birthday = new DateTime(1987, 1, 24) }; var DtoToMake = new PilotDto { Id = 1, CrewId = 1, FirstName = "Ivan", LastName = "Ivanov", Experience = 3, Birthday = new DateTime(1987, 1, 24) }; //act service.Update(DtoToMake); var actual = (unitOfWork.Set <Pilot>() as FakeRpository <Pilot>).updatedItem; //assert Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.CrewId, actual.CrewId); Assert.AreEqual(expected.Experience, actual.Experience); Assert.AreEqual(expected.FirstName, actual.FirstName); Assert.AreEqual(expected.LastName, actual.LastName); Assert.AreEqual(expected.Birthday, actual.Birthday); }
public void Update_WhenDtoIsPassed_ThenReturnedTheSameWithPassedId() { // Arrange var id = Guid.NewGuid(); var dto = new PilotDto() { FirstName = "FirstName", SecondName = "SecondName", BirthDate = new DateTime(1980, 1, 1), Experience = 5 }; var service = new PilotService(unitOfWorkFake, mapper, alwaysValidValidator); // Act var returnedDto = service.Update(id, dto); // Assert Assert.True(returnedDto.Id == id); Assert.AreEqual(dto.FirstName, returnedDto.FirstName); Assert.AreEqual(dto.SecondName, returnedDto.SecondName); Assert.AreEqual(dto.BirthDate, returnedDto.BirthDate); Assert.AreEqual(dto.Experience, returnedDto.Experience); }
public PilotDto GetPilot(string name, int allianceId, int corpId, decimal securityStatus = 0) { var query = _reportingRepository.QueryFor <IPilotByNameQuery>(c => c.Name = name); var dto = query.Execute(); if (dto == null) { var sequence = _reportingRepository.GetNextSequenceFor <PilotDto>(); var uid = SystemIdGenerator.Next(); _bus.Send(new CreatePilot(uid, sequence, name, allianceId, corpId, securityStatus, 0)); dto = new PilotDto { AllianceId = allianceId, CorporationId = corpId, ExternalId = 0, Id = uid, Name = name, Timestamp = SystemDateTime.Now(), Sequence = sequence }; } else { if (dto.CorporationId != corpId) { dto.CorporationId = corpId; _bus.Send(new ChangePilotsCorporation(dto.Id, corpId)); } } return(dto); }
public void PUT_WhenPuttNewItem_ThenServiceReturnOkAndThisObject() { //Arrange var pilot = new PilotDto { Id = Guid.NewGuid(), FirstName = "FirstName", SecondName = "SecondName", Experience = 4, BirthDate = new DateTime(1980, 1, 1) }; var fakeService = A.Fake <IPilotService>(); A.CallTo(() => fakeService.Update(pilot.Id, pilot)).Returns(pilot); var controller = new PilotsController(fakeService); //Act var response = controller.Post(pilot) as ObjectResult; //Assert Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode); Assert.IsInstanceOf(typeof(PilotDto), response.Value); }
public async Task Create(PilotDto item) { var newItem = _mapper.Map <PilotDto, Pilot>(item); await _unitOfWork.Repository <Pilot>().Create(newItem); await _unitOfWork.SaveAsync(); }
public void Update_When_pilotDto_is_null_Then_throw_NullBodyException() { PilotDto nullDto = null; var existId = _context.Pilots .FirstOrDefault(p => p.FirstName == "Petro").Id; Assert.Throws <NullBodyException>(async() => await _service.UpdateAsync(existId, nullDto)); }
public void Make(PilotDto entity) { var entitysForCreate = Entitys.SingleOrDefault(x => x.Id == entity.Id); if (entitysForCreate == null) { Entitys.Add(entity); } }
public PilotDto Create(PilotDto pilotDto) { var pilot = mapper.Map <PilotDto, Pilot>(pilotDto); pilot.Id = Guid.NewGuid(); db.PilotRepositiry.Create(pilot); return(mapper.Map <Pilot, PilotDto>(pilot)); }
public async Task <IActionResult> Get(int id) { PilotDto Pilot = await service.GetById(id); if (Pilot == null) { return(NotFound()); } return(Ok(Pilot)); }
public async Task Update_WhenPilotNull_ThenReturnExeption() { var Pilots = new IFakeRepository <Pilot>(); var context = new IFakeUnitOfFactory(); PilotDto PilotDto = null; PilotService service = new PilotService(context); PilotDto PilotDtoSaved = await service.Update(PilotDto); }
public PilotDto Update(Guid id, PilotDto pilotDto) { var pilot = mapper.Map <PilotDto, Pilot>(pilotDto); pilot.Id = id; db.PilotRepositiry.Update(pilot); return(mapper.Map <Pilot, PilotDto>(pilot)); }
public IActionResult Get(int id) { PilotDto Pilot = service.GetById(id); if (Pilot == null) { return(NotFound()); } return(Ok(Pilot)); }
public void Update(PilotDto entity) { var entitysForUpdate = Entitys.SingleOrDefault(x => x.Id == entity.Id); if (entitysForUpdate != null) { Entitys.Remove(entitysForUpdate); Entitys.Add(entity); } }
public async Task <IActionResult> Put(int id, [FromBody] PilotDto entity) { var result = await _pilotsSrvice.UpdateAsync(entity, id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public async Task <IActionResult> Post([FromBody] PilotDto entity) { var result = await _pilotsSrvice.AddAsync(entity); if (result == null) { return(NotFound()); } return(Ok(result)); }
public Pilot MapPilot(PilotDto value) { return(new Pilot { Id = value.ID, Name = value.FirstName, LastName = value.LastName, Birthday = value.Birthday, Experience = value.Experience }); }
public void Add_When_pilotDto_is_not_valid_Then_throw_ValidationException() { var notValidDto = new PilotDto { FirstName = "S", LastName = "W", Birthdate = new DateTime(2030, 10, 12), Experience = -2 }; Assert.Throws <ValidationException>(async() => await _service.AddAsync(notValidDto)); }
public void Post_When_dto_is_null_Then_return_status_code_400() { var service = A.Fake <IService <PilotDto> >(); A.CallTo(() => service.Add(A <PilotDto> .That.IsNull())).Throws(new NullBodyException()); var controller = new PilotsController(service); PilotDto dto = null; var result = controller.Post(dto) as StatusCodeResult; Assert.AreEqual(400, result.StatusCode); }
public void Add_When_pilotModel_is_not_valid_Then_throw_ValidationException() { var notValidDto = new PilotDto { FirstName = "P", LastName = "B", Birthdate = new DateTime(2030, 10, 12), Experience = -2 }; Assert.Throws <ValidationException>(() => _service.Add(notValidDto)); }
public IActionResult Put(int id, [FromBody] PilotDto value) { if (ModelState.IsValid) { var item = service.Update(value); if (item != null) { return(Ok(item)); } } return(BadRequest()); }
public IActionResult Delete([FromBody] PilotDto pilot) { try { service.Delete(pilot); return(NoContent()); } catch (Exception) { return(NotFound()); } }
public async Task <IActionResult> Delete([FromBody] PilotDto pilot) { try { await service.Delete(pilot); return(NoContent()); } catch (Exception ex) { return(NotFound(ex)); } }
public void Update_When_id_is_not_exist_Then_throw_NotExistException() { var validDto = new PilotDto { FirstName = "Petro", LastName = "Boroda", Birthdate = new DateTime(1989, 10, 12), Experience = 4 }; int notExistId = 2; Assert.Throws <NotExistException>(() => _service.Update(notExistId, validDto)); }
public async Task <int> Create(PilotDto Pilot) { var validationResult = validator.Validate(Pilot); if (validationResult.IsValid) { return(await unit.Pilots.Create(mapper.MapPilot(Pilot))); } else { throw new ValidationException(validationResult.Errors); } }
public void Add_When_pilotModel_is_valid_Then_return_created_model_id() { var validDto = new PilotDto { FirstName = "Petro", LastName = "Boroda", Birthdate = new DateTime(1989, 10, 12), Experience = 4 }; var result = _service.Add(validDto); Assert.AreEqual(result, 1); }
public void Update_When_pilotModel_is_not_valid_and_id_is_exist_Then_throw_ValidationException() { var notValidDto = new PilotDto { FirstName = "P", LastName = "B", Birthdate = new DateTime(2030, 10, 12), Experience = -2 }; int existId = 3; Assert.Throws <ValidationException>(() => _service.Update(existId, notValidDto)); }
public async Task <IActionResult> Update([FromBody] PilotDto pilot) { if (ModelState.IsValid) { await _service.Update(pilot); return(Ok(pilot)); } else { return(new BadRequestObjectResult(ModelState)); } }