コード例 #1
0
        public void IncreaseBuyerStockQty_DecreaseBuyerBalance()
        {
            var tradableType = new TradableType {
                Price = 1000, Type = "TestType1"
            };
            var buyerStock = new Stock {
                Quantity = 100, TradableType = tradableType
            };
            var stockForBuy = new Stock {
                Quantity = 10, TradableType = tradableType
            };

            var trader = new Trader
            {
                Balance = 100000,
                Assets  = new List <Stock>
                {
                    new Stock(),
                    buyerStock
                }
            };

            BusinessService.Acquire(trader, stockForBuy);
            Assert.AreEqual(buyerStock.Quantity, 110);
            Assert.AreEqual(trader.Balance, 90000);
        }
コード例 #2
0
        public void AddNewStockTypeToBuyer()
        {
            var tradableType = new TradableType {
                Price = 1000, Type = "TestType1"
            };
            var stockForBuy = new Stock {
                Quantity = 10, TradableType = tradableType
            };

            var trader = new Trader
            {
                Balance = 100000,
                Assets  = new List <Stock>
                {
                    new Stock(),
                    new Stock(),
                    new Stock()
                }
            };

            BusinessService.Acquire(trader, stockForBuy);
            Assert.AreEqual(trader.Assets.Count, 4);
            Assert.AreEqual(trader.Balance, 90000);
            Assert.AreEqual(trader.Assets.Single(x => x.TradableType == tradableType), stockForBuy);
        }
コード例 #3
0
        public void DecreaseSellerStockQuantity_IncreaseSellerBalance()
        {
            var tradableType = new TradableType {
                Price = 1000, Type = "TestType1"
            };
            var sellerStock = new Stock {
                Quantity = 100, TradableType = tradableType
            };
            var stockForSell = new Stock {
                Quantity = 10, TradableType = tradableType
            };

            var trader = new Trader
            {
                Balance = 100000,
                Assets  = new List <Stock>
                {
                    new Stock(),
                    sellerStock
                }
            };

            BusinessService.Withdraw(trader, stockForSell);
            Received.InOrder(() => { BusinessService.UpdateEntity(sellerStock); });

            Assert.AreEqual(sellerStock.Quantity, 90);
            Assert.AreEqual(trader.Balance, 110000);
        }
コード例 #4
0
        public void BuyerWithdrawStock_SelsNewOperation()
        {
            var tradableType = new TradableType {
                Price = 1000, Type = "TestType1"
            };
            var stock = new Stock {
                Quantity = 10, TradableType = tradableType
            };
            var seller = new Trader
            {
                Assets = new List <Stock>
                {
                    new Stock {
                        Quantity = 100, TradableType = tradableType
                    },
                    new Stock()
                },
                TraderInfo = new IndividualInfo {
                    SecondName = "SellerName"
                },
                Balance = 100000
            };
            var buyer = new Trader
            {
                Assets = new List <Stock>
                {
                    new Stock {
                        Quantity = 100, TradableType = tradableType
                    },
                    new Stock()
                },
                TraderInfo = new IndividualInfo {
                    SecondName = "BuyerName"
                },
                Balance = 100000
            };

            var trade = BusinessService.ProcessTrade(seller, buyer, stock);

            Received.InOrder(() =>
            {
                BusinessService.Withdraw(seller, stock);
                BusinessService.Acquire(buyer, stock);
                BusinessService.UpdateEntity(buyer);
                BusinessService.UpdateEntity(seller);
            });
            Assert.AreEqual(trade.TradableType, stock.TradableType);
            Assert.AreEqual(trade.TradableAmount, 10);
            Assert.AreEqual(trade.TradeAmount, 10000);
            Assert.AreEqual(trade.Buyer.TraderInfo.SecondName, buyer.TraderInfo.SecondName);
            Assert.AreEqual(trade.Seller.TraderInfo.SecondName, seller.TraderInfo.SecondName);
        }