Beispiel #1
0
        public void FormatarResposta_TipoRequisicao_GET_Lista()
        {
            var notificador       = new Notificador();
            var responseFormatter = new ResponseFormatter(notificador);
            var editoras          = new List <EditoraViewModel>
            {
                new()
                {
                    Id    = Guid.NewGuid(),
                    Nome  = "Editora",
                    Email = "*****@*****.**",
                    Pais  = "Brasil"
                }
            };

            var resposta = new Response <IEnumerable <EditoraViewModel> >(editoras, notificador);

            var resultado = responseFormatter.FormatarResposta(TipoRequisicao.Get, editoras);

            resultado.Should().BeOfType <OkObjectResult>()
            .Which.Value.Should().BeEquivalentTo(resposta);

            resultado.Should().BeOfType <OkObjectResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
Beispiel #2
0
        public void FormatarResposta_SemRetorno_TipoRequisicao_GET_Lista()
        {
            var notificador       = new Notificador();
            var responseFormatter = new ResponseFormatter(notificador);
            var editoras          = new List <EditoraViewModel>();

            var resultado = responseFormatter.FormatarResposta(TipoRequisicao.Get, editoras);

            resultado.Should().BeOfType <NoContentResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
        }
Beispiel #3
0
        public void FormatarResposta_TipoRequisicao_DELETE()
        {
            var notificador = new Notificador();
            var formatter   = new ResponseFormatter(notificador);
            var editora     = new EditoraViewModel
            {
                Id    = Guid.NewGuid(),
                Nome  = "Editora",
                Email = "*****@*****.**",
                Pais  = "Brasil"
            };

            var resultado = formatter.FormatarResposta(TipoRequisicao.Delete, editora);

            resultado.Should().BeOfType <NoContentResult>();
        }
Beispiel #4
0
        public void FormatarResposta_ComErroComStatusCodeNotFound_ObjetoUnico()
        {
            var notificador = new Notificador();

            notificador.AdicionarErro("erro", "mensagem", HttpStatusCode.NotFound);
            var responseFormatter = new ResponseFormatter(notificador);
            var editora           = new EditoraViewModel
            {
                Id    = Guid.NewGuid(),
                Nome  = "Editora",
                Email = "*****@*****.**",
                Pais  = "Brasil"
            };

            var resultado = responseFormatter.FormatarResposta(TipoRequisicao.Get, editora);

            resultado.Should().BeOfType <ObjectResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
Beispiel #5
0
        public void FormatarResposta_ComErroSemStatusCode_Lista()
        {
            var notificador = new Notificador();

            notificador.AdicionarErro("erro", "mensagem");
            var responseFormatter = new ResponseFormatter(notificador);
            var editora           = new List <EditoraViewModel>
            {
                new()
                {
                    Id    = Guid.NewGuid(),
                    Nome  = "Editora",
                    Email = "*****@*****.**",
                    Pais  = "Brasil"
                }
            };

            var resultado = responseFormatter.FormatarResposta(TipoRequisicao.Get, editora);

            resultado.Should().BeOfType <BadRequestObjectResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Beispiel #6
0
        public void FormatarResposta_TipoRequisicao_PATCH()
        {
            var notificador = new Notificador();
            var formatter   = new ResponseFormatter(notificador);
            var editora     = new EditoraViewModel
            {
                Id    = Guid.NewGuid(),
                Nome  = "Editora",
                Email = "*****@*****.**",
                Pais  = "Brasil"
            };

            var resposta = new Response <EditoraViewModel>(editora, notificador);

            var resultado = formatter.FormatarResposta(TipoRequisicao.Patch, editora);

            resultado.Should().BeOfType <AcceptedResult>()
            .Which.Value.Should().BeEquivalentTo(resposta);

            resultado.Should().BeOfType <AcceptedResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.Accepted);
        }