public async Task UpdateGender() { var nameDB = Guid.NewGuid().ToString(); var context = BuildContext(nameDB); var mapper = ConfigureAutoMapper(); var newGender = new Gender { Name = "Comedy" }; context.Genders.Add(newGender); await context.SaveChangesAsync(); var context2 = BuildContext(nameDB); var controller = new GendersController(context2, mapper); var updateGender = new CreateGenderDTO { Name = "Drama" }; var response2 = await controller.Put(1, updateGender); var result2 = response2 as StatusCodeResult; Assert.AreEqual(204, result2.StatusCode); var context3 = BuildContext(nameDB); var exists = await context3.Genders.AnyAsync(x => x.Name == "Drama"); Assert.IsTrue(exists); }
public async Task <ActionResult> Put(int id, [FromBody] CreateGenderDTO genderDTO) { var entity = _mapper.Map <Gender>(genderDTO); entity.Id = id; _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <GenderDTO> > Post([FromBody] CreateGenderDTO genderDTO) { var entity = _mapper.Map <Gender>(genderDTO); _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); var genderDto = _mapper.Map <GenderDTO>(entity); return(new CreatedAtRouteResult("getGender", new { id = genderDto.Id }, genderDto)); }
public async Task CreateGender() { var nameDB = Guid.NewGuid().ToString(); var context = BuildContext(nameDB); var mapper = ConfigureAutoMapper(); var newGender = new CreateGenderDTO { Name = "Comedy" }; var controller = new GendersController(context, mapper); var response = await controller.Post(newGender); var result = response.Result as CreatedAtRouteResult; Assert.IsNotNull(result); var context2 = BuildContext(nameDB); var count = await context2.Genders.CountAsync(); Assert.AreEqual(1, count); }
public async Task <ActionResult> Put(int id, [FromBody] CreateGenderDTO create) { return(await Put <CreateGenderDTO, Gender>(id, create)); }
public async Task <ActionResult <GenderDTO> > Post([FromBody] CreateGenderDTO create) { return(await Post <CreateGenderDTO, Gender, GenderDTO>(create, "GetGender")); }