public async Task ReturnCorrectAmount()
        {
            // setup in-memory database
            var dbContextOptions = new Microsoft.EntityFrameworkCore.DbContextOptionsBuilder <VmDbContext>().UseInMemoryDatabase("VMDB");
            var dbContext        = new VmDbContext(dbContextOptions.Options);

            // seed some data
            DataSeedingHelper.Seed(dbContext);

            var service = new VendingMachineService(dbContext);
            var product = (await service.GetProductsAsync()).First();

            var change   = new Dictionary <decimal, int>();
            var payCoins = new Dictionary <decimal, int>();

            payCoins.Add(0.1m, 5);
            payCoins.Add(1.0m, 2);

            var ok = await service.PurchaseAsync(product.Id, payCoins, change);

            Assert.True(ok);

            var changeSum = change.ToList().Sum(x => x.Key * x.Value);
            var paiedSum  = payCoins.ToList().Sum(x => x.Key * x.Value);

            Assert.Equal(changeSum, paiedSum - product.Price);
        }
Esempio n. 2
0
 public VmRepository(VmDbContext context)
 {
     Guard.ArgumentNotNull(context, "context");
     this.DbContext = context;
     this.DbSet     = this.DbContext.Set <TEntity>();
 }
Esempio n. 3
0
 public OrderRepository(VmDbContext dbContext)
     : base(dbContext)
 {
 }
Esempio n. 4
0
 public ProductRepository(VmDbContext dbContext)
     : base(dbContext)
 {
 }
 public VendingMachineService(VmDbContext dbContext)
 {
     this.dbContext = dbContext;
 }