Esempio n. 1
0
        public void testDeleteBid()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_bid_from_db")
                          .Options;


            int    price       = 230;
            string description = "This is how much you owe me";
            var    start       = new DateTime(2017 / 01 / 12);
            var    end         = new DateTime(2017 / 01 / 12);
            Bid    bid         = new Bid();

            bid.bidPrice    = price;
            bid.description = description;
            bid.startDate   = start;
            bid.endDate     = end;

            using (ApplicationDbContext context = new ApplicationDbContext(options))
            {
                IBidRepository bidRepo = new BidRepository(context);
                bidRepo.AddBid(bid);
                bidRepo.Save();
            }

            // Use a seperate instance of the context to verify correct data was saved to the db
            using (var context = new ApplicationDbContext(options))
            {
                Assert.True(context.Bid.Count() == 1);
            }
            using (var context = new ApplicationDbContext(options))
            {
                IBidRepository bidRepo = new BidRepository(context);
                bidRepo.DeleteBid(bid.bidId);
                bidRepo.Save();
            }
            using (var context = new ApplicationDbContext(options))
            {
                Assert.True(context.Bid.Count() == 0);
            }
        }