public void DenominationBalanceTest() { //Arrange var options = new DbContextOptionsBuilder <AtmContext>() .UseInMemoryDatabase($"CourseDatabaseForTesting{Guid.NewGuid()}") .Options; using (var context = new AtmContext(options)) { var inventories = new Inventory[] { new Inventory { Denomination = 100, BillQuantity = 10 }, new Inventory { Denomination = 50, BillQuantity = 10 }, new Inventory { Denomination = 20, BillQuantity = 10 }, new Inventory { Denomination = 10, BillQuantity = 10 }, new Inventory { Denomination = 5, BillQuantity = 10 }, new Inventory { Denomination = 1, BillQuantity = 10 } }; foreach (Inventory i in inventories) { context.Inventories.Add(i); } context.SaveChanges(); } using (var context = new AtmContext(options)) { var repo = new Models.AtmRepository(context); //Act var obj = repo.DenominationBalance(100); //Assert Assert.Equal(10, obj.BillQuantity); } }
public void SimpleTest() { //Arrange var options = new DbContextOptionsBuilder <AtmContext>() .UseInMemoryDatabase($"CourseDatabaseForTesting{Guid.NewGuid()}") .Options; using (var context = new AtmContext(options)) { var inventories = new Inventory[] { new Inventory { Denomination = 100, BillQuantity = 10 }, new Inventory { Denomination = 50, BillQuantity = 10 }, new Inventory { Denomination = 20, BillQuantity = 10 }, new Inventory { Denomination = 10, BillQuantity = 10 }, new Inventory { Denomination = 5, BillQuantity = 10 }, new Inventory { Denomination = 1, BillQuantity = 10 } }; foreach (Inventory i in inventories) { context.Inventories.Add(i); } context.SaveChanges(); } using (var context = new AtmContext(options)) { var repo = new Models.AtmRepository(context); //Withdraw $208 repo.Withdraw(208); foreach (var item in repo.Balance) { switch (item.Denomination) { case 100: Assert.Equal(8, item.BillQuantity); break; case 50: Assert.Equal(10, item.BillQuantity); break; case 20: Assert.Equal(10, item.BillQuantity); break; case 10: Assert.Equal(10, item.BillQuantity); break; case 5: Assert.Equal(9, item.BillQuantity); break; case 1: Assert.Equal(7, item.BillQuantity); break; } } //Withdraw $9 repo.Withdraw(9); foreach (var item in repo.Balance) { switch (item.Denomination) { case 100: Assert.Equal(8, item.BillQuantity); break; case 50: Assert.Equal(10, item.BillQuantity); break; case 20: Assert.Equal(10, item.BillQuantity); break; case 10: Assert.Equal(10, item.BillQuantity); break; case 5: Assert.Equal(8, item.BillQuantity); break; case 1: Assert.Equal(3, item.BillQuantity); break; } } //Withdraw $9 ArgumentException exception = Assert.Throws <ArgumentException>(() => repo.Withdraw(9)); Assert.Equal("Failure: insufficient funds", exception.Message); //Get Denomination for $20 var obj = repo.DenominationBalance(20); Assert.Equal(10, obj.BillQuantity); //Get Denomination for $1 obj = repo.DenominationBalance(1); Assert.Equal(3, obj.BillQuantity); //Get Denomination for $100 obj = repo.DenominationBalance(100); Assert.Equal(8, obj.BillQuantity); //Restock repo.Restock(); foreach (var item in repo.Balance) { switch (item.Denomination) { case 100: Assert.Equal(10, item.BillQuantity); break; case 50: Assert.Equal(10, item.BillQuantity); break; case 20: Assert.Equal(10, item.BillQuantity); break; case 10: Assert.Equal(10, item.BillQuantity); break; case 5: Assert.Equal(10, item.BillQuantity); break; case 1: Assert.Equal(10, item.BillQuantity); break; } } } }