Ejemplo n.º 1
0
        public async Task AddRangeAsync_Test()
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "AddTestDatabase")
                          .Options;

            using (var context = new ApplicationContext(options))
            {
                context.Database.EnsureCreated();
                var repository  = new StudentRepository(context);
                var newStudents = new List <Student>
                {
                    new Student
                    {
                        Name   = "Test",
                        Mobile = "Q",
                        Email  = "Test"
                    },
                    new Student
                    {
                        Name   = "Test",
                        Mobile = "Q",
                        Email  = "Test"
                    }
                };
                var prevCount = repository.GetAll().Count();
                await repository.AddRangeAsync(newStudents);

                await context.SaveChangesAsync();

                var students = repository.GetAll();
                Assert.That(students.Count(), Is.EqualTo(prevCount + 2));
            }
        }