Beispiel #1
0
        public virtual void UnregisterPrig(PrigPackageViewModel vm)
        {
            var umwPkg = new MachineWideUninstallation(Resources.NuGetRootPackageVersion);
            umwPkg.Preparing += () => vm.BeginMachineWideProcessProgress(MachineWideProcesses.Uninstalling);
            umwPkg.ProfilerStatusChecking += profLoc => vm.ReportProfilerStatusCheckingProgress(10u, profLoc);
            umwPkg.DefaultSourceUninstalling += pkgName => vm.ReportDefaultSourceProcessingProgress(20u, pkgName, null);
            umwPkg.DefaultSourceUninstalled += stdout => vm.ReportDefaultSourceProcessedProgress(30u, stdout);
            umwPkg.ProfilerUnregistering += profLoc => vm.ReportProfilerProcessingProgress(40u, profLoc);
            umwPkg.ProfilerUnregistered += stdout => vm.ReportProfilerProcessedProgress(50u, stdout);
            umwPkg.EnvironmentVariableUnregistering += name => vm.ReportEnvironmentVariableProcessingProgress(60u, name, null);
            umwPkg.EnvironmentVariableUnregistered += name => vm.ReportEnvironmentVariableProcessedProgress(70u);
            umwPkg.NuGetSourceUnregistering += name => vm.ReportNuGetSourceProcessingProgress(80u, name, null);
            umwPkg.NuGetSourceUnregistered += stdout => vm.ReportNuGetSourceProcessedProgress(90u, stdout);
            umwPkg.Completed +=
                result =>
                {
                    switch (result)
                    {
                        case MachineWideProcessResults.Skipped:
                            vm.ShowSkippedMachineWideProcessMessage(SkippedReasons.AlreadyRegistered);
                            vm.EndSkippedMachineWideProcessProgress(SkippedReasons.AlreadyRegistered);
                            break;
                        case MachineWideProcessResults.Completed:
                            var restarts = vm.ConfirmRestartingVisualStudioToTakeEffect();
                            vm.EndCompletedMachineWideProcessProgress();
                            if (!restarts)
                                return;

                            ProcessMixin.RestartCurrentProcess();
                            break;
                    }
                };

            MachineWideInstaller.Uninstall(umwPkg);
        }
Beispiel #2
0
 void UnregisterEnvironmentVariables(MachineWideUninstallation mwUninstl)
 {
     var name = EnvironmentRepository.GetPackageFolderKey();
     mwUninstl.OnEnvironmentVariableUnregistering(name);
     EnvironmentRepository.RemovePackageFolder();
     mwUninstl.OnEnvironmentVariableUnregistered(name);
 }
Beispiel #3
0
 void UnregisterNuGetSource(MachineWideUninstallation mwUninstl)
 {
     var name = "Prig Source";
     mwUninstl.OnNuGetSourceUnregistering(name);
     var stdout = NuGetExecutor.StartUnsourcing(name);
     mwUninstl.OnNuGetSourceUnregistered(stdout);
 }
Beispiel #4
0
 void UninstallAllSources(MachineWideUninstallation mwUninstl)
 {
     var pkgName = "All";
     mwUninstl.OnDefaultSourceUninstalling(pkgName);
     var stdout = PrigExecutor.StartUninstalling(pkgName);
     mwUninstl.OnDefaultSourceUninstalled(stdout);
 }
Beispiel #5
0
        void UnregisterProfiler(MachineWideUninstallation mwUninstl)
        {
            var profLocs = EnvironmentRepository.GetProfilerLocations();
            if (profLocs == null || profLocs.Length == 0)
                return;

            foreach (var profLoc in EnvironmentRepository.GetProfilerLocations())
            {
                mwUninstl.OnProfilerUnregistering(profLoc);
                var stdout = Regsvr32Executor.StartUninstalling(profLoc.PathOfInstalling);
                mwUninstl.OnProfilerUnregistered(stdout);
            }
        }
        public void Uninstall_should_raise_the_events_for_the_uninstallation_steps_if_completed()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            var mocks = new MockRepository(MockBehavior.Strict);
            var order = new MockOrder();
            mwUninstl.Completed += mocks.InOrder<Action<MachineWideProcessResults>>(order, m => m.Setup(_ => _(MachineWideProcessResults.Completed))).Object;

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            mocks.VerifyAll();
        }
