Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fix index out of range exception in Package Sources option panel.
Browse files Browse the repository at this point in the history
Disable move buttons if no package source selected.
  • Loading branch information
mrward committed Jan 6, 2013
1 parent 2d45e51 commit c7e1cec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Expand Up @@ -170,7 +170,7 @@ public void RemovePackageSource()
}

public bool CanRemovePackageSource {
get { return selectedPackageSourceViewModel != null; }
get { return IsPackageSourceSelected(); }
}

void RemoveSelectedPackageSourceViewModel()
Expand All @@ -192,10 +192,17 @@ int GetSelectedPackageSourceViewModelIndex()

public bool CanMovePackageSourceUp {
get {
return HasAtLeastTwoPackageSources() && !IsFirstPackageSourceSelected();
return HasAtLeastTwoPackageSources() &&
IsPackageSourceSelected() &&
!IsFirstPackageSourceSelected();
}
}

bool IsPackageSourceSelected()
{
return selectedPackageSourceViewModel != null;
}

bool IsFirstPackageSourceSelected()
{
return selectedPackageSourceViewModel == packageSourceViewModels[0];
Expand All @@ -210,7 +217,9 @@ public void MovePackageSourceDown()

public bool CanMovePackageSourceDown {
get {
return HasAtLeastTwoPackageSources() && !IsLastPackageSourceSelected();
return HasAtLeastTwoPackageSources() &&
IsPackageSourceSelected() &&
!IsLastPackageSourceSelected();
}
}

Expand Down
Expand Up @@ -445,6 +445,30 @@ public void CanMovePackageSourceUp_OnePackageSourceAndNothingIsSelected_ReturnsF
Assert.IsFalse(result);
}

[Test]
public void CanMovePackageSourceUp_TwoPackageSourcesAndNothingIsSelected_ReturnsFalse()
{
CreateViewModelWithTwoPackageSources();
viewModel.Load();
viewModel.SelectedPackageSourceViewModel = null;

bool result = viewModel.CanMovePackageSourceUp;

Assert.IsFalse(result);
}

[Test]
public void CanMovePackageSourceDown_TwoPackageSourcesAndNothingIsSelected_ReturnsFalse()
{
CreateViewModelWithTwoPackageSources();
viewModel.Load();
viewModel.SelectedPackageSourceViewModel = null;

bool result = viewModel.CanMovePackageSourceDown;

Assert.IsFalse(result);
}

[Test]
public void SelectedPackageSourceViewModel_PropertyChanged_FiresPropertyChangedEvent()
{
Expand Down

0 comments on commit c7e1cec

Please sign in to comment.