コード例 #1
0
        public static Conta GetContaValida()
        {
            return(new Conta
            {
                Id = 1,
                Cliente = ClienteObjectMother.GetClienteValido(),
                Ativada = true,
                NumeroConta = 666,
                Limite = 1000,

                Movimentacoes = new List <Movimentacao>
                {
                    new Movimentacao
                    {
                        Id = 1,
                        Data = DateTime.Now.AddDays(-1),
                        Valor = 100,
                        TipoOperacao = TipoOperacaoEnum.Credito
                    },
                    new Movimentacao
                    {
                        Id = 2,
                        Data = DateTime.Now.AddDays(-3),
                        Valor = 150,
                        TipoOperacao = TipoOperacaoEnum.Debito
                    }
                }
            });
        }
コード例 #2
0
        public void Repositorio_Cliente_Atualizar_DeveJogarExcessao_UnknownId()
        {
            _cliente    = ClienteObjectMother.GetClienteValido();
            _cliente.Id = 20;
            var action = new Action(() => _repository.Update(_cliente));

            action.Should().Throw <DbUpdateConcurrencyException>();
        }
コード例 #3
0
        public void Setup()
        {
            var connection = DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString());

            _context    = new FakeDbContext(connection);
            _repository = new ClienteRepository(_context);

            _cliente = ClienteObjectMother.GetClienteValido();
            //Seed
            _clienteSeed = ClienteObjectMother.GetClienteValido();
            _context.Clientes.Add(_clienteSeed);
            _context.SaveChanges();
        }
コード例 #4
0
        public void Service_Cliente_PegarClientePorId_DeveJogarExcessao_NotFoundException()
        {
            //Arrange
            var cliente = ClienteObjectMother.GetClienteValido();

            _repositoryFake.Setup(pr => pr.GetById(cliente.Id)).Throws <NotFoundException>();
            //Action
            Action act = () => _service.GetById(cliente.Id);

            //Assert
            act.Should().Throw <NotFoundException>();
            _repositoryFake.Verify(pr => pr.GetById(cliente.Id), Times.Once);
        }
コード例 #5
0
        public void Service_Cliente_PegarClientePorId_DevePassar()
        {
            //Arrange
            var cliente = ClienteObjectMother.GetClienteValido();

            _repositoryFake.Setup(pr => pr.GetById(cliente.Id)).Returns(cliente);
            //Action
            var recebido = _service.GetById(cliente.Id);

            //Verify
            _repositoryFake.Verify(pr => pr.GetById(cliente.Id), Times.Once);
            recebido.Should().NotBeNull();
            recebido.Id.Should().Be(cliente.Id);
        }
コード例 #6
0
        public void Controller_Clientes_Post_DevePassar()
        {
            // Arrange
            var cliente    = ClienteObjectMother.GetClienteValido();
            var clienteCmd = ClienteObjectMother.GetClienteValidoParaRegistrar();

            _clienteServiceMock.Setup(c => c.Add(clienteCmd)).Returns(cliente.Id);
            // Action
            IHttpActionResult callback = _clientesController.Post(clienteCmd);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <int> >().Subject;

            httpResponse.Content.Should().Be(cliente.Id);
            _clienteServiceMock.Verify(s => s.Add(clienteCmd), Times.Once);
        }
コード例 #7
0
        public void Controller_Clientes_GetById_DevePassar()
        {
            // Arrange
            var cliente = ClienteObjectMother.GetClienteValido();

            _clienteServiceMock.Setup(c => c.GetById(cliente.Id)).Returns(cliente);
            // Action
            IHttpActionResult callback = _clientesController.GetById(cliente.Id);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <ClienteViewModel> >().Subject;

            httpResponse.Content.Should().NotBeNull();
            httpResponse.Content.Id.Should().Be(cliente.Id);
            _clienteServiceMock.Verify(s => s.GetById(cliente.Id), Times.Once);
        }
コード例 #8
0
        public void Service_Cliente_AdicionarCliente_DevePassar()
        {
            //Arrange
            var cliente    = ClienteObjectMother.GetClienteValido();
            var clienteCmd = ClienteObjectMother.GetClienteValidoParaRegistrar();

            _repositoryFake.Setup(x => x.Add(It.IsAny <Cliente>()))
            .Returns(cliente);
            //Action
            var novoClienteId = _service.Add(clienteCmd);

            //Verify
            _repositoryFake.Verify(x => x.Add(It.IsAny <Cliente>()), Times.Once);
            novoClienteId.Should().Be(cliente.Id);
        }
コード例 #9
0
        public void Service_Cliente_AtualizarCliente_DevePassar()
        {
            //Arrange
            var cliente    = ClienteObjectMother.GetClienteValido();
            var clienteCmd = ClienteObjectMother.GetClienteValidoParaAtualizar();
            var atualizado = true;

            _repositoryFake.Setup(x => x.GetById(clienteCmd.Id)).Returns(cliente);
            _repositoryFake.Setup(pr => pr.Update(cliente)).Returns(atualizado);
            //Action
            var clienteAtualizado = _service.Update(clienteCmd);

            //Verify
            _repositoryFake.Verify(pr => pr.GetById(clienteCmd.Id), Times.Once);
            _repositoryFake.Verify(pr => pr.Update(cliente), Times.Once);
            clienteAtualizado.Should().BeTrue();
        }
コード例 #10
0
        public void Service_Cliente_PegarTodosOsClientes_DevePassar()
        {
            //Arrange
            var cliente       = ClienteObjectMother.GetClienteValido();
            var listaClientes = new List <Cliente>()
            {
                cliente
            }.AsQueryable();

            _repositoryFake.Setup(pr => pr.GetAll(0)).Returns(listaClientes);
            //Action
            var recebidos = _service.GetAll();

            //Assert
            _repositoryFake.Verify(pr => pr.GetAll(0), Times.Once);
            recebidos.Should().NotBeNull();
            recebidos.Count().Should().Be(listaClientes.Count());
            recebidos.First().Should().Be(listaClientes.First());
        }
コード例 #11
0
        public void Controller_Clientes_Get_DevePassar()
        {
            // Arrange
            var cliente  = ClienteObjectMother.GetClienteValido();
            var response = new List <Cliente>()
            {
                cliente
            }.AsQueryable();

            _clienteServiceMock.Setup(s => s.GetAll(0)).Returns(response);
            // Action
            var callback = _clientesController.Get();

            //Assert
            _clienteServiceMock.Verify(s => s.GetAll(0), Times.Once);
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <List <ClienteViewModel> > >().Subject;

            httpResponse.Content.Should().NotBeNullOrEmpty();
            httpResponse.Content.First().Id.Should().Be(cliente.Id);
        }
コード例 #12
0
        public void Controller_Clientes_Get_Com_Quantidade_DevePassar()
        {
            // Arrange
            var cliente    = ClienteObjectMother.GetClienteValido();
            var uri        = "http://localhost:9001/api/clientes?quantidade=3";
            var quantidade = 3;
            var response   = new List <Cliente>()
            {
                cliente, cliente, cliente
            }.AsQueryable();

            _clienteServiceMock.Setup(s => s.GetAll(quantidade)).Returns(response);
            _clientesController.Request = GetUri(uri);
            // Action
            var callback = _clientesController.Get();

            //Assert
            _clienteServiceMock.Verify(s => s.GetAll(quantidade), Times.Once);
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <List <ClienteViewModel> > >().Subject;

            httpResponse.Content.Should().NotBeNullOrEmpty();
            httpResponse.Content.Count.Should().Be(quantidade);
            httpResponse.Content.First().Id.Should().Be(cliente.Id);
        }