public async Task AddAuthorTest() { var options = getDatabase("AddAuthorDB"); await using (var context = new LibraryContext(options)) { var _manager = new LibraryManager(context); await _manager.AddAuthor(SingleAuthor()); await context.SaveChangesAsync(); Assert.Equal(1, await context.Authors.CountAsync()); Assert.Equal("AuthorName", context.Authors.Single().Name); } }
public async Task DeleteAuthorTest() { var options = getDatabase("DeleteAuthorDB"); await using (var context = new LibraryContext(options)) { var manager = new LibraryManager(context); await manager.AddAuthor(SingleAuthor()); await context.SaveChangesAsync(); var checkDelete = await manager.DeleteAuthor(1); Assert.Equal(1, checkDelete); } }
public async Task GetBookByIdTest() { var options = getDatabase("GetAuthorDB"); await using (var context = new LibraryContext(options)) { var _manager = new LibraryManager(context); await _manager.AddAuthor(SingleAuthor()); await context.SaveChangesAsync(); var author = await _manager.GetAuthorById(1); Assert.Equal(1, author.Id); Assert.Equal("AuthorName", context.Authors.Single().Name); } }
public async Task UpdateAuthor() { var options = getDatabase("UpdateAuthorDB"); await using (var context = new LibraryContext(options)) { var _manager = new LibraryManager(context); await _manager.AddAuthor(SingleAuthor()); await context.SaveChangesAsync(); } await using (var context = new LibraryContext(options)) { var _manager = new LibraryManager(context); var checkUpdate = await _manager.UpdateAuthor( new Author { Name = "AuthorName" }, 1); await context.SaveChangesAsync(); Assert.Equal(1, checkUpdate); Assert.Equal("AuthorName", context.Authors.Single().Name); } }