public async Task Adicionar_DeveRetornarErroQuandoNaoExistirAmbiente()
        {
            await _polarisLogFixture.RealizarLogin();

            _polarisLogFixture.Client.AtribuirToken(_polarisLogFixture.AccessToken);
            var cadastrarLogPayload = new CadastrarLogPayload
            {
                AmbienteId = Guid.NewGuid().ToString(),
                NivelId    = Guid.NewGuid().ToString(),
                Titulo     = _polarisLogFixture.Faker.Lorem.Word(),
                Descricao  = _polarisLogFixture.Faker.Lorem.Paragraph(),
                Origem     = _polarisLogFixture.Faker.Internet.Ip()
            };

            var response = await _polarisLogFixture.Client.PostAsJsonAsync("Logs", cadastrarLogPayload);

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Beispiel #2
0
        public async Task <IActionResult> Adicionar(CadastrarLogPayload cadastrarLogPayload)
        {
            var logViewModel = _mapper.Map <LogViewModel>(cadastrarLogPayload);
            var usuarioId    = (User.Identity as ClaimsIdentity)?.FindFirst(ClaimTypes.NameIdentifier).Value;

            logViewModel.UsuarioId = Guid.Parse(usuarioId);

            Guid.TryParse(cadastrarLogPayload.AmbienteId, out var ambienteId);
            logViewModel.AmbienteId = ambienteId;

            Guid.TryParse(cadastrarLogPayload.NivelId, out var nivelId);
            logViewModel.NivelId = nivelId;

            var id = await _logAppService.Adicionar(logViewModel);

            if (_notificationHandler.TemNotificacao())
            {
                return(BadRequest(_notificationHandler.ObterNotificacoes()));
            }

            return(Ok(new { id }));
        }