public bool HasBeenInstalled_(MachinePrerequisite machinePreq, IFixture fixture)
        {
            // Arrange
            var mwInstllr = fixture.NewMachineWideInstaller();

            // Act, Assert
            var result = mwInstllr.HasBeenInstalled(machinePreq);
            fixture.Freeze<Mock<IEnvironmentRepository>>().VerifyAll();
            return result;
        }
Example #2
0
        public bool HasBeenInstalled(MachinePrerequisite machinePreq)
        {
            if (machinePreq == null)
                throw new ArgumentNullException("machinePreq");

            var profLocs = EnvironmentRepository.GetProfilerLocations();
            if (profLocs == null || profLocs.Length == 0)
                return false;

            foreach (var profLoc in profLocs)
            {
                using (var classesRootKey = EnvironmentRepository.OpenRegistryBaseKey(RegistryHive.ClassesRoot, profLoc.RegistryView))
                using (var inprocServer32Key = EnvironmentRepository.OpenRegistrySubKey(classesRootKey, ProfilerLocation.InprocServer32Path))
                {
                    machinePreq.OnProfilerStatusChecking(profLoc);
                    if (!IsProfilerInstalled(inprocServer32Key, ProfilerLocation.GetExpectedFileDescription(machinePreq.PackageVersion)))
                        return false;
                }
            }
            return true;
        }
 static TestCaseData should_return_true_if_all_profilers_have_already_been_installed()
 {
     var fixture = new Fixture().Customize(new AutoMoqCustomization());
     var machinePreq = new MachinePrerequisite("2.0.0");
     {
         var profLocs =
             new[] 
             { 
                 new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()), 
                 new ProfilerLocation(RegistryView.Registry64, fixture.Create<string>()) 
             };
         var @params =
             new[] 
             { 
                 new ParameterForHasBeenInstalled() 
                 { 
                     RegistryView = profLocs[0].RegistryView, 
                     ClassesRootKey = RegistryKeyMixin.DummyX86ClassesRootKey, 
                     InProcServer32Key = RegistryKeyMixin.DummyX86InProcServer32Key, 
                     ProfilerPath = @"C:\Users\Akira\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\jvtxkz2r.sld\tools\x86\Urasandesu.Prig.dll", 
                     ProfilerExistence = true, 
                     ProfilerFileDescription = "Prig Profiler 2.0.0 Type Library" 
                 }, 
                 new ParameterForHasBeenInstalled() 
                 { 
                     RegistryView = profLocs[1].RegistryView, 
                     ClassesRootKey = RegistryKeyMixin.DummyX64ClassesRootKey, 
                     InProcServer32Key = RegistryKeyMixin.DummyX64InProcServer32Key, 
                     ProfilerPath = @"C:\Users\Akira\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\jvtxkz2r.sld\tools\x64\Urasandesu.Prig.dll", 
                     ProfilerExistence = true, 
                     ProfilerFileDescription = "Prig Profiler 2.0.0 Type Library" 
                 } 
             };
         fixture.Inject(MockEnvironmentRepository(profLocs, @params));
     }
     return new TestCaseData(machinePreq, fixture).Returns(true).SetName("should_return_true_if_all_profilers_have_already_been_installed");
 }
Example #4
0
        bool DisableTestAdapterCore(PrigPackageViewModel vm)
        {
            vm.BeginProjectWideProcessProgress(ProjectWideProcesses.TestAdapterDisabling);


            var machinePreq = new MachinePrerequisite(Resources.NuGetRootPackageVersion);
            machinePreq.ProfilerStatusChecking += profLoc => vm.ReportProfilerStatusCheckingProgress(25u, profLoc);
            if (!MachineWideInstaller.HasBeenInstalled(machinePreq))
            {
                vm.ShowSkippedProjectWideProcessMessage(SkippedReasons.NotRegisteredYet, null);
                vm.EndSkippedProjectWideProcessProgress(SkippedReasons.NotRegisteredYet, null);
                return false;
            }

            
            var command =
@"
Import-Module ([IO.Path]::Combine($env:URASANDESU_PRIG_PACKAGE_FOLDER, 'tools\Urasandesu.Prig'))
Disable-PrigTestAdapter
";
            var mci = new ManagementCommandInfo(command);
            mci.CommandExecuting += () => vm.ReportProcessingProjectWideProcessProgress(50u, null);
            mci.CommandExecuted += () => vm.EndCompletedProjectWideProcessProgress(null);
            ManagementCommandExecutor.Execute(mci);

            return true;
        }
