public void Matches_ChildViewModelPlusOptionalStepWithAnyStepsStep_MacthesPropertyOfChildChildViewModel()
        {
            var definition = PathDefinition
                             .Empty
                             .Append((EmployeeVMDescriptor x) => x.SelectedProject)
                             .Append(new OptionalStep(new AnyStepsStep <ProjectVMDescriptor>()));

            var customerVM = new CustomerVM();
            var projectVM  = new ProjectVM();

            projectVM.SetValue(x => x.SelectedCustomer, customerVM);
            var rootVM = new EmployeeVM();

            rootVM.SetValue(x => x.SelectedProject, projectVM);

            var path = Path
                       .Empty
                       .Append(rootVM)
                       .Append(rootVM.GetValue(x => x.SelectedProject))
                       .Append(projectVM.GetValue(x => x.SelectedCustomer))
                       .Append(CustomerVM.ClassDescriptor.Name);

            var match = definition.Matches(path);

            Assert.IsTrue(match.Success);
        }
        public void GetDescendants_DescendantViewModelOverSeveralHierarchies_ReturnsLastViewModel()
        {
            var path = PathDefinition
                       .Empty
                       .Append((EmployeeVMDescriptor x) => x.SelectedProject)
                       .Append((ProjectVMDescriptor x) => x.SelectedCustomer);

            var expectedVM = new CustomerVM();
            var projectVM  = new ProjectVM();

            projectVM.SetValue(x => x.SelectedCustomer, expectedVM);
            var rootVM = new EmployeeVM();

            rootVM.SetValue(x => x.SelectedProject, projectVM);

            var descendantVM = path.GetDescendants(rootVM);

            Assert.AreSame(expectedVM, descendantVM.First());
        }
        public void GetDescendants_DesendantViewModelOverCollection_ReturnsAllViewModels()
        {
            var path = PathDefinition
                       .Empty
                       .Append((EmployeeVMDescriptor x) => x.Projects)
                       .Append((ProjectVMDescriptor x) => x.SelectedCustomer);

            var customer1 = new CustomerVM();
            var customer2 = new CustomerVM();
            var customer3 = new CustomerVM();

            var project1 = new ProjectVM();

            project1.SetValue(x => x.SelectedCustomer, customer1);
            var project2 = new ProjectVM();

            project2.SetValue(x => x.SelectedCustomer, customer2);
            var project3 = new ProjectVM();

            project3.SetValue(x => x.SelectedCustomer, customer3);

            var expectedViewModels = new CustomerVM[] {
                customer1,
                customer2,
                customer3
            };

            var rootVM = new EmployeeVM();

            var projects = rootVM.GetValue(x => x.Projects);

            projects.Add(project1);
            projects.Add(project2);
            projects.Add(project3);

            var descenantViewModels = path.GetDescendants(rootVM);

            CollectionAssert.AreEqual(expectedViewModels, descenantViewModels);
        }
        public void GetDescendants_WhenOnlyLoadedIsTrue_DoesNotLoadDescendants()
        {
            var unloadedProject = new ProjectVM();
            var loadedProject   = new ProjectVM();

            var selectedCustomer = new CustomerVM();
            var customerItem     = new CustomerVM();

            loadedProject.SetValue(x => x.SelectedCustomer, selectedCustomer);
            loadedProject.GetValue(x => x.Customers).Add(customerItem);

            var rootVM = new EmployeeVM();

            var projects = rootVM.GetValue(x => x.Projects);

            projects.Add(unloadedProject);
            projects.Add(loadedProject);

            var path = PathDefinition
                       .Empty
                       .Append((EmployeeVMDescriptor x) => x.Projects)
                       .Append((ProjectVMDescriptor x) => x.SelectedCustomer);

            var descenantViewModels = path.GetLoadedDescendants(rootVM);

            CollectionAssert.AreEquivalent(new[] { selectedCustomer }, descenantViewModels);
            ViewModelAssert.IsNotLoaded(unloadedProject, x => x.SelectedCustomer);

            path = PathDefinition
                   .Empty
                   .Append((EmployeeVMDescriptor x) => x.Projects)
                   .Append((ProjectVMDescriptor x) => x.Customers);

            descenantViewModels = path.GetLoadedDescendants(rootVM);

            CollectionAssert.AreEquivalent(new[] { customerItem }, descenantViewModels);
            ViewModelAssert.IsNotLoaded(unloadedProject, x => x.Customers);
        }