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); } }
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); } }
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()); } }