Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Prevent the projects selected from changing when the Manage Packages …

…dialog is opened.
  • Loading branch information...
commit 7355907ff11dd88c9e81ab58112844cafeb8b5f6 1 parent 4c5a649
@mrward mrward authored
View
2  src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementSolution.cs
@@ -73,7 +73,7 @@ public IPackageManagementProject GetProject(IPackageRepository sourceRepository,
public Dictionary<string, FakePackageManagementProject> FakeProjectsToReturnFromGetProject
= new Dictionary<string, FakePackageManagementProject>();
- public IPackageManagementProject GetProject(IPackageRepository sourceRepository, IProject project)
+ public virtual IPackageManagementProject GetProject(IPackageRepository sourceRepository, IProject project)
{
RepositoryPassedToGetProject = sourceRepository;
ProjectPassedToGetProject = project;
View
21 src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementSelectedProjects.cs
@@ -14,7 +14,7 @@ namespace ICSharpCode.PackageManagement
public class PackageManagementSelectedProjects
{
IPackageManagementSolution solution;
- bool? singledProjectSelected;
+ bool? singleProjectSelected;
IProject singleMSBuildProjectSelected;
public PackageManagementSelectedProjects(IPackageManagementSolution solution)
@@ -35,11 +35,11 @@ public IEnumerable<IPackageManagementSelectedProject> GetProjects(IPackageFromRe
public bool HasSingleProjectSelected()
{
- if (!singledProjectSelected.HasValue) {
+ if (!singleProjectSelected.HasValue) {
singleMSBuildProjectSelected = solution.GetActiveMSBuildProject();
- singledProjectSelected = singleMSBuildProjectSelected != null;
+ singleProjectSelected = singleMSBuildProjectSelected != null;
}
- return singledProjectSelected.Value;
+ return singleProjectSelected.Value;
}
IEnumerable<IProject> GetOpenProjects()
@@ -101,8 +101,8 @@ string GetSolutionFileNameWithoutFullPath()
/// </summary>
public bool IsPackageInstalled(IPackageFromRepository package)
{
- IPackageManagementProject project = solution.GetActiveProject(package.Repository);
- if (project != null) {
+ if (HasSingleProjectSelected()) {
+ IPackageManagementProject project = GetSingleProjectSelected(package.Repository);
return project.IsPackageInstalled(package);
}
return IsPackageInstalledInSolution(package);
@@ -121,15 +121,18 @@ public IQueryable<IPackage> GetPackagesInstalledInSolution()
public IQueryable<IPackage> GetInstalledPackages(IPackageRepository sourceRepository)
{
if (HasSingleProjectSelected()) {
- IPackageManagementProject project = GetActiveProject(sourceRepository);
+ IPackageManagementProject project = GetSingleProjectSelected(sourceRepository);
return project.GetPackages();
}
return GetPackagesInstalledInSolution();
}
- public IPackageManagementProject GetActiveProject(IPackageRepository repository)
+ public IPackageManagementProject GetSingleProjectSelected(IPackageRepository repository)
{
- return solution.GetActiveProject(repository);
+ if (HasSingleProjectSelected()) {
+ return solution.GetProject(repository, singleMSBuildProjectSelected);
+ }
+ return null;
}
}
}
View
10 src/AddIns/Misc/PackageManagement/Project/Src/PackageViewModel.cs
@@ -172,14 +172,14 @@ void ClearReportedMessages()
void GetPackageOperations()
{
- IPackageManagementProject project = GetActiveProject();
+ IPackageManagementProject project = GetSingleProjectSelected();
project.Logger = logger;
packageOperations = project.GetInstallPackageOperations(package, false);
}
- IPackageManagementProject GetActiveProject()
+ IPackageManagementProject GetSingleProjectSelected()
{
- return selectedProjects.GetActiveProject(package.Repository);
+ return selectedProjects.GetSingleProjectSelected(package.Repository);
}
bool CanInstallPackage()
@@ -244,7 +244,7 @@ void InstallPackage()
void InstallPackage(IEnumerable<PackageOperation> packageOperations)
{
- IPackageManagementProject project = GetActiveProject();
+ IPackageManagementProject project = GetSingleProjectSelected();
ProcessPackageOperationsAction action = CreateInstallPackageAction(project);
action.Package = package;
action.Operations = packageOperations;
@@ -280,7 +280,7 @@ void LogRemovingPackage()
void TryUninstallingPackage()
{
try {
- IPackageManagementProject project = GetActiveProject();
+ IPackageManagementProject project = GetSingleProjectSelected();
UninstallPackageAction action = project.CreateUninstallPackageAction();
action.Package = package;
actionRunner.Run(action);
View
10 ...dIns/Misc/PackageManagement/Test/Src/Helpers/ExceptionThrowingPackageManagementService.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using ICSharpCode.PackageManagement;
using ICSharpCode.PackageManagement.Design;
+using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace PackageManagement.Tests.Helpers
@@ -12,6 +13,7 @@ namespace PackageManagement.Tests.Helpers
public class ExceptionThrowingPackageManagementSolution : FakePackageManagementSolution
{
public Exception ExceptionToThrowWhenGetActiveProjectCalled { get; set; }
+ public Exception ExceptionToThrowWhenGetProjectCalled { get; set; }
public override IPackageManagementProject GetActiveProject()
{
@@ -28,5 +30,13 @@ public override IPackageManagementProject GetActiveProject(IPackageRepository so
}
return base.GetActiveProject(sourceRepository);
}
+
+ public override IPackageManagementProject GetProject(IPackageRepository sourceRepository, IProject project)
+ {
+ if (ExceptionToThrowWhenGetProjectCalled != null) {
+ throw ExceptionToThrowWhenGetProjectCalled;
+ }
+ return base.GetProject(sourceRepository, project);
+ }
}
}
View
5 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageViewModel.cs
@@ -25,6 +25,7 @@ public TestablePackageViewModel(FakePackageManagementSolution solution)
new FakeLogger())
{
this.FakeSolution = solution;
+ solution.FakeActiveMSBuildProject = ProjectHelper.CreateTestProject();
}
public TestablePackageViewModel(
@@ -63,7 +64,7 @@ public PackageOperation AddOneFakeInstallPackageOperationForViewModelPackage()
var operation = new FakePackageOperation(FakePackage, PackageAction.Install);
FakeSolution
- .FakeActiveProject
+ .FakeProjectToReturnFromGetProject
.FakeInstallOperations
.Add(operation);
@@ -74,7 +75,7 @@ public PackageOperation AddOneFakeUninstallPackageOperation()
{
var package = new FakePackage("PackageToUninstall");
var operation = new FakePackageOperation(package, PackageAction.Uninstall);
- FakeSolution.FakeActiveProject.FakeInstallOperations.Add(operation);
+ FakeSolution.FakeProjectToReturnFromGetProject.FakeInstallOperations.Add(operation);
return operation;
}
}
View
1  src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestableUpdatedPackageViewModel.cs
@@ -32,6 +32,7 @@ public TestableUpdatedPackageViewModel(FakePackageManagementSolution solution)
new FakeLogger())
{
this.FakeSolution = solution;
+ solution.FakeActiveMSBuildProject = ProjectHelper.CreateTestProject("MyProject");
}
public TestableUpdatedPackageViewModel(
View
2  src/AddIns/Misc/PackageManagement/Test/Src/ManagePackagesViewModelTests.cs
@@ -169,7 +169,7 @@ public void PackageUpdatesViewModel_OneUpdatedPackageVersion_HasOnePackageViewMo
Id = "Test",
Version = new Version("1.0.0.0")
};
- fakeSolution.AddPackageToActiveProjectLocalRepository(oldPackage);
+ fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Add(oldPackage);
var newPackage = new FakePackage() {
Id = "Test",
View
49 src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementSelectedProjectsTests.cs
@@ -277,7 +277,7 @@ public void IsPackageInstalled_PackageIsInstalledInProjectAndProjectSelected_Ret
fakeSolution.FakeActiveMSBuildProject = projectsAddedToSolution[0];
var package = new FakePackage("Test");
- fakeSolution.FakeActiveProject.FakePackages.Add(package);
+ fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Add(package);
bool installed = selectedProjects.IsPackageInstalled(package);
@@ -307,7 +307,7 @@ public void IsPackageInstalled_PackagePackageIsNotInstalledInProjectAndProjectSe
var package = new FakePackage("Test");
bool installed = selectedProjects.IsPackageInstalled(package);
- IPackageRepository repository = fakeSolution.RepositoryPassedToGetActiveProject;
+ IPackageRepository repository = fakeSolution.RepositoryPassedToGetProject;
IPackageRepository expectedRepository = package.FakePackageRepository;
Assert.AreEqual(expectedRepository, repository);
@@ -362,31 +362,44 @@ public void GetPackagesInstalledInSolution_PackageInstalledInSolutionAndProjectN
}
[Test]
- public void GetActiveProject_ProjectSelected_ReturnsProject()
+ public void GetSingleProjectSelected_ProjectSelected_ReturnsProject()
{
CreateSelectedProjects();
List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
fakeSolution.FakeActiveMSBuildProject = projectsAddedToSolution[0];
var repository = new FakePackageRepository();
- IPackageManagementProject project = selectedProjects.GetActiveProject(repository);
+ IPackageManagementProject project = selectedProjects.GetSingleProjectSelected(repository);
- FakePackageManagementProject expectedProject = fakeSolution.FakeActiveProject;
+ FakePackageManagementProject expectedProject = fakeSolution.FakeProjectToReturnFromGetProject;
Assert.AreEqual(expectedProject, project);
}
[Test]
- public void GetActiveProject_ProjectSelectedAndRepositoryPassed_ReturnsProjectCreatedWithRepository()
+ public void GetSingleProjectSelected_ProjectSelectedAndRepositoryPassed_ReturnsProjectCreatedWithRepository()
{
CreateSelectedProjects();
List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
fakeSolution.FakeActiveMSBuildProject = projectsAddedToSolution[0];
var repository = new FakePackageRepository();
- IPackageManagementProject project = selectedProjects.GetActiveProject(repository);
+ IPackageManagementProject project = selectedProjects.GetSingleProjectSelected(repository);
- Assert.AreEqual(repository, fakeSolution.RepositoryPassedToGetActiveProject);
+ Assert.AreEqual(repository, fakeSolution.RepositoryPassedToGetProject);
+ }
+
+ [Test]
+ public void GetSingleProjectSelected_NoProjectSelectedAndRepositoryPassed_ReturnsProjectCreatedWithRepository()
+ {
+ CreateSelectedProjects();
+ List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
+ fakeSolution.FakeActiveMSBuildProject = projectsAddedToSolution[0];
+
+ var repository = new FakePackageRepository();
+ IPackageManagementProject project = selectedProjects.GetSingleProjectSelected(repository);
+
+ Assert.AreEqual(repository, fakeSolution.RepositoryPassedToGetProject);
}
[Test]
@@ -454,9 +467,12 @@ public void GetInstalledPackages_PackageInstalledInProjectAndProjectIsSelected_R
CreateSelectedProjects();
List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
fakeSolution.FakeActiveMSBuildProject = projectsAddedToSolution[0];
+ fakeSolution.FakeActiveMSBuildProject.Name = "MyProject";
var package = new FakePackage("Test");
- fakeSolution.FakeActiveProject.FakePackages.Add(package);
+ var project = new FakePackageManagementProject("MyProject");
+ project.FakePackages.Add(package);
+ fakeSolution.FakeProjectsToReturnFromGetProject.Add("MyProject", project);
var repository = new FakePackageRepository();
IQueryable<IPackage> packages = selectedProjects.GetInstalledPackages(repository);
@@ -478,9 +494,22 @@ public void GetInstalledPackages_PackageInstalledInProjectAndProjectIsSelected_C
var expectedRepository = new FakePackageRepository();
IQueryable<IPackage> packages = selectedProjects.GetInstalledPackages(expectedRepository);
- IPackageRepository repository = fakeSolution.RepositoryPassedToGetActiveProject;
+ IPackageRepository repository = fakeSolution.RepositoryPassedToGetProject;
Assert.AreEqual(expectedRepository, repository);
}
+
+ [Test]
+ public void GetSingleProjectSelected_NoProjectSelected_ReturnsNull()
+ {
+ CreateSelectedProjects();
+ AddSolutionWithTwoProjectsToProjectService();
+ NoProjectsSelected();
+
+ var repository = new FakePackageRepository();
+ IPackageManagementProject project = selectedProjects.GetSingleProjectSelected(repository);
+
+ Assert.IsNull(project);
+ }
}
}
View
41 src/AddIns/Misc/PackageManagement/Test/Src/PackageViewModelTests.cs
@@ -44,7 +44,7 @@ void CreateViewModelWithExceptionThrowingProject()
{
CreateViewModel();
exceptionThrowingProject = new ExceptionThrowingPackageManagementProject();
- viewModel.FakeSolution.FakeActiveProject = exceptionThrowingProject;
+ viewModel.FakeSolution.FakeProjectToReturnFromGetProject = exceptionThrowingProject;
}
void CreateViewModel(FakePackageManagementSolution solution)
@@ -54,8 +54,8 @@ void CreateViewModel(FakePackageManagementSolution solution)
this.fakeSolution = solution;
fakePackageManagementEvents = viewModel.FakePackageManagementEvents;
fakeLogger = viewModel.FakeLogger;
- fakeInstallPackageAction = solution.FakeActiveProject.FakeInstallPackageAction;
- fakeUninstallPackageAction = solution.FakeActiveProject.FakeUninstallPackageAction;
+ fakeInstallPackageAction = solution.FakeProjectToReturnFromGetProject.FakeInstallPackageAction;
+ fakeUninstallPackageAction = solution.FakeProjectToReturnFromGetProject.FakeUninstallPackageAction;
fakeActionRunner = viewModel.FakeActionRunner;
}
@@ -72,7 +72,7 @@ void CreateViewModelWithTwoProjectsSelected(string projectName1, string projectN
AddProjectToSolution();
fakeSolution.FakeMSBuildProjects[0].Name = projectName1;
fakeSolution.FakeMSBuildProjects[1].Name = projectName2;
- fakeSolution.FakeActiveProject = null;
+ fakeSolution.NoProjectsSelected();
fakeSolution.AddFakeProjectToReturnFromGetProject(projectName1);
fakeSolution.AddFakeProjectToReturnFromGetProject(projectName2);
@@ -153,18 +153,7 @@ public void AddPackage_PackageAddedSuccessfully_SourcePackageRepositoryUsedToCre
viewModel.AddPackage();
- Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetActiveProject);
- }
-
- [Test]
- public void AddPackage_PackageAddedSuccessfully_SourcePackageRepositoryWhenGettingPackageOperations()
- {
- CreateViewModel();
- viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
-
- viewModel.AddPackage();
-
- Assert.IsFalse(fakeSolution.IsGetActiveProjectWithNoParametersCalled);
+ Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetProject);
}
[Test]
@@ -278,7 +267,7 @@ public void HasReportAbuseUrl_PackageHasNoReportAbuseUrl_ReturnsFalse()
public void IsAdded_ProjectHasPackageAdded_ReturnsTrue()
{
CreateViewModel();
- fakeSolution.FakeActiveProject.FakePackages.Add(fakePackage);
+ fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Add(fakePackage);
Assert.IsTrue(viewModel.IsAdded);
}
@@ -287,7 +276,7 @@ public void IsAdded_ProjectHasPackageAdded_ReturnsTrue()
public void IsAdded_ProjectDoesNotHavePackageInstalled_ReturnsFalse()
{
CreateViewModel();
- fakeSolution.FakeActiveProject.FakePackages.Clear();
+ fakeSolution.FakeProjectToReturnFromGetProject.FakePackages.Clear();
Assert.IsFalse(viewModel.IsAdded);
}
@@ -307,7 +296,7 @@ public void RemovePackage_PackageRemovedSuccessfully_RepositoryUsedToCreateProje
CreateViewModel();
viewModel.RemovePackage();
- Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetActiveProject);
+ Assert.AreEqual(fakePackage.Repository, fakeSolution.RepositoryPassedToGetProject);
}
[Test]
@@ -500,7 +489,7 @@ public void AddPackage_CheckLoggerUsed_PackageViewModelLoggerUsedWhenResolvingPa
viewModel.AddPackage();
ILogger expectedLogger = viewModel.OperationLoggerCreated;
- ILogger actualLogger = fakeSolution.FakeActiveProject.Logger;
+ ILogger actualLogger = fakeSolution.FakeProjectToReturnFromGetProject.Logger;
Assert.AreEqual(expectedLogger, actualLogger);
}
@@ -663,7 +652,7 @@ public void AddPackage_ExceptionThrownWhenResolvingPackageOperations_ExceptionRe
viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
var exception = new Exception("Test");
- exceptionThrowingSolution.ExceptionToThrowWhenGetActiveProjectCalled = exception;
+ exceptionThrowingSolution.ExceptionToThrowWhenGetProjectCalled = exception;
viewModel.AddPackage();
Assert.AreEqual(exception, fakePackageManagementEvents.ExceptionPassedToOnPackageOperationError);
@@ -678,7 +667,7 @@ public void AddPackage_PackagesInstalledSuccessfully_ViewModelPackageUsedWhenRes
FakePackage expectedPackage = fakePackage;
IPackage actualPackage = fakeSolution
- .FakeActiveProject
+ .FakeProjectToReturnFromGetProject
.PackagePassedToGetInstallPackageOperations;
Assert.AreEqual(expectedPackage, actualPackage);
@@ -692,7 +681,7 @@ public void AddPackage_PackagesInstalledSuccessfully_PackageDependenciesNotIgnor
viewModel.AddPackage();
bool result = fakeSolution
- .FakeActiveProject
+ .FakeProjectToReturnFromGetProject
.IgnoreDependenciesPassedToGetInstallPackageOperations;
Assert.IsFalse(result);
@@ -715,7 +704,7 @@ public void IsAdded_SolutionSelectedContainingOneProjectAndPackageIsInstalledInS
{
CreateViewModel();
AddProjectToSolution();
- fakeSolution.FakeActiveProject = null;
+ fakeSolution.NoProjectsSelected();
fakeSolution.FakeInstalledPackages.Add(fakePackage);
bool added = viewModel.IsAdded;
@@ -728,7 +717,7 @@ public void IsAdded_SolutionSelectedContainingOneProjectAndPackageIsNotInstalled
{
CreateViewModel();
AddProjectToSolution();
- fakeSolution.FakeActiveProject = null;
+ fakeSolution.NoProjectsSelected();
bool added = viewModel.IsAdded;
@@ -741,7 +730,7 @@ public void IsManaged_SolutionSelectedContainingTwoProjects_ReturnsTrue()
CreateViewModel();
AddProjectToSolution();
AddProjectToSolution();
- fakeSolution.FakeActiveProject = null;
+ fakeSolution.NoProjectsSelected();
bool managed = viewModel.IsManaged;
View
4 src/AddIns/Misc/PackageManagement/Test/Src/UpdatedPackageViewModelTests.cs
@@ -23,7 +23,7 @@ void CreateViewModel()
{
viewModel = new TestableUpdatedPackageViewModel();
fakeSolution = viewModel.FakeSolution;
- fakeProject = fakeSolution.FakeActiveProject;
+ fakeProject = fakeSolution.FakeProjectToReturnFromGetProject;
updatePackageAction = fakeProject.FakeUpdatePackageAction;
fakeActionRunner = viewModel.FakeActionRunner;
}
@@ -34,7 +34,7 @@ public void AddPackage_PackageAddedSuccessfully_ProjectCreatedUsingSourcePackage
CreateViewModel();
viewModel.AddPackage();
- Assert.AreEqual(viewModel.FakePackage.Repository, fakeSolution.RepositoryPassedToGetActiveProject);
+ Assert.AreEqual(viewModel.FakePackage.Repository, fakeSolution.RepositoryPassedToGetProject);
}
[Test]
View
6 src/AddIns/Misc/PackageManagement/Test/Src/UpdatedPackagesViewModelTests.cs
@@ -61,7 +61,7 @@ void CompleteReadPackagesTask()
FakePackage AddPackageToLocalRepository(string version)
{
FakePackage package = FakePackage.CreatePackageWithVersion(version);
- solution.AddPackageToActiveProjectLocalRepository(package);
+ solution.FakeProjectToReturnFromGetProject.FakePackages.Add(package);
return package;
}
@@ -128,10 +128,10 @@ public void ReadPackages_OneNewerPackageVersionAvailable_ProjectNotCreatedByBack
}
[Test]
- public void ReadPackages_GetActiveProjectThrowsException_ErrorMessageFromExceptionNotOverriddenByReadPackagesCall()
+ public void ReadPackages_GetProjectThrowsException_ErrorMessageFromExceptionNotOverriddenByReadPackagesCall()
{
CreateExceptionThrowingSolution();
- exceptionThrowingSolution.ExceptionToThrowWhenGetActiveProjectCalled =
+ exceptionThrowingSolution.ExceptionToThrowWhenGetProjectCalled =
new Exception("Test");
CreateViewModel(exceptionThrowingSolution);
viewModel.ReadPackages();
Please sign in to comment.
Something went wrong with that request. Please try again.