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); }
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); }
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)); }
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); }