Exemplo n.º 1
0
 public void SetUp()
 {
     _id = 1;
     _fakeTransaction = Substitute.For<Transaction>();
     _fakeDalFacade = Substitute.For<IDalFacade>();
     _uut = new PaymentDao(_fakeDalFacade);
 }
Exemplo n.º 2
0
        public void CreateReceipt_GenerateReceiptFromAnEmptyTransaction_ReceiptContainsOneString()
        {
            var transaction = new Transaction();
            _uut.CreateReceipt(transaction);

            _printer.Received(1).Print();
        }
Exemplo n.º 3
0
 /// <summary>
 /// To update a transaction
 /// </summary>
 /// <param name="transaction">Transaction to be updated</param>
 // ------------------ Update ----------------------- //
 public void Update(Transaction transaction)
 {
     using (var uow = _dalFacade.UnitOfWork)
     {
         uow.TransactionRepository.Update(transaction);
         uow.Save();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Funticon to insert a transaction in the database
 /// </summary>
 /// <param name="transaction">Transaction to be inserted</param>
 // ------------------ Insert ----------------------- //
 public void Insert(Transaction transaction)
 {
     using (var uow = _dalFacade.UnitOfWork)
     {
         uow.SalesOrderRepository.Update(transaction.SalesOrder);
         uow.TransactionRepository.Insert(transaction);
         uow.Save();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates and returns a Transaction.
        /// </summary>
        /// <param name="amountToPay">The amount to be payed.</param>
        /// <param name="description">A description for the payment.</param>
        /// <param name="payment">The provider for the payment.</param>
        /// <returns>A Transaction.</returns>
        public Transaction CreateTransaction(int amountToPay, string description, PaymentType payment)
        {
            var transaction = new Transaction
            {
                Date = DateTime.Now,
                Status = TransactionStatus.Created,
                SalesOrder = _orderController.CurrentOrder,
                Price = amountToPay,
                PaymentType = payment,
                Description = description
            };

            var paymentCompleted = _paymentController.ExecuteTransaction(transaction);
            if (paymentCompleted)
            {
                transaction.Description = "Transaction completed";
                return transaction;
            }
            transaction.Description = "Transaction failed";

            return transaction;
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            _logger = LogFactory.GetLogger(typeof (Program));

            IDatabaseInitializer<CashRegisterContext> seed;

            // Empty
            // seed = new EmptyInitializer();

            // Kalle Seed
            //seed = new CashProductInitializer();

            // Lærke Seed
            seed = new FullProductInitializer();

            using (var contex = new CashRegisterContext(seed))
            {
                Console.WriteLine("FLAF");
                contex.Database.Initialize(true);
                contex.SaveChanges();
            }

            IDalFacade dalFacade = new DalFacade();
            IProductDao pd = new ProductDao(dalFacade);
            IProductController pc = new ProductController(pd);

            SalesOrder o;

            using (var uow = dalFacade.UnitOfWork)
            {
                var d = new Discount
                {
                    Description = "Discount",
                    Percent = 0,
                };
                uow.DiscountRepository.Insert(d);
                uow.Save();

                o = new SalesOrder
                {
                    Date = DateTime.Now,
                    Status = OrderStatus.Created,
                };
                uow.SalesOrderRepository.Insert(o);

            }
            using (var uow = dalFacade.UnitOfWork)
            {

                var t = new Transaction
                {
                    Date = DateTime.Now,
                    Description = "Flaf",
                    PaymentType = PaymentType.Cash,
                    Price = 20,
                    SalesOrder = o,
                    Status = TransactionStatus.Created
                };
                uow.TransactionRepository.Insert(t);
                uow.Save();
            }

                Console.WriteLine("ProductTabs");
            foreach (var productTab in pc.ProductTabs)
            {
                Console.WriteLine(productTab.Priority + ": " + productTab.Name);
                foreach (var productType in productTab.ProductTypes)
                {
                    Console.WriteLine("\t" + productType.Name);
                    foreach (var productGroup in productType.ProductGroups)
                    {
                        Console.WriteLine("\t\t" + productGroup.Name);
                        foreach (var product in productGroup.Products)
                        {
                            Console.WriteLine("\t\t\t" + product.Name);
                        }
                    }
                }
            }

            _logger.Fatal("Fatal");
            _logger.Err("Error");
            _logger.Warn("Warn");
            _logger.Info("Info");
            _logger.Debug("Debug");
        }
Exemplo n.º 7
0
 /// <summary>
 /// To print a transaction
 /// </summary>
 /// <param name="transaction">Transaction to be printet</param>
 public void PrintTransaction(Transaction transaction)
 {
     _receiptController.CreateReceipt(transaction);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Is called to execute a transaction
        /// </summary>
        /// <param name="transaction">The transaction to execute</param>
        /// <returns>True if transaction went well</returns>
        public bool ExecuteTransaction(Transaction transaction)
        {
            var paymentProvider = _paymentProviders.First(p => p.Type == transaction.PaymentType);

            var transferSuccess = paymentProvider.TransferAmount(transaction.Price, transaction.Description);
            var transferStatus = paymentProvider.TransactionStatus();

            if (transferSuccess && transferStatus)
            {
                CashDrawer.Open();
                transaction.Status = TransactionStatus.Completed;
                _paymentDao.Insert(transaction);

                return true;
            }

            transaction.Status = TransactionStatus.Failed;
            _paymentDao.Insert(transaction);
            return false;
        }
Exemplo n.º 9
0
        public void SetUp()
        {
            _cashPayment = new CashPayment();
            _nets = Substitute.ForPartsOf<Nets>();
            _nets.When(x => x.TransferAmount(Arg.Any<int>(), Arg.Any<string>())).DoNotCallBase();
            _nets.TransferAmount(Arg.Any<int>(), Arg.Any<string>()).Returns(false);

            _paymentProviders = new List<IPaymentProvider> {_cashPayment, _nets};

            _fakePaymentDao = Substitute.For<IPaymentDao>();
            _fakeReceiptController = Substitute.For<IReceiptController>();
            _fakeCashDrawer = Substitute.For<ICashDrawer>();
            _fakeCashDrawer.CashChange.Returns(1000);

            _uut = new PaymentController(_paymentProviders, _fakeReceiptController, _fakePaymentDao, _fakeCashDrawer);

            _cashTransaction = new Transaction()
            {

                Description = "noget",
                PaymentType = PaymentType.Cash,
                Price = 100,
            };

            _netTransaction = new Transaction()
            {
                Description = "noget",
                PaymentType = PaymentType.Nets,
                Price = 100,
            };
        }
Exemplo n.º 10
0
        /// <summary>
        /// Formats a new Receipt from a Transaction.
        /// </summary>
        /// <param name="transaction">The Transaction to be formatted and printed.</param>
        public virtual void CreateReceipt(Transaction transaction)
        {
            var receipt = new Receipt(_formatProvider);

            receipt.AddLine(string.Format(_formatProvider, "{0}\nDate: {1}\nId: {2}\n{3}\n\b", transaction.PaymentType, transaction.Date, transaction.Id, transaction.Price));

            Print(receipt);
        }