public async Task GetAllAuthorsShouldReturnAllAuthorsInRightOrder() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.Authors.AddRangeAsync( new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", }, new Author { FirstName = "first2", SecondName = "second2", LastName = "last2", }, new Author { FirstName = "afirst3", SecondName = "asecond3", LastName = "alast3", }); await db.SaveChangesAsync(); var authorsService = new AuthorsService(db); var result = await authorsService.GetAllAuthorsAsync <AuthorTestModel>(); var resultAuthor = result.FirstOrDefault(); Assert.Equal(3, result.Count()); Assert.Equal(3, resultAuthor.Id); Assert.Equal("afirst3", resultAuthor.FirstName); }
public async Task GetAllAuthorsShouldNotReturnDeletedAuthors() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.Authors.AddRangeAsync( new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", }, new Author { FirstName = "first2", SecondName = "second2", LastName = "last2", }, new Author { FirstName = "first3", SecondName = "second3", LastName = "last3", IsDeleted = true, DeletedOn = DateTime.UtcNow, }); await db.SaveChangesAsync(); var authorsService = new AuthorsService(db); var result = await authorsService.GetAllAuthorsAsync <AuthorTestModel>(); Assert.Equal(2, result.Count()); }