Example #1
0
        public void InitiatePdv_With_Positive_Balance_For_BankCoins()
        {
            Pdv _pdv = new Pdv();

            _pdv.InitiatePdv(null, GenerateTestBankCoins);

            Assert.True(_pdv.IsValid);
        }
Example #2
0
        public void Compute_With_Insufficient_Pdv_Balance()
        {
            Pdv _pdv = new Pdv();

            _pdv.InitiatePdv(GenerateTestBankNotesInsufficient);

            Assert.Throws <InsufficientPdvBalanceError>(() => _pdv.Compute(80, 100));
        }
Example #3
0
        public void CheckBalance_Not_OK()
        {
            Pdv pdv = new Pdv();

            pdv.InitiatePdv();
            var check = pdv.CheckBalance(1500);

            Assert.False(check);
        }
Example #4
0
        public void CheckBalance_OK()
        {
            Pdv pdv = new Pdv();

            pdv.InitiatePdv();
            var check = pdv.CheckBalance(70);

            Assert.True(check);
        }
Example #5
0
        public void Compute_With_Suficient_Pdv_Balance()
        {
            Pdv _pdv = new Pdv();

            _pdv.InitiatePdv(GenerateTestBankNotes);
            _pdv.Compute(80, 100);

            Assert.True(_pdv.IsClosed);
        }
Example #6
0
        public void InitiatePdv_With_Invalid_Balance_For_BankCoins()
        {
            List <int> coins = new List <int>
            {
                0,
                -01,
                -05
            };

            Pdv _pdv = new Pdv();

            Assert.Throws <PdvIniatializationError>(() => _pdv.InitiatePdv(coins, null));
        }
Example #7
0
        public void InitiatePdv_With_Invalid_Balance_For_BankNotes()
        {
            List <int> notes = new List <int>
            {
                0,
                -10,
                -50
            };

            Pdv _pdv = new Pdv();

            Assert.Throws <PdvIniatializationError>(() => _pdv.InitiatePdv(notes, null));
        }
Example #8
0
        public Pdv PayBill(double payment, double total)
        {
            try
            {
                var _pdv = new Pdv();
                _pdv.InitiatePdv();
                _pdv.Compute(total, payment);

                // A gravação e tratativas do Histórico também poderia ser controlada
                // por um evento e um controlador deste evento
                // permitindo desacoplar mais a lógica deste código

                if (_pdv.IsClosed.HasValue && _pdv.IsClosed.Value)
                {
                    var historyIn = new PdvHistory
                    {
                        Amount        = payment,
                        CreatedAt     = DateTime.Now,
                        OperationType = OperationType.In
                    };
                    _unitOfWork.PdvHistoryRepository.Insert(historyIn);

                    if (_pdv.BankCoinsToReturn.Count > 0 || _pdv.BankNotesToReturn.Count > 0)
                    {
                        var historyOut = new PdvHistory
                        {
                            Amount        = _pdv.BankNotesToReturn.Sum(b => b) + _pdv.BankCoinsToReturn.Sum(b => b),
                            CreatedAt     = DateTime.Now,
                            OperationType = OperationType.Out
                        };
                        _unitOfWork.PdvHistoryRepository.Insert(historyOut);
                    }
                }

                return(_pdv);
            }
            catch (Exception)
            {
                throw;
            }
        }