예제 #1
0
        public void SelectingNonTypeNodeWhenTypeIsSelected_DoesChangeTextAndKeepsSelectedType()
        {
            var groups =
                new[] {
                new AssemblyGroup(
                    "test",
                    new[] {
                    typeof(TestAssembly1.Namespace1.Class1).Assembly,
                    typeof(TestAssembly2.Namespace1.Class1).Assembly
                })
            };

            var model = new TypeBrowserViewModel(null);

            model.UpdateAssemblyGroups(groups);

            model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = true;

            var modifiedProperties = new List <string>();

            model.PropertyChanged += (s, a) =>
            {
                modifiedProperties.Add(a.PropertyName);
            };

            // simulate selection change
            model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = false;
            model.AssemblyGroups[0].Assemblies[0].Namespaces[1].IsSelected          = true;

            Assert.AreEqual(0, modifiedProperties.Count);
            Assert.IsNotNull(model.ConcreteType);
            Assert.IsFalse(model.HasGenericParameters);
            Assert.AreEqual("TestAssembly1.Namespace1.Class1", model.TypeName);
        }
예제 #2
0
 public SelectInBrowserMenuItem(IShell shell, TypeBrowserViewModel browser, TypeServiceViewModel service)
 {
     this.shell       = shell;
     this.browser     = browser;
     this.service     = service;
     this.DisplayName = Resources.MenuItem_SelectInTypeBrowser;
 }
예제 #3
0
        public void SelectingNonGenericTypeNode_UpdatesTextToFullTypeName()
        {
            var groups =
                new[] {
                new AssemblyGroup(
                    "test",
                    new[] {
                    typeof(TestAssembly1.Namespace1.Class1).Assembly,
                    typeof(TestAssembly2.Namespace1.Class1).Assembly
                })
            };

            var model = new TypeBrowserViewModel(null);

            model.UpdateAssemblyGroups(groups);

            var modifiedProperties = new List <string>();

            model.PropertyChanged += (s, a) =>
            {
                modifiedProperties.Add(a.PropertyName);
            };

            model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = true;

            CollectionAssert.AreEqual(new[] { "HasGenericParameters", "ConcreteType", "TypeName" }, modifiedProperties);
            Assert.IsNotNull(model.ConcreteType);
            Assert.IsFalse(model.HasGenericParameters);
            Assert.AreEqual("TestAssembly1.Namespace1.Class1", model.TypeName);
        }
        /// <summary>
        /// Retrieves and returns the selected type from the user.
        /// </summary>
        /// <param name="selectedType">The type to select in the type selection dialog.</param>
        /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param>
        /// <param name="selectorIncludes">Indicates the types that can be browsed.</param>
        /// <param name="configurationType">The base type from which a type specified by the
        /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/>
        /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary.
        /// </param>
        /// <returns>
        /// The selected <see cref="Type"/> or <see langword="null"/> if not type is selected.
        /// </returns>
        protected virtual Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType)
        {
            var viewModel = new TypeBrowserViewModel(new TypeBuildNodeConstraint(baseType, configurationType, selectorIncludes), this);
            var selector  = new TypeBrowser(viewModel, this.discoveryService);

            Nullable <bool> result = false;

            if (this.UIService != null)
            {
                result = UIService.ShowDialog(selector);
            }
            else
            {
                result = selector.ShowDialog();
            }

            if (result.HasValue && result.Value)
            {
                return(selector.SelectedType);
            }
            return(null);
        }
예제 #5
0
            public bool? ShowDialog( IntPtr owner )
            {
                // create view model based on picker properties, then
                // create and show the view
                var model = new TypeBrowserViewModel()
                {
                    NameConvention = NameConvention,
                    FilterByConvention = !string.IsNullOrEmpty( NameConvention ),
                    LocalAssembly = localAssembly
                };

                model.RestrictedBaseTypeNames.AddRange( RestrictedBaseTypeNames ?? Enumerable.Empty<string>() );
                model.LocalAssemblyReferences.AddRange( localAssemblyReferences );

                using ( var view = new TypeBrowserDialog( model ) )
                {
                    var helper = new WindowInteropHelper( view )
                    {
                        Owner = owner
                    };

                    // change title from default value only if an alternate title is provided
                    if ( !string.IsNullOrEmpty( Title ) )
                        model.Title = Title;

                    var result = view.ShowDialog();

                    // if a type is selected, set it. wrap the type so that it is
                    // serialized across appdomain boundaries
                    if ( ( result ?? false ) )
                        SelectedType = new SimpleType( model.SelectedType );

                    helper.Owner = IntPtr.Zero;

                    return result;
                }
            }
