Beispiel #1
0
        public void RelationsOneToOne()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Employee), typeof(Award));
            Recreate();

            Award.DeleteAll();
            Employee.DeleteAll();

            Employee emp = new Employee();

            emp.FirstName = "john";
            emp.LastName  = "doe";
            emp.Save();

            Assert.AreEqual(1, Employee.FindAll().Length);

            Award award = new Award(emp);

            award.Description = "Invisible employee";
            award.Save();

            Assert.AreEqual(1, Award.FindAll().Length);

            Employee emp2 = Employee.Find(emp.ID);

            Assert.IsNotNull(emp2);
            Assert.IsNotNull(emp2.Award);
            Assert.AreEqual(emp.FirstName, emp2.FirstName);
            Assert.AreEqual(emp.LastName, emp2.LastName);
            Assert.AreEqual(award.Description, emp2.Award.Description);
        }
Beispiel #2
0
        public void RelationsOneToOne()
        {
            using (new SessionScope()) {
                var emp = new Employee {
                    FirstName = "john", LastName = "doe"
                };
                emp.Save();

                Assert.AreEqual(1, Employee.FindAll().Count());

                var award = new Award(emp)
                {
                    Description = "Invisible employee"
                };
                award.Save();

                emp.Award = award;
                emp.Save();

                Assert.AreEqual(1, Award.FindAll().Count());

                var emp2 = Employee.Find(emp.Id);
                Assert.IsNotNull(emp2);
                Assert.IsNotNull(emp2.Award);
                Assert.AreEqual(emp.FirstName, emp2.FirstName);
                Assert.AreEqual(emp.LastName, emp2.LastName);
                Assert.AreEqual(award.Description, emp2.Award.Description);
            }
        }
        public void RelationsOneToOne()
        {
            Employee emp = new Employee();

            emp.FirstName = "john";
            emp.LastName  = "doe";
            emp.Save();

            Assert.AreEqual(1, Employee.FindAll().Length);

            Award award = new Award(emp);

            award.Description = "Invisible employee";
            award.Save();

            Assert.AreEqual(1, Award.FindAll().Length);

            Employee emp2 = Employee.Find(emp.ID);

            Assert.IsNotNull(emp2);
            Assert.IsNotNull(emp2.Award);
            Assert.AreEqual(emp.FirstName, emp2.FirstName);
            Assert.AreEqual(emp.LastName, emp2.LastName);
            Assert.AreEqual(award.Description, emp2.Award.Description);
        }