Пример #1
0
        public async Task LendBook_Test()
        {
            var title       = "TestTitle";
            var username    = "******";
            var lendBookDto = new BaseTitleDto();

            var options = TestUtilities.GetOptions(nameof(LendBook_Test));


            using (var actContext = new LibrarySystemContext(options))
            {
                await actContext.Books.AddAsync(new Book { Title = title });

                var user = await actContext.Users.AddAsync(new User { UserName = username });

                await actContext.SaveChangesAsync();

                lendBookDto.Title  = title;
                lendBookDto.UserId = user.Entity.Id;
            }


            using (var assertContext = new LibrarySystemContext(options))
            {
                var sut = new BookWebService(assertContext);
                await sut.LendBookAsync(lendBookDto);

                Assert.AreEqual(1, assertContext.BookLendings.Count());
            }
        }
Пример #2
0
        public async Task ThrowExeptionWhenBookIdIsNullReturnBook_Test()
        {
            var title     = "TestTitle";
            var username  = "******";
            var reviewDto = new ReviewDto();
            var lendDto   = new BaseTitleDto();

            var options = TestUtilities.GetOptions(nameof(ThrowExeptionWhenBookIdIsNullReturnBook_Test));

            using (var actContext = new LibrarySystemContext(options))
            {
                var book = await actContext.Books.AddAsync(new Book { Title = title });

                var user = await actContext.Users.AddAsync(new User { UserName = username });

                await actContext.SaveChangesAsync();

                reviewDto.UserId = user.Entity.Id;

                lendDto.UserId = user.Entity.Id;

                var bookLending = new BookWebService(actContext);
                await bookLending.LendBookAsync(lendDto);
            }

            using (var assertContext = new LibrarySystemContext(options))
            {
                var sut = new BookWebService(assertContext);
                await sut.ReturnBookAsync(reviewDto);
            }
        }
Пример #3
0
        public async Task RenewBook_Test()
        {
            var isbn     = "TestIsbn";
            var username = "******";
            var days     = 5;

            var renewBookDto = new RenewBookDto();
            var lendDto      = new BaseTitleDto();

            var options = TestUtilities.GetOptions(nameof(RenewBook_Test));

            using (var actContext = new LibrarySystemContext(options))
            {
                var book = await actContext.Books.AddAsync(new Book { ISBN = isbn });

                var user = await actContext.Users.AddAsync(new User { UserName = username });

                await actContext.SaveChangesAsync();

                renewBookDto.BookId = days;
                renewBookDto.BookId = book.Entity.Id;
                renewBookDto.UserId = user.Entity.Id;

                lendDto.Title  = book.Entity.Title;
                lendDto.UserId = user.Entity.Id;

                var bookLending = new BookWebService(actContext);
                await bookLending.LendBookAsync(lendDto);
            }

            using (var assertContext = new LibrarySystemContext(options))
            {
                var sut = new BookWebService(assertContext);
                await sut.RenewBookAsync(renewBookDto);

                var actuaDays = assertContext.BookLendings.Select(book => book.Date);

                Assert.IsNotNull(actuaDays);
            }
        }
Пример #4
0
        public async Task ReturnBook_Test()
        {
            var isbn      = "TestIsbn";
            var username  = "******";
            var reviewDto = new ReviewDto();
            var lendDto   = new BaseTitleDto();

            var options = TestUtilities.GetOptions(nameof(ReturnBook_Test));

            using (var actContext = new LibrarySystemContext(options))
            {
                var book = await actContext.Books.AddAsync(new Book { ISBN = isbn });

                var user = await actContext.Users.AddAsync(new User { UserName = username });

                await actContext.SaveChangesAsync();

                reviewDto.ISBN   = book.Entity.ISBN;
                reviewDto.BookId = book.Entity.Id;
                reviewDto.UserId = user.Entity.Id;

                lendDto.Title  = book.Entity.Title;
                lendDto.UserId = user.Entity.Id;

                var bookLending = new BookWebService(actContext);
                await bookLending.LendBookAsync(lendDto);
            }

            using (var assertContext = new LibrarySystemContext(options))
            {
                var sut = new BookWebService(assertContext);
                await sut.ReturnBookAsync(reviewDto);

                Assert.AreEqual(0, assertContext.BookLendings.Count());
            }
        }