public void Install_should_install_if_a_package_has_not_been_installed_yet() { // Arrange var fixture = new Fixture().Customize(new AutoMoqCustomization()); var proj = fixture.Freeze<Project>(); var pwPkg = new ProjectWidePackage("Prig", "2.0.0", proj); var mocks = new MockRepository(MockBehavior.Strict); { var m = mocks.Create<IVsPackageInstallerServices>(); m.Setup(_ => _.IsPackageInstalledEx(proj, "Prig", "2.0.0")).Returns(false); m.Setup(_ => _.IsPackageInstalled(proj, "Prig")).Returns(false); fixture.Inject(m); } { var m = mocks.Create<IVsPackageUninstaller>(); fixture.Inject(m); } { var m = mocks.Create<IVsPackageInstaller>(); m.Setup(_ => _.InstallPackage(default(string), proj, "Prig", "2.0.0", false)); fixture.Inject(m); } var pwInstllr = fixture.NewProjectWideInstaller(); // Act pwInstllr.Install(pwPkg); // Assert mocks.VerifyAll(); }
public void Install(ProjectWidePackage pwPkg) { if (pwPkg == null) throw new ArgumentNullException("pwPkg"); pwPkg.OnPackagePreparing(); var targetProj = pwPkg.TargetProject; var pkgId = pwPkg.PackageId; var pkgVer = pwPkg.PackageVersion; if (!InstallerServices.IsPackageInstalledEx(targetProj, pkgId, pkgVer)) { if (InstallerServices.IsPackageInstalled(targetProj, pkgId)) Uninstaller.UninstallPackage(targetProj, pkgId, false); InstallPackage(pwPkg, targetProj, pkgId, pkgVer); } }
void InstallPackage(ProjectWidePackage pwPkg, Project proj, string pkgId, string pkgVer) { try { InstallerEvents.PackageInstalling += pwPkg.OnPackageInstalling; InstallerEvents.PackageInstalled += pwPkg.OnPackageInstalled; InstallerEvents.PackageReferenceAdded += pwPkg.OnPackageReferenceAdded; var source = default(string); var ignoreDependencies = false; Installer.InstallPackage(source, proj, pkgId, pkgVer, ignoreDependencies); } finally { InstallerEvents.PackageInstalling -= pwPkg.OnPackageInstalling; InstallerEvents.PackageInstalled -= pwPkg.OnPackageInstalled; InstallerEvents.PackageReferenceAdded -= pwPkg.OnPackageReferenceAdded; } }
public void Install_should_call_installation_steps_by_a_fixed_sequence() { // Arrange var fixture = new Fixture().Customize(new AutoMoqCustomization()); var proj = fixture.Freeze<Project>(); var pwPkg = new ProjectWidePackage("Prig", "2.0.0", proj); var callback = default(Action); var metadataArr = fixture.CreateMany<IVsPackageMetadata>(3).ToArray(); { var m = fixture.Freeze<Mock<IVsPackageInstallerEvents>>(); callback = () => { m.Raise(_ => _.PackageInstalling += null, metadataArr[0]); m.Raise(_ => _.PackageInstalled += null, metadataArr[1]); m.Raise(_ => _.PackageReferenceAdded += null, metadataArr[2]); }; } { var m = fixture.Freeze<Mock<IVsPackageInstaller>>(); m.Setup(_ => _.InstallPackage(It.IsAny<string>(), It.IsAny<Project>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>())).Callback(callback); } var mocks = new MockRepository(MockBehavior.Strict); var order = new MockOrder(); pwPkg.PackageInstalling += mocks.InOrder<VsPackageEventHandler>(order, m => m.Setup(_ => _(metadataArr[0]))).Object; pwPkg.PackageInstalled += mocks.InOrder<VsPackageEventHandler>(order, m => m.Setup(_ => _(metadataArr[1]))).Object; pwPkg.PackageReferenceAdded += mocks.InOrder<VsPackageEventHandler>(order, m => m.Setup(_ => _(metadataArr[2]))).Object; var pwInstllr = fixture.NewProjectWideInstaller(); // Act pwInstllr.Install(pwPkg); // Assert mocks.VerifyAll(); }
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); }