예제 #6
0
        public void UpdatingTheTypeNameToASingleMatch_PerformsSearchAndSetsSelectionButDoesNotChangeTypeName()
        {
            var groups =
                new[] {
                new AssemblyGroup(
                    "test",
                    new[] {
                    typeof(TestAssembly1.Namespace1.Class1).Assembly,
                    typeof(TestAssembly2.Namespace1.Class1).Assembly
                })
            };

            var model = new TypeBrowserViewModel(null);

            model.UpdateAssemblyGroups(groups);

            var modifiedProperties = new List <string>();

            model.PropertyChanged += (s, a) =>
            {
                modifiedProperties.Add(a.PropertyName);
            };

            var frame = new DispatcherFrame();

            model.AssemblyGroups[0].Assemblies[0].Namespaces[0].PropertyChanged += (s, a) =>
            {
                frame.Continue = false;
            };

            model.TypeName = "NamespaceClass";
            Dispatcher.PushFrame(frame);

            Assert.IsNotNull(model.ConcreteType);
            Assert.AreEqual("NamespaceClass", model.TypeName);
            TreeAssert.IsMatch(
                new
            {
                DisplayName = "test",
                Assemblies  = new object[]
                {
                    new
                    {
                        DisplayName = "TestAssembly1",
                        Visibility  = Visibility.Collapsed, IsExpanded = false,
                        Namespaces  = new object []
                        {
                            new
                            {
                                DisplayName = "TestAssembly1.Namespace1",
                                Visibility  = Visibility.Collapsed, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly1.Namespace1.Class1",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "Class2",
                                        FullName    = "TestAssembly1.Namespace1.Class2",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "InternalClass1",
                                        FullName    = "TestAssembly1.Namespace1.InternalClass1",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    },
                                }
                            },
                            new
                            {
                                DisplayName = "TestAssembly1.Namespace2",
                                Visibility  = Visibility.Collapsed, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "AnotherInternalClass",
                                        FullName    = "TestAssembly1.Namespace2.AnotherInternalClass",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    }
                                }
                            }
                        }
                    },
                    new
                    {
                        DisplayName = "TestAssembly2",
                        Visibility  = Visibility.Visible, IsExpanded = true,
                        Namespaces  = new object []
                        {
                            new
                            {
                                DisplayName = "TestAssembly2",
                                Visibility  = Visibility.Visible, IsExpanded = true,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly2.Class1",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "NamespaceClass",
                                        FullName    = "TestAssembly2.NamespaceClass",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    }
                                }
                            },
                            new
                            {
                                DisplayName = "TestAssembly2.Namespace1",
                                Visibility  = Visibility.Collapsed, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly2.Namespace1.Class1",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "Class12",
                                        FullName    = "TestAssembly2.Namespace1.Class12",
                                        Visibility  = Visibility.Collapsed, IsExpanded = false
                                    }
                                }
                            }
                        }
                    }
                }
            },
                model.AssemblyGroups[0]);
        }
예제 #7
0
        public void ViewModelIsInitialized()
        {
            var groups =
                new[] {
                new AssemblyGroup(
                    "test",
                    new[] {
                    typeof(TestAssembly1.Namespace1.Class1).Assembly,
                    typeof(TestAssembly2.Namespace1.Class1).Assembly
                })
            };

            var model = new TypeBrowserViewModel(null);

            model.UpdateAssemblyGroups(groups);

            Assert.IsNull(model.TypeName);
            Assert.IsNull(model.ConcreteType);
            Assert.IsFalse(model.HasGenericParameters);
            Assert.AreEqual(0, model.GenericTypeParameters.Count);
            TreeAssert.IsMatch(
                new
            {
                DisplayName = "test",
                Assemblies  = new object[]
                {
                    new
                    {
                        DisplayName = "TestAssembly1",
                        Visibility  = Visibility.Visible, IsExpanded = false,
                        Namespaces  = new object []
                        {
                            new
                            {
                                DisplayName = "TestAssembly1.Namespace1",
                                Visibility  = Visibility.Visible, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly1.Namespace1.Class1",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "Class2",
                                        FullName    = "TestAssembly1.Namespace1.Class2",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "InternalClass1",
                                        FullName    = "TestAssembly1.Namespace1.InternalClass1",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    },
                                }
                            },
                            new
                            {
                                DisplayName = "TestAssembly1.Namespace2",
                                Visibility  = Visibility.Visible, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "AnotherInternalClass",
                                        FullName    = "TestAssembly1.Namespace2.AnotherInternalClass",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    }
                                }
                            }
                        }
                    },
                    new
                    {
                        DisplayName = "TestAssembly2",
                        Visibility  = Visibility.Visible, IsExpanded = false,
                        Namespaces  = new object []
                        {
                            new
                            {
                                DisplayName = "TestAssembly2",
                                Visibility  = Visibility.Visible, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly2.Class1",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "NamespaceClass",
                                        FullName    = "TestAssembly2.NamespaceClass",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    }
                                }
                            },
                            new
                            {
                                DisplayName = "TestAssembly2.Namespace1",
                                Visibility  = Visibility.Visible, IsExpanded = false,
                                Types       = new object[]
                                {
                                    new
                                    {
                                        DisplayName = "Class1",
                                        FullName    = "TestAssembly2.Namespace1.Class1",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    },
                                    new
                                    {
                                        DisplayName = "Class12",
                                        FullName    = "TestAssembly2.Namespace1.Class12",
                                        Visibility  = Visibility.Visible, IsExpanded = false
                                    }
                                }
                            }
                        }
                    }
                }
            },
                model.AssemblyGroups[0]);
        }