コード例 #1
0
        public async Task AllShouldReturnAllPublishers()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext  = new BookTubeContext(optionsBuilder.Options);
            var service    = new PublisherService(dbContext);
            var publishers = new List <Publisher>
            {
                new Publisher {
                    Name = "Siela", Contacts = "Sofia, Bulgaria"
                },
                new Publisher {
                    Name = "East-West", Contacts = "Some Contacs"
                },
                new Publisher {
                    Name = "Anubis", Contacts = "Ruse, Bulgaria"
                }
            };

            foreach (var publisher in publishers)
            {
                await dbContext.Publishers.AddAsync(publisher);
            }
            await dbContext.SaveChangesAsync();

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

            Assert.Equal(sortedPublishers, actual);
        }