예제 #1
0
        public void TestEatLunchFromCardBooleanTrue()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(11);

            Assert.AreEqual(true, terminal.EatLunch(card), "Buying coffee should return true if balance is enough");
        }
예제 #2
0
        public void TestEatLunchFromCardBooleanFalse()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(2);

            Assert.AreEqual(false, terminal.EatLunch(card), "Buying coffee should return false if balance is not enough");
        }
예제 #3
0
        public void UpdateBalance(Card card)
        {
            try
            {
                PaymentActivasionValidarior(card);
                MinimumBalanceValidator(card);
                card = CreateNotificasion(card);
                var crudCard = new CardCrud();
                crudCard.UpdateBalance(card);
                Payment payment = new Payment();
                payment.Date       = DateTime.Now;
                payment.IssuerUser = card.User;
                payment.Card       = card;
                payment.Amount     = card.newBalance;
                payment.Detail     = "Recarga de saldo del usario";
                Glosary glosary = new Glosary();
                glosary.PkIdTerm    = 4;
                payment.PaymentType = glosary;
                payment             = PayCrud.CreateParkingPayment(payment);
                PaymentTerminal py = new PaymentTerminal();
                py.PercentageUsed = 0;
                py.TerminalPayed  = card.Terminal;
                py.PaymentGot     = payment;

                PTCrud.Create(py);
            }
            catch (Exception ex)
            {
                ExceptionManager.GetInstance().Process(ex);
            }
        }
예제 #4
0
        public void TestDrinkCoffeeFromCard()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(5);

            terminal.DrinkCoffee(card);
            Assert.AreEqual(Math.Round(Convert.ToDouble("2.5", System.Globalization.CultureInfo.InvariantCulture), 2), Math.Round(card.balance, 2), "Buying coffee should decrease tha amount by 2.5!");
        }
예제 #5
0
        public void TestTerminalConstructor()
        {
            PaymentTerminal terminal = new PaymentTerminal();

            Assert.AreEqual(1000, terminal.money, "Terminal should start with 1000 cash!");
            Assert.AreEqual(0, terminal.coffeeAmount, "Terminal should start with 0 coffees sold");
            Assert.AreEqual(0, terminal.lunchAmount, "Terminal should start with 0 lunches sold");
        }
예제 #6
0
        public void TestEatLunchFromCardNotEnoughMoney()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(10);

            terminal.EatLunch(card);
            Assert.AreEqual(10, card.balance, "Lunch should not decrease the balance if there is not enough money!");
        }
예제 #7
0
        public void TestEatLunchFromCard()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(11);

            terminal.EatLunch(card);
            Assert.AreEqual(Math.Round(Convert.ToDouble("0.7", System.Globalization.CultureInfo.InvariantCulture), 2), Math.Round(Convert.ToDouble(card.balance, System.Globalization.CultureInfo.InvariantCulture), 2), "Lunch should decrease the balance by 10.3!");
        }
예제 #8
0
        public void TestAddMoneyToBalances()
        {
            PaymentTerminal terminal = new PaymentTerminal();
            PaymentCard     card     = new PaymentCard(10);

            terminal.AddMoneyToCard(card, 10);
            Assert.AreEqual(20, card.balance, "Adding money should increase the balance of the card!");
            Assert.AreEqual(1010, terminal.money, "Adding money should increase the money of the terminal!");
        }
예제 #9
0
 private void InitDependencies()
 {
     this.itemsCollection = new ContainableItemsCollection(this);
     this.itemsCollection.LoadFromFile(DatabaseFilePath);
     this.statisticsComponent = new StatisticsComponent(this);
     this.dispenser           = new Dispenser(this);
     this.dispenser.AddObserver(this.statisticsComponent);
     this.dispenser.AddObserver(this.itemsCollection);
     this.paymentTerminal = new PaymentTerminal();
     this.paymentTerminal.AddObserver(this.dispenser);
 }
