コード例 #1
0
        public async Task Update(PilotDto item)
        {
            var updItem = _mapper.Map <PilotDto, Pilot>(item);
            await _unitOfWork.Repository <Pilot>().Update(updItem);

            await _unitOfWork.SaveAsync();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Update_When_pilotDto_is_null_Then_throw_NullBodyException()
        {
            PilotDto nullDto = null;
            int      id      = 1;

            Assert.Throws <NullBodyException>(() => _service.Update(id, nullDto));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public async Task Create(PilotDto item)
        {
            var newItem = _mapper.Map <PilotDto, Pilot>(item);
            await _unitOfWork.Repository <Pilot>().Create(newItem);

            await _unitOfWork.SaveAsync();
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        public void Make(PilotDto entity)
        {
            var entitysForCreate = Entitys.SingleOrDefault(x => x.Id == entity.Id);

            if (entitysForCreate == null)
            {
                Entitys.Add(entity);
            }
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        public async Task <IActionResult> Get(int id)
        {
            PilotDto Pilot = await service.GetById(id);

            if (Pilot == null)
            {
                return(NotFound());
            }
            return(Ok(Pilot));
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        public IActionResult Get(int id)
        {
            PilotDto Pilot = service.GetById(id);

            if (Pilot == null)
            {
                return(NotFound());
            }
            return(Ok(Pilot));
        }
コード例 #16
0
        public void Update(PilotDto entity)
        {
            var entitysForUpdate = Entitys.SingleOrDefault(x => x.Id == entity.Id);

            if (entitysForUpdate != null)
            {
                Entitys.Remove(entitysForUpdate);
                Entitys.Add(entity);
            }
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        public async Task <IActionResult> Post([FromBody] PilotDto entity)
        {
            var result = await _pilotsSrvice.AddAsync(entity);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
コード例 #19
0
ファイル: Mapping.cs プロジェクト: ZameAlex/BSA2018_Hometask7
 public Pilot MapPilot(PilotDto value)
 {
     return(new Pilot
     {
         Id = value.ID,
         Name = value.FirstName,
         LastName = value.LastName,
         Birthday = value.Birthday,
         Experience = value.Experience
     });
 }
コード例 #20
0
        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));
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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));
        }
コード例 #23
0
 public IActionResult Put(int id, [FromBody] PilotDto value)
 {
     if (ModelState.IsValid)
     {
         var item = service.Update(value);
         if (item != null)
         {
             return(Ok(item));
         }
     }
     return(BadRequest());
 }
コード例 #24
0
 public IActionResult Delete([FromBody] PilotDto pilot)
 {
     try
     {
         service.Delete(pilot);
         return(NoContent());
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
コード例 #25
0
        public async Task <IActionResult> Delete([FromBody] PilotDto pilot)
        {
            try
            {
                await service.Delete(pilot);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }
コード例 #26
0
        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));
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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));
        }
コード例 #30
0
        public async Task <IActionResult> Update([FromBody] PilotDto pilot)
        {
            if (ModelState.IsValid)
            {
                await _service.Update(pilot);

                return(Ok(pilot));
            }
            else
            {
                return(new BadRequestObjectResult(ModelState));
            }
        }