Beispiel #7
0
        public void Uninstall(MachineWideUninstallation mwUninstl)
        {
            if (mwUninstl == null)
                throw new ArgumentNullException("mwUninstl");

            mwUninstl.OnPreparing();

            if (!HasBeenInstalled(mwUninstl.Prerequisite))
            {
                mwUninstl.OnCompleted(MachineWideProcessResults.Skipped);
                return;
            }

            UninstallAllSources(mwUninstl);
            UnregisterProfiler(mwUninstl);
            UnregisterEnvironmentVariables(mwUninstl);
            UnregisterNuGetSource(mwUninstl);
            EnvironmentRepository.UnregisterToolsPath();
            EnvironmentRepository.UnregisterPackageFolder();

            mwUninstl.OnCompleted(MachineWideProcessResults.Completed);
        }
        public void Uninstall_should_unregister_package_folder()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            {
                var m = fixture.Freeze<Mock<IEnvironmentRepository>>();
                m.Setup(_ => _.UnregisterPackageFolder()).Verifiable();
            }

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            fixture.Freeze<Mock<IEnvironmentRepository>>().Verify();
        }
        public void Uninstall_should_call_uninstallation_steps_by_a_fixed_sequence()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            var mocks = new MockRepository(MockBehavior.Strict);
            var order = new MockOrder();
            mwUninstl.Preparing += mocks.InOrder<Action>(order, m => m.Setup(_ => _())).Object;
            mwUninstl.ProfilerStatusChecking += mocks.InOrder<Action<ProfilerLocation>>(order, m => m.Setup(_ => _(It.IsAny<ProfilerLocation>()))).Object;
            mwUninstl.DefaultSourceUninstalling += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.DefaultSourceUninstalled += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.ProfilerUnregistering += mocks.InOrder<Action<ProfilerLocation>>(order, m => m.Setup(_ => _(It.IsAny<ProfilerLocation>()))).Object;
            mwUninstl.ProfilerUnregistered += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.EnvironmentVariableUnregistering += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.EnvironmentVariableUnregistered += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.NuGetSourceUnregistering += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.NuGetSourceUnregistered += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(It.IsAny<string>()))).Object;
            mwUninstl.Completed += mocks.InOrder<Action<MachineWideProcessResults>>(order, m => m.Setup(_ => _(It.IsAny<MachineWideProcessResults>()))).Object;

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            mocks.VerifyAll();
        }
        public void Uninstall_should_unregister_NuGet_source()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            {
                var name = @"Prig Source";
                var m = fixture.Freeze<Mock<INuGetExecutor>>();
                m.Setup(_ => _.StartUnsourcing(name)).Returns(fixture.Create<string>());
            }

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            fixture.Freeze<Mock<INuGetExecutor>>().VerifyAll();
        }
        public void Uninstall_should_raise_the_event_to_unregister_NuGet_source_before_and_after()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            var stdout = fixture.Create<string>();
            {
                var m = fixture.Freeze<Mock<INuGetExecutor>>();
                m.Setup(_ => _.StartUnsourcing(It.IsAny<string>())).Returns(stdout);
            }
            var mocks = new MockRepository(MockBehavior.Strict);
            var order = new MockOrder();
            mwUninstl.NuGetSourceUnregistering += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _("Prig Source"))).Object;
            mwUninstl.NuGetSourceUnregistered += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(stdout))).Object;

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            mocks.VerifyAll();
        }
        public void Uninstall_should_raise_the_event_to_unregister_environment_variables_before_and_after()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            var variableName = "URASANDESU_PRIG_PACKAGE_FOLDER";
            {
                var m = fixture.Freeze<Mock<IEnvironmentRepository>>();
                m.Setup(_ => _.GetPackageFolderKey()).Returns(variableName);
            }
            var mocks = new MockRepository(MockBehavior.Strict);
            var order = new MockOrder();
            mwUninstl.EnvironmentVariableUnregistering += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(variableName))).Object;
            mwUninstl.EnvironmentVariableUnregistered += mocks.InOrder<Action<string>>(order, m => m.Setup(_ => _(variableName))).Object;

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            mocks.VerifyAll();
        }
        public void Uninstall_should_raise_the_event_to_unregister_profiler_before_and_after()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            var profLocs =
                new[] 
                { 
                    new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()), 
                    new ProfilerLocation(RegistryView.Registry64, fixture.Create<string>()) 
                };
            fixture.FreezeInstalledEnvironment(profLocs);
            var stdouts = fixture.CreateMany<string>(2).ToArray();
            {
                var m = fixture.Freeze<Mock<IRegsvr32Executor>>();
                m.Setup(_ => _.StartUninstalling(profLocs[0].PathOfInstalling)).Returns(stdouts[0]);
                m.Setup(_ => _.StartUninstalling(profLocs[1].PathOfInstalling)).Returns(stdouts[1]);
            }
            var mocks = new MockRepository(MockBehavior.Strict);
            var order1 = new MockOrder();
            var order2 = new MockOrder();
            mwUninstl.ProfilerUnregistering += 
                mocks.Create<Action<ProfilerLocation>>().
                      InOrder(order1, m => m.Setup(_ => _(profLocs[0]))).
                      InOrder(order2, m => m.Setup(_ => _(profLocs[1]))).Object;
            mwUninstl.ProfilerUnregistered += 
                mocks.Create<Action<string>>().
                      InOrder(order1, m => m.Setup(_ => _(stdouts[0]))).
                      InOrder(order2, m => m.Setup(_ => _(stdouts[1]))).Object;

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            mocks.VerifyAll();
        }
        public void Uninstall_should_unregister_profiler()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            var profLocs =
                new[] 
                { 
                    new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()), 
                    new ProfilerLocation(RegistryView.Registry64, fixture.Create<string>()) 
                };
            fixture.FreezeInstalledEnvironment(profLocs);
            {
                var m = fixture.Freeze<Mock<IRegsvr32Executor>>();
                m.Setup(_ => _.StartUninstalling(profLocs[0].PathOfInstalling)).ReturnsUsingFixture(fixture);
                m.Setup(_ => _.StartUninstalling(profLocs[1].PathOfInstalling)).ReturnsUsingFixture(fixture);
            }

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            fixture.Freeze<Mock<IRegsvr32Executor>>().VerifyAll();
        }
        public void Uninstall_should_uninstall_all_sources()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeInstalledEnvironment();
            {
                var m = fixture.Freeze<Mock<IPrigExecutor>>();
                m.Setup(_ => _.StartUninstalling("All")).ReturnsUsingFixture(fixture);
            }

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.Uninstall(mwUninstl);


            // Assert
            fixture.Freeze<Mock<IPrigExecutor>>().VerifyAll();
        }
        public void Uninstall_should_skip_uninstallation_if_it_has_been_already_uninstalled()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var mwUninstl = new MachineWideUninstallation("2.0.0");
            fixture.FreezeUninstalledEnvironment();
            fixture.Inject(new Mock<INuGetExecutor>(MockBehavior.Strict));
            fixture.Inject(new Mock<IRegsvr32Executor>(MockBehavior.Strict));
            fixture.Inject(new Mock<IPrigExecutor>(MockBehavior.Strict));

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act, Assert
            mwInstllr.Uninstall(mwUninstl);
        }