예제 #1
0
        public void PurchaseProduct_When_TwoOneEuroCoinsAddedChickenSoupProductPurchased_Then_ReturnSuccess()
        {
            //Arrange
            var coin         = Coin.OneEuro;
            var product      = Product.ChickenSoup;
            var coinReturned = new List <CoinSlot>
            {
                new CoinSlot(Coin.TwentyCents)
            };
            var inventory = new List <ProductSlot>
            {
                new ProductSlot(product)
            };
            var purse = new List <CoinSlot>
            {
                new CoinSlot(Coin.TwentyCents),
                new CoinSlot(Coin.FiftyCents)
            };
            var vendingMachine = new VendingMachine(inventory, purse);
            var sut            = new PurchaseProductUseCase(vendingMachine);

            //Act
            sut.InsertCoin(coin);
            sut.InsertCoin(coin);
            var actual = sut.PurchaseProduct(product);

            //Assert
            actual.HasFailed.Should().BeFalse();
            actual.ProductPurchased.Should().Be(product);
            actual.CoinsReturned.Should().BeEquivalentTo(coinReturned);
        }
예제 #2
0
        public void PurchaseProduct_When_OneEuroCoinsAddedEspressoProductPurchased_Then_ReturnFailed()
        {
            //Arrange
            var coin      = Coin.OneEuro;
            var product   = Product.Espresso;
            var inventory = new List <ProductSlot>
            {
                new ProductSlot(product)
            };
            var purse = new List <CoinSlot>
            {
                new CoinSlot(Coin.TwentyCents)
            };
            var vendingMachine = new VendingMachine(inventory, purse);
            var sut            = new PurchaseProductUseCase(vendingMachine);

            //Act
            sut.InsertCoin(coin);
            var actual = sut.PurchaseProduct(product);

            //Assert
            actual.HasFailed.Should().BeTrue();
            actual.PurchaseFailedReason.Should().Be(PurchaseFailedType.InsufficientCoins);
            actual.ProductPurchased.Should().Be(product);
        }
예제 #3
0
        public void InsertCoin_When_TwoFiftyCentCoinInserted_Then_ReturnSuccess()
        {
            //Arrange
            decimal expectedCurrentAmount = 1.00m;
            var     inventory             = new List <ProductSlot>();
            var     purse          = new List <CoinSlot>();
            var     vendingMachine = new VendingMachine(inventory, purse);
            var     coin           = Coin.FiftyCents;
            var     sut            = new PurchaseProductUseCase(vendingMachine);

            //Act
            sut.InsertCoin(coin);
            var actual = sut.InsertCoin(coin);

            //Assert
            actual.HasFailed.Should().BeFalse();
            actual.CurrentAmount.Should().Be(expectedCurrentAmount);
        }
예제 #4
0
        public void CancelPurchase_When_TwoTenCentCoinsAddedAndPurchaseCanceled_Then_ReturnSuccess()
        {
            //Arrange
            var coin          = Coin.TwentyCents;
            var coinsReturned = new List <CoinSlot>
            {
                new CoinSlot(Coin.TwentyCents, 2)
            };
            var inventory      = new List <ProductSlot>();
            var purse          = new List <CoinSlot>();
            var vendingMachine = new VendingMachine(inventory, purse);
            var sut            = new PurchaseProductUseCase(vendingMachine);

            //Act
            sut.InsertCoin(coin);
            sut.InsertCoin(coin);
            var actual = sut.CancelPurchase();

            //Assert
            actual.HasFailed.Should().BeFalse();
            actual.CoinsReturned.Should().BeEquivalentTo(coinsReturned);
        }
예제 #5
0
        public async Task ReceiveInsertedCoin(string coinId)
        {
            Coin coinToBeInserted;

            switch (coinId)
            {
            case "tenCentCoin":
                coinToBeInserted = Coin.TenCents;
                break;

            case "twentyCentCoin":
                coinToBeInserted = Coin.TwentyCents;
                break;

            case "fiftyCentCoin":
                coinToBeInserted = Coin.FiftyCents;
                break;

            case "oneEuroCoin":
                coinToBeInserted = Coin.OneEuro;
                break;

            default:
                await SendVendingMachineMessage("Coin not found, please try again!");

                throw new Exception($"Please insert valid coinId, actual: {coinId}");
            }

            var result = _useCase.InsertCoin(coinToBeInserted);

            string message;

            if (result.HasFailed)
            {
                message = $"{result.Message} failed, because amount of money can't exceed above €2,00 \r\n" +
                          $"Amount of money: €{result.CurrentAmount}";
            }
            else
            {
                message = $"{result.Message} \r\n" +
                          $"Amount of money: {result.CurrentAmount}";
            }

            await SendVendingMachineMessage(message);
        }