Example #1
0
        public async Task NaoDeveEditarCasoPedidoContenhaSituacaoInvalida()
        {
            IComandaService comandaService = _serviceProvider.GetRequiredService <IComandaService>();
            ComandaDto      comanda        = new ComandaDto
            {
                Id       = Guid.NewGuid(),
                Situacao = ComandaSituacao.Aberta
            };

            foreach (var produto in ProdutoMock.ObterListaDeProdutos())
            {
                comanda.Pedidos.Add(new ComandaPedidoDto()
                {
                    ProdutoId    = produto.Id,
                    ProdutoNome  = produto.Nome,
                    ProdutoPreco = produto.Preco,
                    Quantidade   = 1,
                    Situacao     = default(ComandaPedidoSituacao)
                });
            }

            var result = await comandaService.CadastrarAsync(comanda);

            result.Should().BeNull();
            comandaService.MensagensValidacao.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
            comandaService.MensagensValidacao.Any(c => c == ComandaMessage.SituacaoInvalida).Should().BeTrue();
        }
Example #2
0
        public async Task DeveEditarComandaValido()
        {
            IComandaService comandaService = _serviceProvider.GetRequiredService <IComandaService>();
            ComandaDto      comanda        = new ComandaDto
            {
                Id       = Guid.NewGuid(),
                Situacao = ComandaSituacao.Aberta
            };

            foreach (var produto in ProdutoMock.ObterListaDeProdutos())
            {
                comanda.Pedidos.Add(new ComandaPedidoDto()
                {
                    ProdutoId    = Guid.NewGuid(),
                    ProdutoNome  = produto.Nome,
                    ProdutoPreco = produto.Preco,
                    Quantidade   = 1,
                    Situacao     = ComandaPedidoSituacao.Pedido
                });
            }

            var result = await comandaService.EditarAsync(comanda);

            result.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
        }
