예제 #1
0
        public void AcceptAllOrders_Test()
        {
            var wallet     = new Item("Wallet", "Common wallet", 15);
            var loan       = new Item("loan", "It's a loan", -5000);
            var investment = new Item("Inheritence", "It's a loan", 5000);

            var orderPurchase = new PurhcaseOrder("Order1", "Buying wallet with a loan");
            var orderSales    = new SalesOrder("Order1", "Buying wallet with a loan");

            orderPurchase.AddItem(wallet);
            orderPurchase.AddItem(loan);

            orderSales.AddItem(wallet);
            orderSales.AddItem(investment);

            var ledger = new Ledger();

            ledger.AddOrder(orderPurchase);
            ledger.AddOrder(orderSales);

            var orderProcessor = new Mock <IOrderProcessor>();

            orderProcessor.Setup(m => m.Accept(orderSales));
            orderProcessor.Setup(m => m.Decline(orderSales));

            var financialCenter = new FinancialCenter(orderProcessor.Object);

            financialCenter.Process(ledger);

            orderProcessor.Verify(m => m.Decline(orderSales), Times.Never);
            orderProcessor.Verify(m => m.Accept(orderSales), Times.Once);
            orderProcessor.Verify(m => m.Decline(orderPurchase), Times.Never);
            orderProcessor.Verify(m => m.Accept(orderPurchase), Times.Once);
        }
예제 #2
0
        public void Process_SalesOrdersOnly_Accepted_Test()
        {
            var wallet = new Item("Wallet", "Common wallet", 15);
            var loan   = new Item("Inheritence", "It's a loan", 5000);

            var order = new SalesOrder("Order1", "Buying wallet with a loan");

            order.AddItem(wallet);
            order.AddItem(loan);

            var ledger = new Ledger();

            ledger.AddOrder(order);

            var orderProcessor = new Mock <IOrderProcessor>();

            orderProcessor.Setup(m => m.Accept(order));
            orderProcessor.Setup(m => m.Decline(order));

            var financialCenter = new FinancialCenter(orderProcessor.Object);

            financialCenter.Process(ledger);

            orderProcessor.Verify(m => m.Decline(order), Times.Never);
            orderProcessor.Verify(m => m.Accept(order), Times.Once);
        }
예제 #3
0
        public void Adding_SingleItem_Test()
        {
            var wallet = new Item("Wallet", "Common wallet", 15);
            var loan   = new Item("Loan1", "It's a loan", -5000);

            var order = new SalesOrder("Order1", "Buying wallet with a loan");

            order.AddItem(wallet);
            order.AddItem(loan);

            var       itemCount     = order.Get().Count();
            const int expectedCount = 2;

            Assert.Equal(expectedCount, itemCount);
        }
예제 #4
0
        public async Task AddSalesOrderItemAsync(Guid salesOrderId, Guid itemId, Guid priceListId, int units = 1)
        {
            SalesOrder salesOrder = await _salesOrderRepository.GetByIdAsync(salesOrderId);

            Item item = await _itemRepository.GetByIdAsync(itemId);

            ItemOrdered itemQuoted = new(item.Id, item.Name, item.Description);

            PriceList priceList = await _priceListRepository.GetByIdAsync(priceListId);

            SalesOrderItem salesOrderItem = new(itemQuoted, priceList.UnitPrice, units);

            salesOrder.AddItem(salesOrderItem);

            await _salesOrderRepository.UpdateAsync(salesOrder);
        }