public void PickCoinsForChange_NoEuroLeft_ReturnsChangeAsCents() { VendingCoinInventoryService vis = new VendingCoinInventoryService(); var invSnapshot = vis.CreateInventorySnapshot(); VendingCoinRepository.VendingCoins.Clear(); VendingCoinRepository.VendingCoins = new List <VendingCoin>() { new VendingCoin() { Value = .10M, Quantity = 100 }, new VendingCoin() { Value = .20M, Quantity = 100 }, new VendingCoin() { Value = .50M, Quantity = 100 }, }; var result = vis.PickCoinsForChange(1.30M); var changeAmount = result.Sum(s => s.Amount); Assert.Equal(1.30M, changeAmount); Assert.Equal(0, result.Count(c => Math.Truncate(c.Value) > 0)); vis.RestoreInventorySnapshot(invSnapshot.ToList()); }
public void PickCoinsForChange_ValidateEuroCentChangeAmount_ReturnsCorrectAmount() { VendingCoinInventoryService vis = new VendingCoinInventoryService(); var result = vis.PickCoinsForChange(1.30M); var changeAmount = result.Sum(s => s.Amount); Assert.Equal(1.30M, changeAmount); }
public void WithdrawVendingItem_WithdrawItemReturnChangeFromInsertedCoins_ReturnsFewerCoinsChange() { List <VendingCoin> insertedCoins = new List <VendingCoin>() { new VendingCoin() { Value = 1, Quantity = 1 }, new VendingCoin() { Value = .20M, Quantity = 1 }, new VendingCoin() { Value = .50M, Quantity = 1 }, new VendingCoin() { Value = .10M, Quantity = 1 }, new VendingCoin() { Value = .20M, Quantity = 1 }, }; VendingCoinInventoryService vis = new VendingCoinInventoryService(); var invSnapshot = vis.CreateInventorySnapshot(); VendingCoinRepository.VendingCoins.ToList().Clear(); VendingCoinRepository.VendingCoins = new List <VendingCoin>() { new VendingCoin() { Value = .10M, Quantity = 1 }, }; VendingMachineService vms = new VendingMachineService(new VendingCoinInventoryService()); var result = vms.WithdrawVendingItem(new VendingItem() { Name = "Tea", Price = 1.80M, Quantity = 10 }, insertedCoins); Assert.Equal(.20M, result.ReturnedAmount); Assert.Equal(.20M, result.ReturnedCoins.Where(w => w.Value == .20M).Select(s => s.Amount).FirstOrDefault()); Assert.Contains("Thank You", result.Message); vis.RestoreInventorySnapshot(invSnapshot.ToList()); }
public void WithdrawVendingItem_WithdrawItemNoChange_ReturnsInsertedCoins() { List <VendingCoin> insertedCoins = new List <VendingCoin>() { new VendingCoin() { Value = 1, Quantity = 1 }, new VendingCoin() { Value = .50M, Quantity = 1 }, new VendingCoin() { Value = .50M, Quantity = 1 }, }; VendingCoinInventoryService vis = new VendingCoinInventoryService(); var invSnapshot = vis.CreateInventorySnapshot(); VendingCoinRepository.VendingCoins.Clear(); VendingCoinRepository.VendingCoins = new List <VendingCoin>() { new VendingCoin() { Value = .10M, Quantity = 1 }, }; VendingMachineService vms = new VendingMachineService(new VendingCoinInventoryService()); var result = vms.WithdrawVendingItem(new VendingItem() { Name = "Tea", Price = 1.80M, Quantity = 10 }, insertedCoins); Assert.Equal(2, result.ReturnedAmount); Assert.Contains("Not enough coins", result.Message); vis.RestoreInventorySnapshot(invSnapshot.ToList()); }