예제 #1
0
        public void UpdateAmount_WhenAssetIsInThePortfolio()
        {
            // Arrange
            string  assetName   = "Bitcoin";
            decimal cash        = 10000;
            decimal assetPrice  = 5000;
            int     assetAmount = 2;

            var assetMock = new Mock <IAsset>();

            assetMock.SetupProperty(x => x.Price, assetPrice);
            assetMock.Setup(x => x.Name).Returns(assetName);
            assetMock.SetupProperty(x => x.Amount, assetAmount);

            // Act

            var wallet = new Wallet(cash);

            wallet.AddAsset(assetMock.Object);
            wallet.AddAsset(assetMock.Object);

            // Assert

            var actual = wallet.Portfolio[assetName].Amount;

            Assert.AreEqual(4, actual);
        }
예제 #2
0
        public void RemoveAsset_When_PortfolioAmountIsZero()
        {
            // Arrange
            string  assetName   = "Bitcoin";
            decimal cash        = 10000;
            decimal assetPrice  = 5000;
            int     assetAmount = 2;

            var assetMock  = new Mock <IAsset>();
            var assetMock2 = new Mock <IAsset>();

            assetMock.SetupProperty(x => x.Price, assetPrice);
            assetMock.Setup(x => x.Name).Returns(assetName);
            assetMock.SetupProperty(x => x.Amount, assetAmount);

            assetMock2.SetupProperty(x => x.Price, assetPrice);
            assetMock2.Setup(x => x.Name).Returns(assetName);
            assetMock2.SetupProperty(x => x.Amount, assetAmount);
            // Act

            var wallet = new Wallet(cash);

            wallet.AddAsset(assetMock.Object);
            wallet.AddAsset(assetMock2.Object);
            wallet.RemoveAsset(assetMock.Object);
            var actual = wallet.Portfolio.ContainsKey(assetName);

            // Assert
            Assert.AreEqual(false, actual);
        }
예제 #3
0
        public void ThrowArgumentException_PortfolioAmountIsLessThanZero()
        {
            // Arrange
            string  assetName   = "Bitcoin";
            decimal cash        = 10000;
            decimal assetPrice  = 5000;
            int     assetAmount = 2;

            var assetMock  = new Mock <IAsset>();
            var assetMock2 = new Mock <IAsset>();

            assetMock.SetupProperty(x => x.Price, assetPrice);
            assetMock.Setup(x => x.Name).Returns(assetName);
            assetMock.SetupProperty(x => x.Amount, assetAmount);

            assetMock2.SetupProperty(x => x.Price, assetPrice);
            assetMock2.Setup(x => x.Name).Returns(assetName);
            assetMock2.SetupProperty(x => x.Amount, assetAmount + 5);
            // Act

            var wallet = new Wallet(cash);

            wallet.AddAsset(assetMock.Object);

            // Assert
            Assert.ThrowsException <ArgumentException>(() => wallet.RemoveAsset(assetMock2.Object));
        }
예제 #4
0
        public void AddAsset_WhenItsNotInThePortfolio()
        {
            // Arrange
            string  assetName   = "Bitcoin";
            decimal cash        = 10000;
            decimal assetPrice  = 5000;
            int     assetAmount = 1;

            var assetMock = new Mock <IAsset>();

            assetMock.Setup(x => x.Price).Returns(assetPrice);
            assetMock.Setup(x => x.Name).Returns(assetName);
            assetMock.Setup(x => x.Amount).Returns(assetAmount);

            // Act
            var wallet = new Wallet(cash);

            wallet.AddAsset(assetMock.Object);

            // Assert
            var actual = wallet.Portfolio[assetName];

            Assert.AreSame(assetMock.Object, actual);
        }