예제 #10
0
        public void InitializeConstructors()
        {
            twixBand        = new ProductBand();
            paymentTerminal = new PaymentTerminal();
            dispenser       = new Dispenser();

            twixItem = ProductFactory.CreateTwixProduct();
            twixBand.Add(twixItem);
            ProductBand.Instance().Add(twixItem);

            paymentTerminal.Attach(dispenser);
        }
        /// <summary>
        /// Updates a ParkingBill
        /// </summary>
        /// <param name="pb"></param>
        public void UpdateParkingBill(ParkingBill pb)
        {
            try
            {
                ParkingBill exist = PBCrud.RetrieveParkingBillByCard <ParkingBill>(pb.ParkingCard);
                if (exist == null)
                {
                    throw new BusinessException(33);
                }
                exist.ParkedParking = PCrud.Retrieve <Parking>(exist.ParkedParking);
                exist.ParkingCard   = pb.ParkingCard;
                exist.EndDate       = pb.EndDate;
                exist.AmountHours   = Convert.ToInt32(Math.Round(exist.EndDate.Subtract(exist.BeginDate).TotalHours));

                if (exist.AmountHours > 8)
                {
                    exist.AmountHours = (exist.AmountHours / 24 + 1) * 24;
                }

                exist.TotalCost = exist.AmountHours * exist.ParkedParking.RentalCost;

                if (exist.ParkingCard.Balance - exist.TotalCost <= 0)
                {
                    throw new BusinessException(34);
                }

                exist.ParkingCard.Balance = exist.ParkingCard.Balance - exist.TotalCost;

                var payment = GetPayment(exist);
                payment = PYCrud.CreateParkingPayment(payment);

                var paymentTerminal = new PaymentTerminal
                {
                    Amount         = exist.TotalCost,
                    PercentageUsed = 0,
                    PaymentGot     = payment,
                    TerminalPayed  = exist.ParkingCard.Terminal,
                };

                PTCrud.Create(paymentTerminal);
                PBCrud.Update(exist);
                CCrud.UpdateBalance(exist.ParkingCard);
                exist.ParkedParking.OccupiedSpces -= 1;
                PCrud.ChangeOccupiedSpaces(exist.ParkedParking);
            }
            catch (Exception ex)
            {
                ExceptionManager.GetInstance().Process(ex);
            }
        }
        static void Main()
        {
            var paymentTerminal = new PaymentTerminal();

            try
            {
                // Vending Machine Out Of Service
                var pringlesItem = ProductFactory.CreatePringlesProduct();
                ProductBand.Instance().Add(pringlesItem);
                var dispenser = new Dispenser();
                paymentTerminal.Attach(dispenser);
            }
            catch (Exception exception)
            {
                if (exception is BandIsFullException)
                {
                    Console.WriteLine("Band is full! It can't store any items.");
                }
            }

            try
            {
                // New Customer Requests for a Pringles
                var visaCard = new CreditCard("4012888888881881");
                paymentTerminal.Pay(visaCard, 1, "Pringles");
            }
            catch (Exception exception)
            {
                if (exception is FormatException)
                {
                    Console.WriteLine("You entered a wrong value! Press any key and try again!");
                }
                if (exception is CardNotValidException)
                {
                    Console.WriteLine("This credit card is not valid! Try another payment method.");
                }
                if (exception is CardNotFoundException)
                {
                    Console.WriteLine("Card was not found! Payment canceled!");
                }
                if (exception is BandIsEmptyException)
                {
                    Console.WriteLine("Band is empty! You can't {0} any item!", exception.Message);
                }
            }

            Console.ReadKey();
        }
예제 #13
0
        public IHttpActionResult AddPaymentTerminal(PaymentTerminalModel model)
        {
            using (var dbContext = new DataContext())
            {
                if (dbContext.PaymentTerminals.Any(f => f.TerminalType == (Data.Enums.TerminalType)model.TerminalType && f.UUID == model.UUID))
                {
                    return(this.BadRequestEx(Error.PaymentTerminalAlreadyExist));
                }

                var paymentTerminal = new PaymentTerminal();
                paymentTerminal.UUID              = model.UUID;
                paymentTerminal.TerminalType      = (Data.Enums.TerminalType)model.TerminalType;
                paymentTerminal.ModifiedTimestamp = DateTime.Now;
                paymentTerminal.Status            = Data.Enums.Status.Active;

                dbContext.PaymentTerminals.Add(paymentTerminal);
                dbContext.SaveChanges();

                model.ID = paymentTerminal.ID;
                model.ModifiedTimestamp = paymentTerminal.ModifiedTimestamp;

                return(Ok(model));
            }
        }