Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Manage button in Manage Packages dialog being disabled after a Nu…

…Get package is installed.
  • Loading branch information...
commit e936e539d6373f6fda06de882ebf11049941eb66 1 parent 051bda8
@mrward mrward authored
View
2  src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageManagementSolution.cs
@@ -28,10 +28,12 @@ public FakePackage AddPackageToActiveProjectLocalRepository(string packageId)
public int GetActiveProjectCallCount;
public FakePackageManagementProject FakeActiveProject = new FakePackageManagementProject();
+ public bool IsGetActiveProjectWithNoParametersCalled;
public virtual IPackageManagementProject GetActiveProject()
{
GetActiveProjectCallCount++;
+ IsGetActiveProjectWithNoParametersCalled = true;
return FakeActiveProject;
}
View
1  src/AddIns/Misc/PackageManagement/Project/Src/IPackageViewModelFactory.cs
@@ -12,6 +12,7 @@ public interface IPackageViewModelFactory
PackageViewModel CreatePackageViewModel(IPackageFromRepository package);
IPackageManagementSolution Solution { get; }
+ PackageManagementSelectedProjects SelectedProjects { get; }
IPackageManagementEvents PackageManagementEvents { get; }
IPackageActionRunner PackageActionRunner { get; }
}
View
19 src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementSelectedProjects.cs
@@ -14,6 +14,8 @@ namespace ICSharpCode.PackageManagement
public class PackageManagementSelectedProjects
{
IPackageManagementSolution solution;
+ bool? singledProjectSelected;
+ IProject singleMSBuildProjectSelected;
public PackageManagementSelectedProjects(IPackageManagementSolution solution)
{
@@ -33,12 +35,11 @@ public IEnumerable<IPackageManagementSelectedProject> GetProjects(IPackageFromRe
public bool HasSingleProjectSelected()
{
- return GetSingleMSBuildProjectSelected() != null;
- }
-
- IProject GetSingleMSBuildProjectSelected()
- {
- return solution.GetActiveMSBuildProject();
+ if (!singledProjectSelected.HasValue) {
+ singleMSBuildProjectSelected = solution.GetActiveMSBuildProject();
+ singledProjectSelected = singleMSBuildProjectSelected != null;
+ }
+ return singledProjectSelected.Value;
}
IEnumerable<IProject> GetOpenProjects()
@@ -48,8 +49,7 @@ IEnumerable<IProject> GetOpenProjects()
IPackageManagementSelectedProject GetSingleProjectSelected(IPackageFromRepository package)
{
- IProject project = GetSingleMSBuildProjectSelected();
- return CreateSelectedProject(project, package);
+ return CreateSelectedProject(singleMSBuildProjectSelected, package);
}
IPackageManagementSelectedProject CreateSelectedProject(IProject msbuildProject, IPackageFromRepository package)
@@ -88,8 +88,7 @@ string GetSelectionName()
string GetSingleProjectSelectedName()
{
- IProject project = GetSingleMSBuildProjectSelected();
- return project.Name;
+ return singleMSBuildProjectSelected.Name;
}
string GetSolutionFileNameWithoutFullPath()
View
24 src/AddIns/Misc/PackageManagement/Project/Src/PackageViewModel.cs
@@ -16,7 +16,6 @@ public class PackageViewModel : ViewModelBase<PackageViewModel>
DelegateCommand removePackageCommand;
DelegateCommand managePackageCommand;
- IPackageManagementSolution solution;
PackageManagementSelectedProjects selectedProjects;
IPackageManagementEvents packageManagementEvents;
IPackageFromRepository package;
@@ -26,19 +25,17 @@ public class PackageViewModel : ViewModelBase<PackageViewModel>
public PackageViewModel(
IPackageFromRepository package,
- IPackageManagementSolution solution,
+ PackageManagementSelectedProjects selectedProjects,
IPackageManagementEvents packageManagementEvents,
IPackageActionRunner actionRunner,
ILogger logger)
{
this.package = package;
- this.solution = solution;
+ this.selectedProjects = selectedProjects;
this.packageManagementEvents = packageManagementEvents;
this.actionRunner = actionRunner;
this.logger = CreateLogger(logger);
- selectedProjects = new PackageManagementSelectedProjects(solution);
-
CreateCommands();
}
@@ -175,11 +172,16 @@ void ClearReportedMessages()
void GetPackageOperations()
{
- IPackageManagementProject project = solution.GetActiveProject();
+ IPackageManagementProject project = GetActiveProject();
project.Logger = logger;
packageOperations = project.GetInstallPackageOperations(package, false);
}
+ IPackageManagementProject GetActiveProject()
+ {
+ return selectedProjects.GetActiveProject(package.Repository);
+ }
+
bool CanInstallPackage()
{
IEnumerable<IPackage> packages = GetPackagesRequiringLicenseAcceptance();
@@ -236,15 +238,13 @@ void TryInstallingPackage()
void InstallPackage()
{
- InstallPackage(package, packageOperations);
+ InstallPackage(packageOperations);
OnPropertyChanged(model => model.IsAdded);
}
- void InstallPackage(
- IPackageFromRepository package,
- IEnumerable<PackageOperation> packageOperations)
+ void InstallPackage(IEnumerable<PackageOperation> packageOperations)
{
- IPackageManagementProject project = solution.GetActiveProject(package.Repository);
+ IPackageManagementProject project = GetActiveProject();
ProcessPackageOperationsAction action = CreateInstallPackageAction(project);
action.Package = package;
action.Operations = packageOperations;
@@ -280,7 +280,7 @@ void LogRemovingPackage()
void TryUninstallingPackage()
{
try {
- IPackageManagementProject project = solution.GetActiveProject(package.Repository);
+ IPackageManagementProject project = GetActiveProject();
UninstallPackageAction action = project.CreateUninstallPackageAction();
action.Package = package;
actionRunner.Run(action);
View
4 src/AddIns/Misc/PackageManagement/Project/Src/PackageViewModelFactory.cs
@@ -23,6 +23,7 @@ public PackageViewModelFactory(IPackageViewModelFactory packageViewModelFactory)
IPackageActionRunner actionRunner)
{
this.Solution = solution;
+ this.SelectedProjects = new PackageManagementSelectedProjects(solution);
this.PackageManagementEvents = packageManagementEvents;
this.PackageActionRunner = actionRunner;
this.Logger = new PackageManagementLogger(packageManagementEvents);
@@ -32,13 +33,14 @@ public virtual PackageViewModel CreatePackageViewModel(IPackageFromRepository pa
{
return new PackageViewModel(
package,
- Solution,
+ SelectedProjects,
PackageManagementEvents,
PackageActionRunner,
Logger);
}
public IPackageManagementSolution Solution { get; private set; }
+ public PackageManagementSelectedProjects SelectedProjects { get; private set; }
public IPackageManagementEvents PackageManagementEvents { get; private set; }
public ILogger Logger { get; private set; }
public IPackageActionRunner PackageActionRunner { get; private set; }
View
4 src/AddIns/Misc/PackageManagement/Project/Src/UpdatedPackageViewModel.cs
@@ -12,11 +12,11 @@ public class UpdatedPackageViewModel : PackageViewModel
{
public UpdatedPackageViewModel(
IPackageFromRepository package,
- IPackageManagementSolution solution,
+ PackageManagementSelectedProjects selectedProjects,
IPackageManagementEvents packageManagementEvents,
IPackageActionRunner actionRunner,
ILogger logger)
- : base(package, solution, packageManagementEvents, actionRunner, logger)
+ : base(package, selectedProjects, packageManagementEvents, actionRunner, logger)
{
}
View
2  src/AddIns/Misc/PackageManagement/Project/Src/UpdatedPackageViewModelFactory.cs
@@ -17,7 +17,7 @@ public override PackageViewModel CreatePackageViewModel(IPackageFromRepository p
{
return new UpdatedPackageViewModel(
package,
- Solution,
+ SelectedProjects,
PackageManagementEvents,
PackageActionRunner,
Logger);
View
9 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakePackageViewModelFactory.cs
@@ -16,11 +16,16 @@ public class FakePackageViewModelFactory : IPackageViewModelFactory
public FakeLogger FakeLogger = new FakeLogger();
public FakePackageActionRunner FakeActionRunner = new FakePackageActionRunner();
+ public FakePackageViewModelFactory()
+ {
+ SelectedProjects = new PackageManagementSelectedProjects(FakeSolution);
+ }
+
public PackageViewModel CreatePackageViewModel(IPackageFromRepository package)
{
return new PackageViewModel(
package,
- FakeSolution,
+ SelectedProjects,
FakePackageManagementEvents,
FakeActionRunner,
FakeLogger);
@@ -30,6 +35,8 @@ public PackageViewModel CreatePackageViewModel(IPackageFromRepository package)
get { return FakeSolution; }
}
+ public PackageManagementSelectedProjects SelectedProjects { get; set; }
+
public IPackageManagementEvents PackageManagementEvents {
get { return FakePackageManagementEvents; }
}
View
8 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestablePackageViewModel.cs
@@ -19,28 +19,28 @@ public class TestablePackageViewModel : PackageViewModel
public TestablePackageViewModel(FakePackageManagementSolution solution)
: this(
new FakePackage("Test"),
- solution,
+ new PackageManagementSelectedProjects(solution),
new FakePackageManagementEvents(),
new FakePackageActionRunner(),
new FakeLogger())
{
+ this.FakeSolution = solution;
}
public TestablePackageViewModel(
FakePackage package,
- FakePackageManagementSolution solution,
+ PackageManagementSelectedProjects selectedProjects,
FakePackageManagementEvents packageManagementEvents,
FakePackageActionRunner actionRunner,
FakeLogger logger)
: base(
package,
- solution,
+ selectedProjects,
packageManagementEvents,
actionRunner,
logger)
{
this.FakePackage = package;
- this.FakeSolution = solution;
this.FakePackageManagementEvents = packageManagementEvents;
this.FakeActionRunner = actionRunner;
this.FakeLogger = logger;
View
10 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestableUpdatedPackageViewModel.cs
@@ -26,28 +26,28 @@ public TestableUpdatedPackageViewModel()
public TestableUpdatedPackageViewModel(FakePackageManagementSolution solution)
: this(
new FakePackage(),
- solution,
+ new PackageManagementSelectedProjects(solution),
new FakePackageManagementEvents(),
new FakePackageActionRunner(),
new FakeLogger())
- {
+ {
+ this.FakeSolution = solution;
}
public TestableUpdatedPackageViewModel(
FakePackage package,
- FakePackageManagementSolution solution,
+ PackageManagementSelectedProjects selectedProjects,
FakePackageManagementEvents packageManagementEvents,
FakePackageActionRunner actionRunner,
FakeLogger logger)
: base(
package,
- solution,
+ selectedProjects,
packageManagementEvents,
actionRunner,
logger)
{
this.FakePackage = package;
- this.FakeSolution = solution;
this.FakeActionRunner = actionRunner;
this.FakeLogger = logger;
}
View
41 src/AddIns/Misc/PackageManagement/Test/Src/PackageManagementSelectedProjectsTests.cs
@@ -76,6 +76,33 @@ public void GetProjects_SolutionHasTwoProjectsAndOneProjectSelectedInProjectsBro
}
[Test]
+ public void GetProjects_SolutionHasTwoProjectsAndOneProjectSelectedInitiallyAndGetProjectsCalledAgainAfterNoProjectsAreSelected_ReturnsProjectSelectedInProjects()
+ {
+ CreateSelectedProjects();
+ List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
+ IProject project = projectsAddedToSolution[1];
+ project.Name = "MyProject";
+ fakeSolution.FakeActiveMSBuildProject = project;
+
+ var fakeProject = fakeSolution.AddFakeProjectToReturnFromGetProject("MyProject");
+
+ var fakePackage = new FakePackage();
+ var projects = new List<IPackageManagementSelectedProject>();
+ projects.AddRange(selectedProjects.GetProjects(fakePackage));
+
+ projects.Clear();
+
+ NoProjectsSelected();
+ projects.AddRange(selectedProjects.GetProjects(fakePackage));
+
+ var expectedProject = new FakeSelectedProject("MyProject");
+ var expectedProjects = new List<IPackageManagementSelectedProject>();
+ expectedProjects.Add(expectedProject);
+
+ SelectedProjectCollectionAssert.AreEqual(expectedProjects, projects);
+ }
+
+ [Test]
public void GetProjects_SolutionHasTwoProjectsAndOneProjectSelectedInProjectsBrowserAndPackageIsInstalledInProject_ReturnsProjectAndIsSelectedIsTrue()
{
CreateSelectedProjects();
@@ -388,6 +415,20 @@ public void HasSingleProjectSelected_SolutionHasTwoProjectsAndNoProjectsSelected
}
[Test]
+ public void HasSingleProjectSelected_NoProjectsInitiallySelectedAndProjectSelectedAfterInitialCall_IsUnchangedAndReturnsFalse()
+ {
+ CreateSelectedProjects();
+ List<IProject> projectsAddedToSolution = AddSolutionWithTwoProjectsToProjectService();
+ NoProjectsSelected();
+
+ bool singleProjectSelected = selectedProjects.HasSingleProjectSelected();
+ fakeSolution.FakeActiveMSBuildProject = fakeSolution.FakeMSBuildProjects[0];
+ singleProjectSelected = selectedProjects.HasSingleProjectSelected();
+
+ Assert.IsFalse(singleProjectSelected);
+ }
+
+ [Test]
public void GetInstalledPackages_PackageInstalledInSolutionAndProjectNotSelected_ReturnsPackageInstalledInSolution()
{
CreateSelectedProjects();
View
11 src/AddIns/Misc/PackageManagement/Test/Src/PackageViewModelTests.cs
@@ -157,6 +157,17 @@ public void AddPackage_PackageAddedSuccessfully_SourcePackageRepositoryUsedToCre
}
[Test]
+ public void AddPackage_PackageAddedSuccessfully_SourcePackageRepositoryWhenGettingPackageOperations()
+ {
+ CreateViewModel();
+ viewModel.AddOneFakeInstallPackageOperationForViewModelPackage();
+
+ viewModel.AddPackage();
+
+ Assert.IsFalse(fakeSolution.IsGetActiveProjectWithNoParametersCalled);
+ }
+
+ [Test]
public void AddPackage_PackageAddedSuccessfully_PackageIsInstalled()
{
CreateViewModel();
Please sign in to comment.
Something went wrong with that request. Please try again.