public async Task UpdateClub_WhenCalled_UpdateExistingClub()
        {
            const int    id         = 1;
            const string updateName = "Chelsea";

            var clubUpdateDto = new ClubUpdateDto
            {
                Name = updateName
            };

            var club = new Club
            {
                Id   = id,
                Name = "Arsenal"
            };

            var expectedClub = new Club
            {
                Id   = id,
                Name = updateName
            };

            _clubService.Setup(c => c.GetByIdAsync(id)).ReturnsAsync(club);
            _clubService.Setup(c => c.GetDetailByIdAsync(id)).ReturnsAsync(expectedClub);

            var result = await _clubsController.UpdateClub(id, clubUpdateDto);

            var okObjectResult      = result as OkObjectResult;
            var okObjectResultValue = okObjectResult.Value as ClubDetailDto;

            _clubService.Verify(c => c.UpdateAsync(It.IsAny <Club>()), Times.Once);

            Assert.That(result, Is.TypeOf <OkObjectResult>());
            Assert.That(okObjectResultValue.Name, Is.EqualTo(updateName));
        }
示例#2
0
        public ActionResult UpdateClub(int id, ClubUpdateDto clubUpdateDto)
        {
            var clubModelFromRepo = _repository.GetClubById(id);

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

            _mapper.Map(clubUpdateDto, clubModelFromRepo);

            _repository.UpdateClub(clubModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
        public async Task UpdateClub_WhenCalled_ReturnNotFound()
        {
            const int    id         = 1;
            const string updateName = "Chelsea";

            var clubUpdateDto = new ClubUpdateDto
            {
                Name = updateName
            };

            _clubService.Setup(c => c.GetByIdAsync(id)).ReturnsAsync((Club)null);

            var result = await _clubsController.UpdateClub(id, clubUpdateDto);

            _clubService.Verify(c => c.GetByIdAsync(id), Times.Once);
            _clubService.Verify(c => c.UpdateAsync(It.IsAny <Club>()), Times.Never);

            Assert.That(result, Is.TypeOf <NotFoundResult>());
        }
        public async Task <IActionResult> UpdateClub(int id, [FromBody] ClubUpdateDto clubUpdateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var club = await _clubService.GetByIdAsync(id);

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

            _mapper.Map(clubUpdateDto, club);
            await _clubService.UpdateAsync(club);

            var updatedClub = await _clubService.GetDetailByIdAsync(id);

            var returnClub = _mapper.Map <ClubDetailDto>(updatedClub);

            return(Ok(returnClub));
        }
示例#5
0
 public virtual Task <ClubDto> UpdateAsync(Guid id, ClubUpdateDto input)
 {
     return(_clubsAppService.UpdateAsync(id, input));
 }