コード例 #1
0
        public void TestInsert()
        {
            Demo.Bll.Entities.Student student = new Demo.Bll.Entities.Student
            {
                FirstName = string.Format("FirstName{0}", DateTime.Now.Millisecond),
                LastName  = string.Format("LastName{0}", DateTime.Now.Millisecond)
            };
            DemoEntities       context        = new DemoEntities();
            IStudentRepository repo           = new StudentRepository(context);
            IStudentService    studentService = new StudentService(repo);
            int id = studentService.Insert(student);

            Assert.IsTrue(id > 0);
        }
コード例 #2
0
        public void TestUpdate()
        {
            Demo.Bll.Entities.Student student = new Demo.Bll.Entities.Student
            {
                FirstName = string.Format("FirstName{0}", DateTime.Now.Millisecond),
                LastName  = string.Format("LastName{0}", DateTime.Now.Millisecond)
            };
            DemoEntities       context        = new DemoEntities();
            IStudentRepository repo           = new StudentRepository(context);
            IStudentService    studentService = new StudentService(repo);
            int id           = studentService.Insert(student);
            var newFirstName = string.Format("{0}modified", student.FirstName);
            var newLastName  = string.Format("{0}modified", student.LastName);

            student.Id        = id;
            student.FirstName = newFirstName;
            student.LastName  = newLastName;
            studentService.Update(student);
            var modifiedStudent = studentService.GetById(id);

            Assert.IsTrue(modifiedStudent.FirstName == newFirstName);
            Assert.IsTrue(modifiedStudent.LastName == newLastName);
        }