public OutAcorde Get(string nome) { nome = HttpUtility.UrlDecode(nome); OutAcorde outAcorde = new OutAcorde(); Acordes.DML.Acorde acorde = new Acordes.DML.Acorde(nome); Acordes.Interpreter.InterpreterAcorde interpreterAcorde = new Acordes.Interpreter.InterpreterAcorde(); try { interpreterAcorde.Interpret(acorde); outAcorde = acorde; outAcorde.Status.Sucesso = true; } catch (Acordes.Interpreter.ExpressaoInvalidaException ex) { this.HttpContext.Response.StatusCode = 400; outAcorde.Status.Sucesso = false; outAcorde.Status.MensagemErro = ex.Message; } catch (Exception) { this.HttpContext.Response.StatusCode = 500; outAcorde.Status.Sucesso = false; outAcorde.Status.MensagemErro = "Erro interno na API"; } return(outAcorde); }
public async Task Acorde_InterpretacaoInvalida() { var response = await contexto.Client.GetAsync("acorde/Hm"); string jsonResposta = await response.Content.ReadAsStringAsync(); OutAcorde saida = JsonSerializer.Deserialize <PowerChords.OutAcorde>(jsonResposta); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.False(saida.Status.Sucesso); }