Пример #1
0
        public void Return_SuccessMessage()
        {
            string  assetName = "bitcoin";
            decimal price     = 3000;
            decimal cash      = 10000;
            int     amount    = 1;
            string  message   = $"Succesfully selled {amount} {assetName} " + (amount > 1 ? "assets" : "asset");

            var user        = new Mock <IUser>();
            var wallet      = new Mock <IWallet>();
            var market      = new Mock <IMarket>();
            var factory     = new Mock <IAssetFactory>();
            var userSession = new Mock <IUserSession>();

            user.Setup(x => x.Wallet).Returns(wallet.Object);

            wallet.Setup(x => x.Cash).Returns(cash);

            market.Setup(x => x.AssetPrice(assetName)).Returns(price);
            userSession.Setup(x => x.User).Returns(user.Object);

            var    broker = new BrokerMock(factory.Object, market.Object, userSession.Object);
            string result = broker.Sell(assetName, amount);

            Assert.AreEqual(message, result);
        }
Пример #2
0
        public void Invoke_WalletRemoveAsset()
        {
            string  assetName = "bitcoin";
            decimal price     = 3000;
            int     amount    = 1;
            string  message   = $"Succesfully purchased {amount} {assetName} " + (amount > 1 ? "assets" : "asset");

            var user        = new Mock <IUser>();
            var wallet      = new Mock <IWallet>();
            var market      = new Mock <IMarket>();
            var factory     = new Mock <IAssetFactory>();
            var asset       = new Mock <IAsset>();
            var userSession = new Mock <IUserSession>();

            user.Setup(x => x.Wallet).Returns(wallet.Object);

            factory.Setup <IAsset>(x => x.CreateAsset(assetName, price, amount)).Returns(asset.Object);

            wallet.Setup(x => x.RemoveAsset(asset.Object));

            market.Setup(x => x.AssetPrice(assetName)).Returns(price);
            userSession.Setup(x => x.User).Returns(user.Object);

            var    broker = new BrokerMock(factory.Object, market.Object, userSession.Object);
            string result = broker.Sell(assetName, amount);

            wallet.Verify(x => x.RemoveAsset(asset.Object), Times.Once);
        }