Ejemplo n.º 1
0
        public void SingleTableDoEdit(string code, string name, SchoolTypeEnum schooltype, string remark)
        {
            School s = new School();

            s.SchoolCode     = "000";
            s.SchoolName     = "default";
            s.SchoolType     = null;
            s.Remark         = "default";
            _schoolvm.Entity = s;
            _schoolvm.DoAdd();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                School s2 = new School();
                s2.SchoolCode    = code;
                s2.SchoolName    = name;
                s2.SchoolType    = schooltype;
                s2.Remark        = remark;
                s2.ID            = s.ID;
                _schoolvm.DC     = context;
                _schoolvm.Entity = s2;
                _schoolvm.DoEdit(true);
            }

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var rv = context.Set <School>().ToList();
                Assert.AreEqual(1, rv.Count());
                Assert.AreEqual(code, rv[0].SchoolCode);
                Assert.AreEqual(name, rv[0].SchoolName);
                Assert.AreEqual(schooltype, rv[0].SchoolType);
                Assert.AreEqual(remark, rv[0].Remark);
                Assert.AreEqual("schooluser", rv[0].UpdateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv[0].UpdateTime.Value).Seconds < 10);
            }
        }
Ejemplo n.º 2
0
        public void Many2ManyDoEdit()
        {
            Major m1 = new Major
            {
                MajorCode = "111",
                MajorName = "major1",
                MajorType = MajorTypeEnum.Optional
            };
            Major m2 = new Major
            {
                MajorCode = "222",
                MajorName = "major2",
                MajorType = MajorTypeEnum.Required
            };
            Major m3 = new Major
            {
                MajorCode = "333",
                MajorName = "major3",
                MajorType = MajorTypeEnum.Required
            };
            Student s1 = new Student
            {
                LoginName = "s1",
                Password  = "******",
                Name      = "student1"
            };

            _majorvm.Entity = m1;
            _majorvm.DoAdd();
            _majorvm.Entity = m2;
            _majorvm.DoAdd();
            _majorvm.Entity = m3;
            _majorvm.DoAdd();

            s1.StudentMajor = new List <StudentMajor>();
            s1.StudentMajor.Add(new StudentMajor {
                MajorId = m1.ID
            });
            s1.StudentMajor.Add(new StudentMajor {
                MajorId = m2.ID
            });
            _studentvm.Entity = s1;
            _studentvm.DoAdd();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                s1.StudentMajor.RemoveAt(0);
                s1.StudentMajor.Add(new StudentMajor {
                    MajorId = m3.ID
                });
                _studentvm.DC     = context;
                _studentvm.Entity = s1;
                _studentvm.DoEdit();
            }

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(3, context.Set <Major>().Count());
                Assert.AreEqual(1, context.Set <Student>().Count());
                Assert.AreEqual(2, context.Set <StudentMajor>().Count());
                var rv1 = context.Set <StudentMajor>().Where(x => x.MajorId == m2.ID).SingleOrDefault();
                var rv2 = context.Set <StudentMajor>().Where(x => x.MajorId == m3.ID).SingleOrDefault();
                Assert.AreEqual(s1.ID, rv1.StudentId);
                Assert.AreEqual(m2.ID, rv1.MajorId);
                Assert.AreEqual(s1.ID, rv2.StudentId);
                Assert.AreEqual(m3.ID, rv2.MajorId);
            }
        }