コード例 #1
0
        /// <summary>
        /// Completes our initialization. This may be called from out overridden Initialize method and sometimes waiting until after the zombie state has
        /// gone from VS.
        /// </summary>
        private void InitializeMenus()
        {
            if (!this.SetupMode)
            {
                IServiceContainer sc = this;
                sc.AddService(typeof(IVsPackage), this, false);

                // Ensure that the IDE enviroment is available.
                EnvDTE.DTE dte = (EnvDTE.DTE) this.GetService(typeof(EnvDTE.DTE));
                if (dte == null)
                {
                    throw new InvalidOperationException(Strings.CouldNotGetVSEnvironment);
                }

                ProjectUtilities.Initialize(this);
                this.Core.Initialize(null, true);
                this.Helper.Initialize();

                // Ensuring that the form is created on the UI thread.
                if (InvisibleForm.Instance == null)
                {
                    throw new InvalidOperationException(Strings.NoInvisbleForm);
                }

                // Set up the menu items.
                this.commandSet = new PackageCommandSet(this);
                this.commandSet.Initialize();
            }
        }
        public void PackageCommandSetConstructorTest()
        {
            var mockActiveDocument = new Mock<Document>();
            var mockDte = new Mock<DTE>();

            mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);

            PackageCommandSet target = new PackageCommandSet(this.mockServiceProvider.Instance);
            CommandSet innerTarget = new PackageCommandSet(this.mockServiceProvider.Instance);
            Assert.IsNotNull(typeof(PackageCommandSet).GetProperty("CommandList", BindingFlags.NonPublic | BindingFlags.Instance)
                .GetValue(innerTarget),
                "CommandList was not created.");
            Assert.IsNotNull(typeof(PackageCommandSet).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance)
                .GetValue(innerTarget),
                "Service provider not stored by the constructor");
        }
コード例 #3
0
        public void PackageCommandSetConstructorTest()
        {
            var mockActiveDocument = new Mock<Document>();
            var mockDte = new Mock<DTE>();

            mockDte.ImplementExpr(dte => dte.ActiveDocument, mockActiveDocument.Instance);

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);

            PackageCommandSet target = new PackageCommandSet(this.mockServiceProvider.Instance);
            CommandSet innerTarget = new PackageCommandSet(this.mockServiceProvider.Instance);

            PrivateObject packageCommandSet = new PrivateObject(target, new PrivateType(typeof(PackageCommandSet)));
            PrivateObject commandSet = new PrivateObject(innerTarget, new PrivateType(typeof(CommandSet)));

            Assert.IsNotNull(packageCommandSet.GetFieldOrProperty("CommandList"), "CommandList was not created.");
            Assert.IsNotNull(commandSet.GetFieldOrProperty("ServiceProvider"), "Service provider not stored by the constructor");
        }
コード例 #4
0
        /// <summary>
        /// Completes our initialization. This may be called from out overridden Initialize method and sometimes waiting until after the zombie state has
        /// gone from VS.
        /// </summary>
        private void InitializeMenus()
        {
            if (!this.SetupMode)
            {
                IServiceContainer sc = this;
                sc.AddService(typeof(IVsPackage), this, false);

                // Ensure that the IDE enviroment is available.
                EnvDTE.DTE dte = (EnvDTE.DTE)this.GetService(typeof(EnvDTE.DTE));
                if (dte == null)
                {
                    throw new InvalidOperationException(Strings.CouldNotGetVSEnvironment);
                }

                ProjectUtilities.Initialize(this);
                this.Core.Initialize(null, true);
                this.Helper.Initialize();

                // Ensuring that the form is created on the UI thread.
                if (InvisibleForm.Instance == null)
                {
                    throw new InvalidOperationException(Strings.NoInvisbleForm);
                }

                // Set up the menu items.
                this.commandSet = new PackageCommandSet(this);
                this.commandSet.Initialize();
            }
        }
コード例 #5
0
 /// <summary>
 /// Adds the menu items for this package.
 /// </summary>
 private void AddMenuItems()
 {
     this.commandSet = new PackageCommandSet(this);
     this.commandSet.Initialize();
 }