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

            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))
            {
                SchoolWithOtherID s2 = new SchoolWithOtherID();
                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 <SchoolWithOtherID>().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);
            }
        }
Esempio n. 2
0
        public void SingleTableDelete()
        {
            SchoolWithOtherID s = new SchoolWithOtherID();

            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))
            {
                Assert.AreEqual(1, context.Set <SchoolWithOtherID>().Count());
                _schoolvm.DC     = context;
                _schoolvm.Entity = new SchoolWithOtherID {
                    ID = s.ID
                };
                _schoolvm.DoDelete();
            }

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(0, context.Set <SchoolWithOtherID>().Count());
            }
        }
Esempio n. 3
0
        public void One2ManyDoEditFields()
        {
            One2ManyDoAdd();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var id              = context.Set <SchoolWithOtherID>().Select(x => x.ID).First();
                var mid             = context.Set <MajorWithOtherID>().Select(x => x.ID).First();
                SchoolWithOtherID s = new SchoolWithOtherID {
                    ID = id
                };
                s.Majors = new List <MajorWithOtherID>();
                s.Majors.Add(new MajorWithOtherID
                {
                    ID        = "id3",
                    MajorCode = "333",
                    MajorName = "major3",
                    MajorType = MajorTypeEnum.Optional
                });
                s.Majors.Add(new MajorWithOtherID {
                    ID = mid, MajorCode = "111update"
                });
                _schoolvm.Entity = s;
                _schoolvm.DC     = context;
                _schoolvm.FC     = new Dictionary <string, object>();
                _schoolvm.FC.Add("Entity.Majors[0].MajorCode", null);
                _schoolvm.DoEdit();
            }

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var id = context.Set <SchoolWithOtherID>().Select(x => x.ID).First();
                Assert.AreEqual(1, context.Set <SchoolWithOtherID>().Count());
                Assert.AreEqual(2, context.Set <MajorWithOtherID>().Where(x => x.SchoolId == id).Count());
                var rv1 = context.Set <MajorWithOtherID>().Where(x => x.MajorCode == "111update").SingleOrDefault();
                Assert.AreEqual("111update", rv1.MajorCode);
                Assert.AreEqual("major1", rv1.MajorName);
                Assert.AreEqual(MajorTypeEnum.Optional, rv1.MajorType);
                var rv2 = context.Set <MajorWithOtherID>().Where(x => x.MajorCode == "333").SingleOrDefault();
                Assert.AreEqual("333", rv2.MajorCode);
                Assert.AreEqual("major3", rv2.MajorName);
                Assert.AreEqual(MajorTypeEnum.Optional, rv2.MajorType);

                Assert.AreEqual("schooluser", rv1.UpdateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv1.UpdateTime.Value).Seconds < 10);
                Assert.AreEqual("schooluser", rv2.CreateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv2.CreateTime.Value).Seconds < 10);
            }
        }
Esempio n. 4
0
        public void One2ManyDoAdd()
        {
            SchoolWithOtherID s = new SchoolWithOtherID();

            s.SchoolCode = "000";
            s.SchoolName = "school";
            s.SchoolType = SchoolTypeEnum.PRI;
            s.Majors     = new List <MajorWithOtherID>();
            s.Majors.Add(new MajorWithOtherID
            {
                ID        = "id1",
                MajorCode = "111",
                MajorName = "major1",
                MajorType = MajorTypeEnum.Optional
            });
            s.Majors.Add(new MajorWithOtherID
            {
                ID        = "id2",
                MajorCode = "222",
                MajorName = "major2",
                MajorType = MajorTypeEnum.Required
            });
            _schoolvm.Entity = s;
            _schoolvm.DoAdd();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(1, context.Set <SchoolWithOtherID>().Count());
                Assert.AreEqual(2, context.Set <MajorWithOtherID>().Count());
                var rv = context.Set <MajorWithOtherID>().ToList();
                Assert.AreEqual("id1", rv[0].ID);
                Assert.AreEqual("111", rv[0].MajorCode);
                Assert.AreEqual("major1", rv[0].MajorName);
                Assert.AreEqual(MajorTypeEnum.Optional, rv[0].MajorType);
                Assert.AreEqual("id2", rv[1].ID);
                Assert.AreEqual("222", rv[1].MajorCode);
                Assert.AreEqual("major2", rv[1].MajorName);
                Assert.AreEqual(MajorTypeEnum.Required, rv[1].MajorType);

                Assert.AreEqual("schooluser", rv[0].CreateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv[0].CreateTime.Value).Seconds < 10);
                Assert.AreEqual("schooluser", rv[1].CreateBy);
                Assert.IsTrue(DateTime.Now.Subtract(rv[1].CreateTime.Value).Seconds < 10);
            }
        }
Esempio n. 5
0
        public void SingleTableDoAdd(string code, string name, SchoolTypeEnum schooltype, string remark)
        {
            SchoolWithOtherID s = new SchoolWithOtherID();

            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 <SchoolWithOtherID>().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.IsTrue(_schoolvm.MSD.Count == 0);
        }