コード例 #1
0
        public void TestDeletePerson()
        {
            using (var context = new School2Context(options))
            {
                var repository = new PersonRepository(context);
                repository.Delete(1);

                Assert.AreEqual(0, context.Person.Count());
            }
        }
コード例 #2
0
        public void TestAddPerson()
        {
            using (var context = new School2Context(options))
            {
                Assert.AreEqual(1, context.Person.Count());
                Assert.AreEqual("TestStudent", context.Person.Single().LastName);

                var repository = new PersonRepository(context);
            }
        }
コード例 #3
0
        public void TestInitialization()
        {
            options = new DbContextOptionsBuilder <School2Context>()
                      .UseInMemoryDatabase(databaseName: "InMemoryTestDb")
                      .Options;

            using (var context = new School2Context(options))
            {
                var repository = new PersonRepository(context);
                if (context.Person.Count() == 0)
                {
                    repository.Add("TestStudent", "Test", null, null, "Student");
                }
            }
        }
コード例 #4
0
        public void TestGetInstructors()
        {
            using (var context = new School2Context(options))
            {
                var repository = new PersonRepository(context);
                repository.Add("TestInstructor", "Test", null, null, "Instructor");
            }

            using (var context = new School2Context(options))
            {
                var repository = new PersonRepository(context);
                var insructors = repository.GetInstructors();

                Assert.AreEqual(1, insructors.Count());
                Assert.AreEqual("TestInstructor", insructors.First().LastName);
            }
        }
コード例 #5
0
 public PersonRepository(School2Context context)
 {
     _context = context;
 }