Beispiel #1
0
        public void SingleTablePersistDelete()
        {
            Student s = new Student();

            s.LoginName       = "a";
            s.Password        = "******";
            s.Name            = "ab";
            _studentvm.Entity = s;
            _studentvm.DoAdd();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(1, context.Set <Student>().Count());
                _studentvm.DC     = context;
                _studentvm.Entity = new Student {
                    ID = s.ID
                };
                _studentvm.DoDelete();
            }

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(1, context.Set <Student>().Count());
                var rv = context.Set <Student>().ToList()[0];
                Assert.AreEqual("studentuser", rv.UpdateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv.UpdateTime.Value).Seconds < 10);
            }
        }
Beispiel #2
0
        public void Many2ManyDoAdd()
        {
            Major m1 = new Major
            {
                MajorCode = "111",
                MajorName = "major1",
                MajorType = MajorTypeEnum.Optional
            };
            Major m2 = new Major
            {
                MajorCode = "222",
                MajorName = "major2",
                MajorType = MajorTypeEnum.Required
            };
            Student s1 = new Student
            {
                LoginName = "s1",
                Password  = "******",
                Name      = "student1"
            };
            Student s2 = new Student
            {
                LoginName = "s2",
                Password  = "******",
                Name      = "student2"
            };

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

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

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(2, context.Set <Major>().Count());
                Assert.AreEqual(2, context.Set <Student>().Count());
                Assert.AreEqual(2, context.Set <StudentMajor>().Count());
                var rv = context.Set <StudentMajor>().ToList();
                Assert.AreEqual(s1.ID, rv[0].StudentId);
                Assert.AreEqual(m1.ID, rv[0].MajorId);
                Assert.AreEqual(s2.ID, rv[1].StudentId);
                Assert.AreEqual(m2.ID, rv[1].MajorId);
            }
        }
Beispiel #3
0
        public void SingleTableDoAdd(string code, string name, SchoolTypeEnum schooltype, string remark)
        {
            School s = new School();

            s.SchoolCode     = code;
            s.SchoolName     = name;
            s.SchoolType     = schooltype;
            s.Remark         = remark;
            _schoolvm.Entity = s;
            _schoolvm.DoAdd();

            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].CreateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv[0].CreateTime.Value).Seconds < 10);
            }
            Assert.IsTrue(_schoolvm.MSD.Count == 0);
        }