public void Setup() { _amountToPay = 100; _orderctrl = Substitute.For <IOrderController>(); _paymentController = Substitute.For <IPaymentController>(); _paymentController.ExecuteTransaction(Arg.Any <Transaction>()).Returns(true); _paymentControllerFail = Substitute.For <IPaymentController>(); _paymentControllerFail.ExecuteTransaction(Arg.Any <Transaction>()).Returns(false); _productController = Substitute.For <IProductController>(); _orderctrl.MissingAmount().Returns(_amountToPay); _orderControllerMissingNone = Substitute.For <IOrderController>(); _orderControllerMissingNone.MissingAmount().Returns(0); _receiptctrl = Substitute.For <IReceiptController>(); _trans = Substitute.For <Transaction>(); _orderctrl.CurrentOrder.Returns(new SalesOrder()); _orderControllerMissingNone.CurrentOrder.Returns(new SalesOrder()); _product = new Product("Fedt", 100, true); _paymentType = PaymentType.Cash; _description = "Description"; _discount = new Discount { Description = "Test Discount", Id = 0, Percent = 10 }; _uut = new SalesController(_orderctrl, _receiptctrl, _productController, _paymentController); }
/// <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); }
public void ExecuteTransaction_TransactionCompleted_CallCashDrawerOpen() { _uut.ExecuteTransaction(_cashTransaction); _fakeCashDrawer.Received(1).Open(); }