示例#1
0
        public async void GetAllAsync_ShouldReturnListOfEmployees()
        {
            // Arrange
            var employees = new List <Pet>
            {
                new Pet {
                    Id = 21, Name = "Dick", Type = "duck", OwnerId = 23
                },
                new Pet {
                    Id = 12, Name = "Mat", Type = "cat", OwnerId = 48
                }
            };

            var options = new DbContextOptionsBuilder <AppContext>()
                          .UseInMemoryDatabase(databaseName: "Pets1")
                          .Options;

            using (var appContext = new AppContext(options))
            {
                await appContext.Pets.AddRangeAsync(employees);

                await appContext.SaveChangesAsync();
            }

            using (var appContext = new AppContext(options))
            {
                var repo = new PetsRepository(appContext);

                // Act
                var result = await repo.GetAllAsync();

                // Assert
                Assert.IsAssignableFrom <IEnumerable <Pet> >(result);
                Assert.Equal(employees.Count, result.Count());
            }
        }