예제 #1
0
        public void SucessfullyBarterForFractionalGood()
        {
            MarketMock.Setup(x => x.GetPrice(JobInput.Object))
            .Returns(20);

            LifeNeed.Setup(x => x.Fractional)
            .Returns(true);

            JobInputs.SetProductAmount(JobInput.Object, 6);

            var changeRet = new ProductAmountCollection();

            changeRet.SetProductAmount(JobInput.Object, 5);

            // Add Storage and ForSale
            sut.Storage.AddProducts(LifeNeed.Object, 2);
            sut.ForSale.AddProducts(LifeNeed.Object, 2);

            // Setup Market Change for price.
            MarketMock.Setup(x => x.ChangeForPrice(JobInputs, 100))
            .Returns(changeRet);

            // Barter 1 LifeNeed for 1 JobInput.
            var result = sut.BarterGood(JobInputs, LifeNeed.Object, 2, MarketMock.Object);

            // check transaction
            AssertProductAmountIsEqual(result, LifeNeed, 1.2);
            AssertProductAmountIsEqual(result, JobInput, -6);

            // Ensure no change in storage or for sale
            AssertProductAmountIsEqual(sut.Storage, LifeNeed, 2);
            AssertProductAmountIsEqual(sut.ForSale, LifeNeed, 2);

            // Ensure that receipt doesn't go above storage or ForSale
            Assert.That(sut.Storage.GetProductValue(LifeNeed.Object),
                        Is.GreaterThanOrEqualTo(result.GetProductValue(LifeNeed.Object)));
            Assert.That(sut.ForSale.GetProductValue(LifeNeed.Object),
                        Is.GreaterThanOrEqualTo(result.GetProductValue(LifeNeed.Object)));
        }
예제 #2
0
        public void CompleteATransactionsCorrectly()
        {
            // create transaction
            var transaction = new ProductAmountCollection();

            transaction.AddProducts(LifeNeed.Object, 1);
            transaction.AddProducts(DailyNeed.Object, 2);
            transaction.AddProducts(LuxNeed.Object, 3);
            transaction.AddProducts(CurrencyMock1.Object, 4);
            transaction.AddProducts(CurrencyMock2.Object, 5);

            // complete transaction
            sut.CompleteTransaction(transaction);

            // check it's all there in Storage
            AssertProductAmountIsEqual(sut.Storage, LifeNeed, 1);
            AssertProductAmountIsEqual(sut.Storage, DailyNeed, 2);
            AssertProductAmountIsEqual(sut.Storage, LuxNeed, 3);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock1, 4);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock2, 5);

            // Check it's in For Sale
            AssertProductAmountIsEqual(sut.ForSale, LifeNeed, 1);
            AssertProductAmountIsEqual(sut.ForSale, DailyNeed, 2);
            AssertProductAmountIsEqual(sut.ForSale, LuxNeed, 3);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock1, 4);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock2, 5);

            // Add it again to double check
            sut.CompleteTransaction(transaction);

            // check it's all there in Storage
            AssertProductAmountIsEqual(sut.Storage, LifeNeed, 2);
            AssertProductAmountIsEqual(sut.Storage, DailyNeed, 4);
            AssertProductAmountIsEqual(sut.Storage, LuxNeed, 6);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock1, 8);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock2, 10);

            // Check it's in For Sale
            AssertProductAmountIsEqual(sut.ForSale, LifeNeed, 2);
            AssertProductAmountIsEqual(sut.ForSale, DailyNeed, 4);
            AssertProductAmountIsEqual(sut.ForSale, LuxNeed, 6);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock1, 8);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock2, 10);

            // check again, but subtract this time.
            transaction.SetProductAmount(LifeNeed.Object, -2);

            sut.CompleteTransaction(transaction);

            // check it's all there in Storage
            AssertProductAmountIsEqual(sut.Storage, LifeNeed, 0);
            AssertProductAmountIsEqual(sut.Storage, DailyNeed, 6);
            AssertProductAmountIsEqual(sut.Storage, LuxNeed, 9);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock1, 12);
            AssertProductAmountIsEqual(sut.Storage, CurrencyMock2, 15);

            // Check it's in For Sale
            AssertProductAmountIsEqual(sut.ForSale, DailyNeed, 6);
            AssertProductAmountIsEqual(sut.ForSale, LuxNeed, 9);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock1, 12);
            AssertProductAmountIsEqual(sut.ForSale, CurrencyMock2, 15);

            // ensure that Subtracted product is deleted
            Assert.That(sut.ForSale.Contains(LifeNeed.Object), Is.False);
        }
예제 #3
0
 public void ThrowNullArgumentIfProductISNull()
 {
     Assert.Throws <ArgumentNullException>(() => sut.SetProductAmount(null, 100));
 }