Esempio n. 1
0
        public void LoanBook_Should_Change_IsLoaned_To_False_For_Not_Loaned_Book()
        {
            var options = new DbContextOptionsBuilder <BookContext>()
                          .UseInMemoryDatabase(databaseName: "LoabBook")
                          .Options;

            using (var context = new BookContext(options))
            {
                context.BookItems.Add(new Book()
                {
                    Id       = 1,
                    Author   = "Mickiewicz Adam",
                    Title    = "Szyponka",
                    Isbn     = "12343",
                    IsLoaned = false
                });
                context.SaveChanges();
            }

            using (var context = new BookContext(options))
            {
                var service = new BookController(context);
                service.LoanBook(1);

                var results = service.FetchBooks();
                Assert.True(results.Value.First().IsLoaned);
            }
        }
Esempio n. 2
0
        public void FetchBooks_Should_Return_All_Books()
        {
            var options = new DbContextOptionsBuilder <BookContext>()
                          .UseInMemoryDatabase(databaseName: "FetchBooks")
                          .Options;

            var expectedResults = new List <Book>()
            {
                new Book()
                {
                    Id       = 1,
                    Author   = "Mickiewicz Adam",
                    Title    = "Szyponka",
                    Isbn     = "12343",
                    IsLoaned = false
                },
                new Book()
                {
                    Id       = 2,
                    Author   = "Justyna Czubówna",
                    Title    = "Hari Mona",
                    Isbn     = "46456",
                    IsLoaned = false
                }
            };

            using (var context = new BookContext(options))
            {
                context.BookItems.AddRange(expectedResults);
                context.SaveChanges();
            }

            using (var context = new BookContext(options))
            {
                var service = new BookController(context);
                var results = service.FetchBooks();
                Assert.Equal(expectedResults, results.Value);
            }
        }