public void GetPropertyValueTest()
        {
            // Arrange.
            var employee = new TestEmployee
                               {
                                   FirstName = "aaa",
                                   LastName = "AAA",
                                   BusinessUnit = 11,
                                   BusinessUnitMember =
                                       new TestBusinessUnit
                                           {
                                               Name = "Test BU",
                                               ParentBusinessUnit = 12,
                                               ParentBusinessUnitMember = new TestBusinessUnit { Name = "Parent BU" }
                                           }
                               };

            var itemsRetrieverFactory = Mock.Create<IProcessFieldItemsRetrieverFactory>(Behavior.Loose);

            var context = new EditableRootDataContext(employee, itemsRetrieverFactory);

            // Act / Assert.
            Assert.IsNull(context.GetPropertyValue(null));
            Assert.IsNull(context.GetPropertyValue("TestProp"));
            Assert.AreEqual("aaa", context.GetPropertyValue("FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("LastName"));
            Assert.AreEqual("Test BU", context.GetPropertyValue("BusinessUnit.Name"));
            Assert.AreEqual("Parent BU", context.GetPropertyValue("BusinessUnit.ParentBusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Roles.Name"));
        }
        public void EnumerateItemsTest()
        {
            // Arrange.
            var editItem = new TestEdit();

            var employee1 = new TestEmployee
                                {
                                    FirstName = "aaa",
                                    LastName = "AAA",
                                    BusinessUnit = 11,
                                    BusinessUnitMember = new TestBusinessUnit { Name = "BU 1" }
                                };
            var employee2 = new TestEmployee
                                {
                                    FirstName = "bbb",
                                    LastName = "BBB",
                                    BusinessUnit = 12,
                                    BusinessUnitMember = new TestBusinessUnit { Name = "BU 2" }
                                };

            var employeesRetriever = new Mock<IProcessFieldItemsRetriever>();
            employeesRetriever.Setup(x => x.ItemType).Returns(typeof(TestEmployee));
            employeesRetriever.Setup(x => x.GetItems(editItem)).Returns(new[] { employee1, employee2 });

            var role1 = new TestRole { Name = "Role 1" };
            var role2 = new TestRole { Name = "Role 2" };
            var role3 = new TestRole { Name = "Role 3" };

            var rolesRetriever = new Mock<IProcessFieldItemsRetriever>();
            rolesRetriever.Setup(x => x.ItemType).Returns(typeof(TestRole));
            rolesRetriever.Setup(x => x.GetItems(employee1)).Returns(new[] { role1 });
            rolesRetriever.Setup(x => x.GetItems(employee2)).Returns(new[] { role2, role3 });

            var retrieverFactory = new Mock<IProcessFieldItemsRetrieverFactory>();
            retrieverFactory.Setup(x => x.CreateItemsRetriever(typeof(TestEdit), "Employees")).Returns(employeesRetriever.Object);
            retrieverFactory.Setup(x => x.CreateItemsRetriever(typeof(TestEmployee), "Roles")).Returns(rolesRetriever.Object);

            var context = new EditableRootDataContext(editItem, retrieverFactory.Object);

            // Act / Assert.
            var employees = context.EnumerateItems("Employees");
            var employeeEnumerator = employees.GetEnumerator();

            Assert.IsNull(context.GetPropertyValue("Employees.FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees.LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            var roles = context.EnumerateItems("Employees.Roles");
            var rolesEnumerator = roles.GetEnumerator();
            
            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 1", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(employeeEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            roles = context.EnumerateItems("Employees.Roles");
            rolesEnumerator = roles.GetEnumerator();

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 2", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.AreEqual("Role 3", context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(rolesEnumerator.MoveNext());
            Assert.AreEqual("bbb", context.GetPropertyValue("Employees.FirstName"));
            Assert.AreEqual("BBB", context.GetPropertyValue("Employees.LastName"));
            Assert.AreEqual("BU 2", context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));

            Assert.IsFalse(employeeEnumerator.MoveNext());
            Assert.IsNull(context.GetPropertyValue("Employees.FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees.LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees.BusinessUnit.Name"));
            Assert.IsNull(context.GetPropertyValue("Employees.Roles.Name"));
        }