Exemplo n.º 1
0
        public async Task ThrowExeptionWhenUserNoHAveBookForReturnReturnBook_Test()
        {
            var isbn      = "TestIsbn";
            var username  = "******";
            var reviewDto = new ReviewDto();

            var options = TestUtilities.GetOptions(nameof(ThrowExeptionWhenUserNoHAveBookForReturnReturnBook_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;
            }

            using (var assertContext = new LibrarySystemContext(options))
            {
                var sut = new BookWebService(assertContext);
                await sut.ReturnBookAsync(reviewDto);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
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());
            }
        }