public async Task <CourseDtoUpdateResult> Put(CourseDtoUpdate Course) { var model = _mapper.Map <CourseModel>(Course); var entity = _mapper.Map <CourseEntity>(model); var result = await _repository.UpdateAsync(entity); return(_mapper.Map <CourseDtoUpdateResult>(result)); }
public CourseTestes() { IdUsuario = Guid.NewGuid(); NameCourse = Faker.Name.FullName(); NameCourseAlterado = Faker.Name.FullName(); for (int i = 0; i < 10; i++) { var dto = new CourseDto() { Id = Guid.NewGuid(), Name = Faker.Name.FullName() }; listaCourseDto.Add(dto); } CourseDto = new CourseDto { Id = IdUsuario, Name = NameCourse }; CourseDtoCreate = new CourseDtoCreate { Name = NameCourse }; CourseDtoCreateResult = new CourseDtoCreateResult { Id = IdUsuario, Name = NameCourse, CreateAt = DateTime.UtcNow }; CourseDtoUpdate = new CourseDtoUpdate { Id = IdUsuario, Name = NameCourseAlterado }; CourseDtoUpdateResult = new CourseDtoUpdateResult { Id = IdUsuario, Name = NameCourseAlterado, UpdateAt = DateTime.UtcNow }; }
public async Task <ActionResult> Put([FromBody] CourseDtoUpdate course) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Put(course); if (result != null) { return(Ok(result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task E_Possivel_Realizar_Crud_Course() { _name = Faker.Name.First(); _email = Faker.Internet.Email(); var courseDto = new CourseDtoCreate() { Name = _name }; //Post var response = await PostJsonAsync(courseDto, $"{hostApi}courses", client); var postResult = await response.Content.ReadAsStringAsync(); var registroPost = JsonConvert.DeserializeObject <CourseDtoCreateResult>(postResult); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal(_name, registroPost.Name); Assert.True(registroPost.Id != default(Guid)); //Get All response = await client.GetAsync($"{hostApi}courses"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var jsonResult = await response.Content.ReadAsStringAsync(); var listaFromJson = JsonConvert.DeserializeObject <IEnumerable <CourseDto> >(jsonResult); Assert.NotNull(listaFromJson); Assert.True(listaFromJson.Count() > 0); Assert.True(listaFromJson.Where(r => r.Id == registroPost.Id).Count() == 1); var updateCourseDto = new CourseDtoUpdate() { Id = registroPost.Id, Name = Faker.Name.FullName() }; //PUT var stringContent = new StringContent(JsonConvert.SerializeObject(updateCourseDto), Encoding.UTF8, "application/json"); response = await client.PutAsync($"{hostApi}courses", stringContent); jsonResult = await response.Content.ReadAsStringAsync(); var registroAtualizado = JsonConvert.DeserializeObject <CourseDtoUpdateResult>(jsonResult); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotEqual(registroPost.Name, registroAtualizado.Name); //GET Id response = await client.GetAsync($"{hostApi}courses/{registroAtualizado.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); jsonResult = await response.Content.ReadAsStringAsync(); var registroSelecionado = JsonConvert.DeserializeObject <CourseDto>(jsonResult); Assert.NotNull(registroSelecionado); Assert.Equal(registroSelecionado.Name, registroAtualizado.Name); //DELETE response = await client.DeleteAsync($"{hostApi}courses/{registroSelecionado.Id}"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); //GET ID depois do DELETE response = await client.GetAsync($"{hostApi}courses/{registroSelecionado.Id}"); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }