public async Task PalestrantesController_UpdatePalestrante() { // Arrange var login = await UserUtils.LoginUser(Environment.Client); var palestrante = new PalestranteViewModel { Id = Guid.Parse("108E5C22-3D7B-4CBE-9BA8-4F257A6C4652"), Nome = "USADO PELO TESTE DE INTEGRAÇÃO", MiniBio = "*** NÃO REMOVER ***", Url = "http://www.teste-integracao-api.com/" }; var postContent = new StringContent( JsonConvert.SerializeObject(palestrante), Encoding.UTF8, "application/json"); var response = await Environment.Client.PutAsync("api/v1/palestrante-management", postContent); // Act var userResult = JsonConvert.DeserializeObject <PalestranteJsonDTO>(await response.Content.ReadAsStringAsync()); // Assert response.EnsureSuccessStatusCode(); var statusResult = userResult.success; Assert.True(statusResult); }
public void PalestranteController_CreatePalestrante_ReturnErrorsFromDomainLayer() { // Arrange var mockIPalestranteAppService = new Mock <IPalestranteAppService>(); var mockIPalestraAppService = new Mock <IPalestraAppService>(); var mockNotification = new Mock <DomainNotificationHandler>(); var mockIMediatorHandler = new Mock <IMediatorHandler>(); var palestranteViewModel = new PalestranteViewModel(); mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>()); var palestranteController = new PalestranteController( mockIPalestranteAppService.Object, mockIPalestraAppService.Object, mockNotification.Object, mockIMediatorHandler.Object); var notificationList = new List <DomainNotification> { new DomainNotification("Error", "Erro ao adicionar Palestrante") }; mockNotification.Setup(m => m.GetNotifications()).Returns(notificationList); mockNotification.Setup(c => c.HasNotifications()).Returns(true); //Act var result = palestranteController.Post(new PalestranteViewModel()); //Assert mockIPalestranteAppService.Verify(m => m.Register(palestranteViewModel), Times.Never); Assert.IsType <BadRequestObjectResult>(result); }
public void PalestranteController_CreatePalestrante_ReturnSuccess() { // Arrange var mockIPalestranteAppService = new Mock <IPalestranteAppService>(); var mockIPalestraAppService = new Mock <IPalestraAppService>(); var mockNotification = new Mock <DomainNotificationHandler>(); var mockIMediatorHandler = new Mock <IMediatorHandler>(); var palestranteViewModel = new PalestranteViewModel(); mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>()); var palestranteController = new PalestranteController( mockIPalestranteAppService.Object, mockIPalestraAppService.Object, mockNotification.Object, mockIMediatorHandler.Object); //Act var result = palestranteController.Post(palestranteViewModel); //Assert mockIPalestranteAppService.Verify(m => m.Register(palestranteViewModel), Times.Once); Assert.IsType <OkObjectResult>(result); }
public PalestranteViewModel Update(PalestranteViewModel entity) { var palestrante = mapper.Map <Palestrante>(entity); palestranteRepositorio.Update(palestrante); return(mapper.Map <PalestranteViewModel>(palestrante)); }
public IActionResult Put([FromBody] PalestranteViewModel palestranteViewModel) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(Response(palestranteViewModel)); } _palestranteAppService.Update(palestranteViewModel); return(Response(palestranteViewModel)); }
public IActionResult Create(PalestranteViewModel palestranteViewModel) { if (!ModelState.IsValid) { return(View(palestranteViewModel)); } _palestranteAppService.Register(palestranteViewModel); if (IsValidOperation()) { ViewBag.Sucesso = "Palestrante Cadastrado!"; } return(View(palestranteViewModel)); }
public async Task <IActionResult> Post([FromBody] PalestranteViewModel model) { try { palestranteAppServece.Add(model); if (await palestranteAppServece.SaveChangesAsync()) { return(Created($"/api/palestrante/{model.Id}", model)); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Erro no Banco de Dados")); } return(BadRequest()); }
public IActionResult Edit(PalestranteViewModel palestranteViewModel) { if (!ModelState.IsValid) { return(View(palestranteViewModel)); } _palestranteAppService.Update(palestranteViewModel); if (IsValidOperation()) { ViewBag.Sucesso = "Palestrante Atualizado!"; } return(View(palestranteViewModel)); }
public async Task <IActionResult> Put(int palestranteId, [FromBody] PalestranteViewModel model) { try { var result = palestranteAppServece.ObterPalestranteAsyncPorPalestranteId(palestranteId, false); if (result == null) { return(NotFound()); } palestranteAppServece.Update(model); if (await palestranteAppServece.SaveChangesAsync()) { return(Created($"/api/palestrante/{model.Id}", model)); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Erro no banco de dados")); } return(BadRequest()); }
public void Update(PalestranteViewModel palestranteViewModel) { var updateCommand = _mapper.Map <UpdatePalestranteCommand>(palestranteViewModel); Bus.SendCommand(updateCommand); }
public void Register(PalestranteViewModel palestranteViewModel) { var registerCommand = _mapper.Map <RegisterNewPalestranteCommand>(palestranteViewModel); Bus.SendCommand(registerCommand); }
public void Delete(PalestranteViewModel entity) { var palestrante = mapper.Map <Palestrante>(entity); palestranteRepositorio.Delete(palestrante); }