Example #5
0
        void RemovePrigAssemblyCore(PrigPackageViewModel vm, string deletionalInclude)
        {
            vm.BeginProjectWideProcessProgress(ProjectWideProcesses.PrigAssemblyRemoving);


            var machinePreq = new MachinePrerequisite(Resources.NuGetRootPackageVersion);
            machinePreq.ProfilerStatusChecking += profLoc => vm.ReportProfilerStatusCheckingProgress(13u, profLoc);
            if (!MachineWideInstaller.HasBeenInstalled(machinePreq))
            {
                vm.ShowSkippedProjectWideProcessMessage(SkippedReasons.NotRegisteredYet, deletionalInclude);
                vm.EndSkippedProjectWideProcessProgress(SkippedReasons.NotRegisteredYet, deletionalInclude);
                return;
            }

            
            if (!vm.ConfirmRemovingPrigAssembly(deletionalInclude))
                return;


            var proj = MonitoringSelectionService.GetCurrentProject();


            var pwPkg = new ProjectWidePackage(Resources.NuGetRootPackageId, Resources.NuGetRootPackageVersion, proj);
            pwPkg.PackagePreparing += () => vm.ReportPackagePreparingProgress(25u);
            pwPkg.PackageInstalling += metadata => vm.ReportPackageInstallingProgress(50u, metadata);
            pwPkg.PackageInstalled += metadata => vm.ReportPackageInstalledProgress(50u, metadata);
            pwPkg.PackageReferenceAdded += metadata => vm.ReportPackageReferenceAddedProgress(50u, metadata);
            ProjectWideInstaller.Install(pwPkg);


            var command = string.Format(
@"
Import-Module ([IO.Path]::Combine($env:URASANDESU_PRIG_PACKAGE_FOLDER, 'tools\Urasandesu.Prig'))
Start-PrigSetup -DeletionalInclude {0} -Project $Project
", deletionalInclude);
            var mci = new ManagementCommandInfo(command, proj);
            mci.CommandExecuting += () => vm.ReportProcessingProjectWideProcessProgress(75u, deletionalInclude);
            mci.CommandExecuted +=
                () =>
                {
                    vm.ShowCompletedProjectWideProcessMessage(deletionalInclude);
                    vm.EndCompletedProjectWideProcessProgress(deletionalInclude);
                };
            ManagementCommandExecutor.Execute(mci);
        }
Example #6
0
        public virtual void PrepareUnregisteringPrig(PrigPackageViewModel vm)
        {
            vm.BeginMachineWideProcessProgress(MachineWideProcesses.Uninstalling);

            var machinePreq = new MachinePrerequisite(Resources.NuGetRootPackageVersion);
            machinePreq.ProfilerStatusChecking += profLoc => vm.ReportProfilerStatusCheckingProgress(50u, profLoc);

            if (!MachineWideInstaller.HasBeenInstalled(machinePreq))
            {
                vm.ShowSkippedMachineWideProcessMessage(SkippedReasons.AlreadyRegistered);
                vm.EndSkippedMachineWideProcessProgress(SkippedReasons.AlreadyRegistered);
                return;
            }


            if (!WindowsIdentity.GetCurrent().IsElevated())
            {
                vm.ShowVisualStudioHasNotBeenElevatedYetMessage();
                if (ProcessMixin.RestartCurrentProcessWith(_ => { _.Verb = "runas"; }))
                    return;

                vm.EndSkippedMachineWideProcessProgress(SkippedReasons.CanceledByUser);
            }
            else
            {
                UnregisterPrig(vm);
            }
        }
        public void HasBeenInstalled_should_raise_the_checking_event_even_if_profiler_has_not_registered_yet()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var machinePreq = new MachinePrerequisite("2.0.0");
            var profLocs = new[] { new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()) };
            {
                var m = new Mock<IEnvironmentRepository>(MockBehavior.Strict);
                m.Setup(_ => _.GetProfilerLocations()).Returns(profLocs);
                m.Setup(_ => _.OpenRegistryBaseKey(RegistryHive.ClassesRoot, profLocs[0].RegistryView)).Returns(RegistryKeyMixin.DummyX86ClassesRootKey);
                m.Setup(_ => _.OpenRegistrySubKey(RegistryKeyMixin.DummyX86ClassesRootKey, ProfilerLocation.InprocServer32Path)).Returns(default(RegistryKey));
                fixture.Inject(m);
            }
            {
                var m = new Mock<Action<ProfilerLocation>>(MockBehavior.Strict);
                m.Setup(_ => _(profLocs[0]));
                fixture.Inject(m);
                machinePreq.ProfilerStatusChecking += m.Object;
            }

            var mwInstllr = fixture.NewMachineWideInstaller();


            // Act
            mwInstllr.HasBeenInstalled(machinePreq);


            // Assert
            fixture.Freeze<Mock<Action<ProfilerLocation>>>().VerifyAll();
        }
 static TestCaseData should_return_false_if_there_is_mismatch_between_registered_profilers_x86()
 {
     var fixture = new Fixture().Customize(new AutoMoqCustomization());
     var machinePreq = new MachinePrerequisite("2.0.0");
     {
         var profLocs =
             new[] 
             { 
                 new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()), 
                 new ProfilerLocation(RegistryView.Registry64, fixture.Create<string>()) 
             };
         var DoesNotCall = ParameterForHasBeenInstalled.DoesNotCall;
         var @params =
             new[] 
             { 
                 new ParameterForHasBeenInstalled() 
                 { 
                     RegistryView = profLocs[0].RegistryView, 
                     ClassesRootKey = RegistryKeyMixin.DummyX86ClassesRootKey, 
                     InProcServer32Key = RegistryKeyMixin.DummyX86InProcServer32Key, 
                     ProfilerPath = @"C:\Users\Akira\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\jvtxkz2r.sld\tools\x86\Urasandesu.Prig.dll", 
                     ProfilerExistence = true, 
                     ProfilerFileDescription = "Prig Profiler 1.0.0 Type Library" 
                 }, 
                 new ParameterForHasBeenInstalled() 
                 { 
                     SetupOpenRegistryBaseKey = DoesNotCall, 
                     SetupOpenRegistrySubKey = DoesNotCall, 
                     SetupGetRegistryValue = DoesNotCall, 
                     SetupExistsFile = DoesNotCall, 
                     SetupGetFileDescription = DoesNotCall
                 } 
             };
         fixture.Inject(MockEnvironmentRepository(profLocs, @params));
     }
     return new TestCaseData(machinePreq, fixture).Returns(false).SetName("should_return_false_if_there_is_mismatch_between_registered_profilers_x86");
 }
 static TestCaseData should_return_false_if_profiler_is_not_registered_to_regstry()
 {
     var fixture = new Fixture().Customize(new AutoMoqCustomization());
     var machinePreq = new MachinePrerequisite("2.0.0");
     {
         var profLocs =
             new[] 
             { 
                 new ProfilerLocation(RegistryView.Registry32, fixture.Create<string>()), 
                 new ProfilerLocation(RegistryView.Registry64, fixture.Create<string>()) 
             };
         var DoesNotCall = ParameterForHasBeenInstalled.DoesNotCall;
         var @params =
             new[] 
             { 
                 new ParameterForHasBeenInstalled() 
                 { 
                     RegistryView = profLocs[0].RegistryView, 
                     ClassesRootKey = RegistryKeyMixin.DummyX86ClassesRootKey, 
                     InProcServer32Key = null, 
                     SetupGetRegistryValue = DoesNotCall, 
                     SetupExistsFile = DoesNotCall, 
                     SetupGetFileDescription = DoesNotCall
                 }, 
                 new ParameterForHasBeenInstalled() 
                 { 
                     SetupOpenRegistryBaseKey = DoesNotCall,
                     SetupOpenRegistrySubKey = DoesNotCall,
                     SetupGetRegistryValue = DoesNotCall, 
                     SetupExistsFile = DoesNotCall, 
                     SetupGetFileDescription = DoesNotCall
                 } 
             };
         fixture.Inject(MockEnvironmentRepository(profLocs, @params));
     }
     return new TestCaseData(machinePreq, fixture).Returns(false).SetName("should_return_false_if_profiler_is_not_registered_to_regstry");
 }
Example #10
0
 static TestCaseData should_return_false_if_profiler_locations_are_empty()
 {
     var fixture = new Fixture().Customize(new AutoMoqCustomization());
     var machinePreq = new MachinePrerequisite("2.0.0");
     {
         var profLocs = new ProfilerLocation[0];
         var @params = new ParameterForHasBeenInstalled[0];
         fixture.Inject(MockEnvironmentRepository(profLocs, @params));
     }
     return new TestCaseData(machinePreq, fixture).Returns(false).SetName("should_return_false_if_profiler_locations_are_empty");
 }