Example #3
0
        public async Task NaoDeveFecharCasoComandaInValido()
        {
            IComandaService comandaService = _serviceProvider.GetRequiredService <IComandaService>();
            var             result         = await comandaService.ConfirmarAsync(Guid.Empty);

            result.Should().BeNull();
            comandaService.MensagensValidacao.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
            comandaService.MensagensValidacao.Any(c => c == ComandaMessage.ComandaInvalida).Should().BeTrue();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="notifications"></param>
 /// <param name="comandaService"></param>
 /// <param name="unitOfWork"></param>
 public ComandaController(
     INotificationHandler <DomainNotification> notifications,
     IComandaService comandaService,
     IUnitOfWork unitOfWork
     ) : base(notifications, unitOfWork)
 {
     _comandaService = comandaService;
     _unitOfWork     = unitOfWork;
 }
Example #5
0
        public async Task NaoDeveCadastarCasoNaoContenhaPedido()
        {
            IComandaService comandaService = _serviceProvider.GetRequiredService <IComandaService>();
            ComandaDto      comanda        = new ComandaDto
            {
                Situacao = ComandaSituacao.Aberta
            };

            var result = await comandaService.CadastrarAsync(comanda);

            result.Should().BeNull();
            comandaService.MensagensValidacao.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
            comandaService.MensagensValidacao.Any(c => c == ComandaMessage.PedidoObrigatorio).Should().BeTrue();
        }
Example #6
0
        public async Task DeveConfirmarCasoComandaValido()
        {
            MockComandaParameter parameter = new MockComandaParameter()
            {
                Exists   = true,
                Comanda  = MockHelper.Obter <Comanda>(),
                Comandas = MockHelper.ObterTodos <Comanda>()
            };

            IComandaService comandaService = Startup.GetServiceProvider(new ServiceParameter(parameter)).GetRequiredService <IComandaService>();
            var             result         = await comandaService.ConfirmarAsync(Guid.NewGuid());

            result.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
        }
Example #7
0
        public async Task NaoDeveEditarCasoPedidoNaoContenhaProduto()
        {
            IComandaService comandaService = _serviceProvider.GetRequiredService <IComandaService>();
            ComandaDto      comanda        = new ComandaDto
            {
                Id       = Guid.NewGuid(),
                Situacao = ComandaSituacao.Aberta
            };

            comanda.Pedidos.Add(new ComandaPedidoDto()
            {
                Quantidade = 1, Situacao = ComandaPedidoSituacao.Pedido
            });

            var result = await comandaService.EditarAsync(comanda);

            result.Should().BeNull();
            comandaService.MensagensValidacao.Should().NotBeNull(StringHelper.JoinHtmlMensagem(comandaService.MensagensValidacao));
            comandaService.MensagensValidacao.Any(c => c == ComandaMessage.ProdutoObrigatorio).Should().BeTrue();
        }
Example #8
0
        private async Task TesteDeCrudIntegracaoAsync()
        {
            IComandaService service        = serviceProvider.GetRequiredService <IComandaService>();
            IUsuarioService usuarioService = serviceProvider.GetRequiredService <IUsuarioService>();
            IProdutoService produtoService = serviceProvider.GetRequiredService <IProdutoService>();

            Comanda comandaNovo = null;
            Usuario usuario     = null;
            Produto produto     = null;
            Produto produto2    = null;

            try
            {
                usuario = await ObterUsuario(usuarioService);

                produto = await ObterProduto(produtoService, $"Produto pedido");

                produto2 = await ObterProduto(produtoService, $"Produto pedido 2");

                Comanda comanda = new Comanda();
                comanda.Garcom = usuario;
                comanda.AdicionarPedido(produto, 1);
                comandaNovo = await service.Add(comanda);

                service.Result.Any().Should().BeFalse();

                Comanda comandaPedidoEmPreparo = await service.AlterarSituacaoPedido(comandaNovo.Id, ComandaPedidoSituacao.Preparando);

                comandaPedidoEmPreparo.Pedidos.All(c => c.Situacao == ComandaPedidoSituacao.Preparando).Should().BeTrue();

                Comanda comandaPedidoPronto = await service.AlterarSituacaoPedido(comandaNovo.Id, ComandaPedidoSituacao.Pronto);

                comandaPedidoPronto.Pedidos.All(c => c.Situacao == ComandaPedidoSituacao.Pronto).Should().BeTrue();

                Comanda comandaPedidoCancelado = await service.AlterarSituacaoPedido(comandaNovo.Id, ComandaPedidoSituacao.Cancelado);

                comandaPedidoCancelado.Pedidos.All(c => c.Situacao == ComandaPedidoSituacao.Cancelado).Should().BeTrue();

                IList <Comanda> comandasAbertas = await service.TotasComandasAbertas();

                comandasAbertas.Any().Should().BeTrue();

                IQueryable <Comanda> comandasAbertasQueryable = service.ComandasAbertas();
                comandasAbertasQueryable.Any().Should().BeTrue();

                comandaNovo = await comandasAbertasQueryable.Where(c => c.Id == comandaNovo.Id)
                              .Include(c => c.Garcom)
                              .Include(c => c.Pedidos)
                              .ThenInclude(c => c.Produto)
                              .FirstOrDefaultAsync();

                comandaNovo.Should().NotBeNull();
                comandaNovo.Id.Should().NotBe(0);
                comandaNovo.Garcom.Nome.Should().Be(usuario.Nome);
                comandaNovo.AdicionarPedido(produto2, 1);
                comandaNovo.FecharConta();
                comandaNovo.Situacao.Should().Be(ComandaSituacao.Fechada);
                comandaNovo.TotalAPagar.Should().Be(20);
                comandaNovo.GorjetaGarcom.Should().Be(2.0M);

                bool resultadoEdicao = await service.Edity(comandaNovo);

                resultadoEdicao.Should().BeTrue();

                IEnumerable <Comanda> entidades = await service.GetAll();

                entidades.Any().Should().BeTrue();

                Comanda comandaById = await service.GetById(comandaNovo.Id);

                comandaById.Should().NotBeNull();

                bool exists = service.Exists(comandaNovo.Id);
                exists.Should().BeTrue();
            }
            finally
            {
                if (comandaNovo != null)
                {
                    bool resultadoExclusao = await service.Delete(comandaNovo.Id);

                    resultadoExclusao.Should().BeTrue();
                }

                if (usuario != null)
                {
                    bool resultadoExclusao = await usuarioService.Delete(usuario.Id);

                    resultadoExclusao.Should().BeTrue();
                }

                if (produto != null)
                {
                    bool resultadoExclusao = await produtoService.Delete(produto.Id);

                    resultadoExclusao.Should().BeTrue();
                }

                if (produto2 != null)
                {
                    bool resultadoExclusao = await produtoService.Delete(produto2.Id);

                    resultadoExclusao.Should().BeTrue();
                }
            }
        }
Example #9
0
 public ComandaController(IComandaService service)
 {
     _service = service;
 }
Example #10
0
 public ComandaController(IComandaService comandaService, ILogService logService)
 {
     _comandaService = comandaService;
     _logService     = logService;
 }