Пример #1
0
        public void Commit_Validation01()
        {
            String guid;
            using (IMobeelizerTransaction db = Mobeelizer.GetDatabase().BeginTransaction())
            {
                var departments = db.GetModelSet<Department>();
                Department department = new Department();
                department.Name = "Dep1";
                department.InternalNumber = 333;
                departments.InsertOnSubmit(department);
                db.SubmitChanges();
                guid = department.Guid;
            }
            using (IMobeelizerTransaction db = Mobeelizer.GetDatabase().BeginTransaction())
            {
                var employees = db.GetModelSet<Employee>();
                Employee employee = new Employee();
                employee.Name = "NameNameNameNameNameNameNameNameNameNameName";
                employee.Surname = "Surname";
                employee.Position = "Position";
                employee.Department = guid;
                employees.InsertOnSubmit(employee);
                String exceptionMessage = string.Empty;
                bool thrown = false;
                try
                {
                    db.SubmitChanges();
                }

                catch (ArgumentException e)
                {
                    thrown = true;
                    exceptionMessage = e.Message;
                }

                Assert.IsTrue(thrown);
                Assert.IsTrue(exceptionMessage.Contains("Name"));
            }
        }
Пример #2
0
        public void Querys()
        {
            String justAddEntityGuid = string.Empty;
            using (IMobeelizerTransaction db = Mobeelizer.GetDatabase().BeginTransaction())
            {
                var departmentTable = db.GetModelSet<Department>();
                Department de = new Department();
                de.InternalNumber = 1;
                de.Name = "ddd";
                departmentTable.InsertOnSubmit(de);
                db.SubmitChanges();
                justAddEntityGuid = de.Guid;
            }

            using (IMobeelizerTransaction transaction = Mobeelizer.GetDatabase().BeginTransaction())
            {
                var employees = transaction.GetModelSet<Employee>();
                Employee employee = new Employee() { Department = justAddEntityGuid, Name = "name", Position = "position", Surname = "surname", Salary = 13 };
                employees.InsertOnSubmit(employee);
                transaction.SubmitChanges();
            }

            using (IMobeelizerTransaction transaction = Mobeelizer.GetDatabase().BeginTransaction())
            {
                var employees = transaction.GetModelSet<Employee>();
                var departments = transaction.GetModelSet<Department>();

                var query = from e in employees join d in departments on e.Department equals d.Guid select new { eName = e.Name, dName = d.Name };
                int found = 0;
                foreach (var result in query)
                {
                    ++found;
                }
                Assert.IsTrue(found > 0);
            }
        }