Exemple #1
0
        public void Setup()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_find_book_user")
                      .Options;

            db = new FancyLibraryContext(options);

            userBookServices = new UserBookServices(db);

            db.Users.AddRange(FillUsers());
            db.Books.AddRange(FillBooks());
            db.UsersBooks.AddRange(FillUsersBooks());

            db.SaveChanges();
        }
Exemple #2
0
        public void DoesMethodReturnZeroWhenUserHasZeroBooks()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_books_count_zero")
                      .Options;

            db = new FancyLibraryContext(options);

            services = new UserBookServices(db);

            db.Books.AddRange(FillBooks());
            db.UsersBooks.AddRange(FillUsersBooks());
            db.Users.AddRange(FillUsers());

            db.SaveChanges();

            User user = db.Users.Last();

            Assert.That(0, Is.EqualTo(services.GetUserBooksCount(user)));
        }
Exemple #3
0
        public void IsFindingCorrectCountWhenUserHasMoreThanZeroBook()
        {
            options = new DbContextOptionsBuilder <FancyLibraryContext>()
                      .UseInMemoryDatabase(databaseName: "fancy_library_books_count_four")
                      .Options;

            db = new FancyLibraryContext(options);

            services = new UserBookServices(db);

            db.Books.AddRange(FillBooks());
            db.UsersBooks.AddRange(FillUsersBooks());
            db.Users.AddRange(FillUsers());

            db.SaveChanges();

            User user = db.Users.First();

            Assert.That(4, Is.EqualTo(services.GetUserBooksCount(user)));
        }