public static LibraryContext Create()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;


            var context = new LibraryContext(options);


            var books = new[] {
                new BookEntity
                {
                    ISBN  = "9781449331818",
                    Title = "Learning JavaScript Design Patterns"
                },
                new BookEntity
                {
                    ISBN  = "9781449331818",
                    Title = "Learning JavaScript Design Patterns"
                },
                new BookEntity
                {
                    ISBN  = "9781491950296",
                    Title = "Programming JavaScript Applications"
                }
            };

            context.AddRange(books);
            context.SaveChanges();
            return(context);
        }
 public void Batch_Add()
 {
     using (var ctx = new LibraryContext())
     {
         ctx.AddRange
         (
             new Book {
             Title = "Title 1", Isbn = "XXXX1", AuthorId = 1
         },
             new Book {
             Title = "Title 2", Isbn = "XXXX2", AuthorId = 1
         },
             new Book {
             Title = "Title 3", Isbn = "XXXX3", AuthorId = 1
         }
         );
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: "TestDatabase")
                          .Options;

            _context        = new LibraryContext(options);
            _loanController = new LoanController(new LibraryContext(options));
            var loans = new List <Loan>
            {
                new Loan {
                    Id = 1, Volume_Id = 1, Member_SSN = "123", Checkout_Date = DateTime.Now, Expiry_Date = DateTime.Now, Is_Returned = false
                },
                new Loan {
                    Id = 2, Volume_Id = 3, Member_SSN = "456", Checkout_Date = DateTime.Now, Expiry_Date = DateTime.Now, Is_Returned = true
                }
            };

            _context.AddRange(loans);
            _context.SaveChanges();
        }