Пример #1
0
        public void testAddBid()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_bid_to_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 separate instance of the context to verify correct data was saved to database
            using (var context = new ApplicationDbContext(options))
            {
                IBidRepository bidRepo     = new BidRepository(context);
                var            bidRecieved = bidRepo.GetBidByID(bid.bidId);
                Assert.True(bidRecieved.bidPrice == price);
            }
        }
        public async Task <IActionResult> ItemPage(int partItem, string name, string phoneNumber, int bid)
        {
            ServiceReference1.AuctionItem auctionItem = await service.GetAuctionItemAsync(partItem);

            if (await service.ProvideBidAsync(partItem, bid, name, phoneNumber) == "OK")
            {
                auctionItem = await service.GetAuctionItemAsync(partItem);

                bidRepo.AddBid(partItem, name, bid, DateTime.Now);
            }

            return(View(auctionItem));
        }
Пример #3
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);
            }
        }