예제 #1
0
        public async Task AllShouldReturnAllAuthors()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new AuthorsService(dbContext);

            var authors = new List <Author>
            {
                new Author {
                    Id = 1, Name = "Ivan Vazov", Bio = "Born in Sopot, Bulgaria"
                },
                new Author {
                    Id = 2, Name = "Aleko Konstantinov", Bio = "Born in Svishtov, Bulgaria"
                },
                new Author {
                    Id = 3, Name = "Elin Pelin", Bio = "Born in Bailovo, Bulgaria"
                }
            };

            foreach (var author in authors)
            {
                await dbContext.Authors.AddAsync(author);
            }
            await dbContext.SaveChangesAsync();

            var sortedPublishers = authors.OrderBy(x => x.Name).ToList();
            var actual           = service.All();

            Assert.Equal(sortedPublishers, actual);
        }