public void GetPropertyValueTest()
        {
            // Arrange.
            var typeResolver = Mock.Create<ITypeResolver>(Behavior.Loose);
            var role1 = new TestRole { Name = "Test Role 1" };
            var role2 = new TestRole { Name = "Test Role 2", ParentRole = new TestRole { Name = "Parent Role" } };
            var businessUnit = new TestBusinessUnit { Name = "Test BU", ParentBusinessUnit = new TestBusinessUnit { Name = "Parent BU" } };
            var employee = new TestEmployee { FirstName = "aaa", LastName = "AAA", BusinessUnit = businessUnit, Roles = new[] { role1, role2 } };
            var request = new TestRequest1 { Employee = employee };

            var context = new WebMethodResultDataContext(request, typeResolver);

            // Act / Assert.
            Assert.IsNull(context.GetPropertyValue(null));
            Assert.AreEqual("aaa", context.GetPropertyValue("Employee|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employee|LastName"));
            Assert.AreEqual("Test BU", context.GetPropertyValue("Employee|BusinessUnit|Name"));
            Assert.AreEqual("Parent BU", context.GetPropertyValue("Employee|BusinessUnit|ParentBusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employee|Roles|Name"));
            Assert.IsNull(context.GetPropertyValue("Employee|Roles|ParentRole|Name"));
        }
        public void EnumerateItemsTest()
        {
            // Arrange.
            var typeResolver = Mock.Create<ITypeResolver>(Behavior.Loose);
            var role1 = new TestRole { Name = "Role 1" };
            var role2 = new TestRole { Name = "Role 2" };
            var role3 = new TestRole { Name = "Role 3" };
            var businessUnit1 = new TestBusinessUnit { Name = "BU 1" };
            var businessUnit2 = new TestBusinessUnit { Name = "BU 2" };

            var employee1 = new TestEmployee { FirstName = "aaa", LastName = "AAA", BusinessUnit = businessUnit1, Roles = new[] { role1 } };
            var employee2 = new TestEmployee { FirstName = "bbb", LastName = "BBB", BusinessUnit = businessUnit2, Roles = new[] { role2, role3 } };
            var request = new TestRequest2 { Employees = new[] { employee1, employee2 } };

            var context = new WebMethodResultDataContext(request, typeResolver);

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

            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.IsNull(context.GetPropertyValue("Employees|Item[]|Roles|Name"));

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

            var roles = context.EnumerateItems("Employees|Item[]|Roles");
            var rolesEnumerator = roles.GetEnumerator();

            Assert.IsTrue(rolesEnumerator.MoveNext());
            Assert.AreEqual("aaa", context.GetPropertyValue("Employees|Item[]|FirstName"));
            Assert.AreEqual("AAA", context.GetPropertyValue("Employees|Item[]|LastName"));
            Assert.AreEqual("BU 1", context.GetPropertyValue("Employees|Item[]|BusinessUnit|Name"));
            Assert.AreEqual("Role 1", context.GetPropertyValue("Employees|Item[]|Roles|Item[]|Name"));

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

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

            roles = context.EnumerateItems("Employees|Item[]|Roles");
            rolesEnumerator = roles.GetEnumerator();

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

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

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

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