Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
Implement the rest of DropRepoViewModel
Browse files Browse the repository at this point in the history
Still needs tests though
  • Loading branch information
anaisbetts committed May 15, 2012
1 parent 42a0720 commit d54ef91
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
8 changes: 6 additions & 2 deletions RepoRepairTool.Tests/ViewModels/DropRepoViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
using System.Reactive.Linq;
using System.Text;
using GitHub;
using NSubstitute;
using Newtonsoft.Json;
using Ninject;
using Ninject.MockingKernel.NSubstitute;
using ReactiveUI;
using ReactiveUI.Routing;
using ReactiveUI.Xaml;
using RepoRepairTool.ViewModels;
using Should;
Expand All @@ -25,7 +29,7 @@ public void AnalyzeRepoWithThingsThatArentReposShouldFail(string input)
UserError error = null;

using(UserError.OverrideHandlersForTesting(x => { error = x; return RecoveryOptionResult.CancelOperation; })) {
var fixture = new DropRepoViewModel(null);
var fixture = new DropRepoViewModel(null, null);
fixture.AnalyzeRepo.Execute(input);
}

Expand All @@ -37,7 +41,7 @@ public void ScanningOurselvesShouldReturnResults()
{
var repoRootPath = CoreUtility.FindRepositoryRoot(IntegrationTestHelper.GetIntegrationTestRootDirectory());

var fixture = new DropRepoViewModel(null);
var fixture = new DropRepoViewModel(null, null);
fixture.AnalyzeRepo.Execute(repoRootPath);
fixture.AnalyzeRepo.ItemsInflight.Where(x => x == 0).First();

Expand Down
3 changes: 3 additions & 0 deletions RepoRepairTool.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<package id="Ninject" version="3.0.0.15" />
<package id="Ninject.Extensions.Logging" version="3.0.0.7" />
<package id="Ninject.Extensions.Logging.nlog2" version="3.0.0.7" />
<package id="Ninject.MockingKernel" version="3.0.0.5" />
<package id="Ninject.MockingKernel.NSubstitute" version="3.0.0.5" />
<package id="NLog" version="2.0.0.2000" />
<package id="NSubstitute" version="1.3.0.0" />
<package id="reactiveui" version="3.1.2" />
<package id="reactiveui-core" version="3.1.2" />
<package id="reactiveui-testing" version="3.1.2" />
Expand Down
1 change: 1 addition & 0 deletions RepoRepairTool/RepoRepairTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
</ApplicationDefinition>
<Compile Include="ViewModels\AppBootstrapper.cs" />
<Compile Include="ViewModels\DropRepoViewModel.cs" />
<Compile Include="ViewModels\RepairViewModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
22 changes: 22 additions & 0 deletions RepoRepairTool/ViewModels/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows;
using System.Windows.Controls;
using Akavache;
using GitHub.Helpers;
using Ninject;
using Ninject.Extensions.Conventions;
using Ninject.Extensions.Conventions.BindingGenerators;
Expand All @@ -18,10 +19,31 @@ namespace RepoRepairTool.ViewModels
{
public interface IAppState : IReactiveNotifyPropertyChanged
{
string CurrentRepo { get; set; }
Dictionary<string, HeuristicTreeInformation> BranchInformation { get; set; }
HeuristicTreeInformation WorkingDirectoryInformation { get; set; }
}

public class AppBootstrapper : ReactiveObject, IScreen, IAppState
{
string _CurrentRepo;
public string CurrentRepo {
get { return _CurrentRepo; }
set { this.RaiseAndSetIfChanged(x => x.CurrentRepo, value); }
}

Dictionary<string, HeuristicTreeInformation> _BranchInformation;
public Dictionary<string, HeuristicTreeInformation> BranchInformation {
get { return _BranchInformation; }
set { this.RaiseAndSetIfChanged(x => x.BranchInformation, value); }
}

HeuristicTreeInformation _WorkingDirectoryInformation;
public HeuristicTreeInformation WorkingDirectoryInformation {
get { return _WorkingDirectoryInformation; }
set { this.RaiseAndSetIfChanged(x => x.WorkingDirectoryInformation, value); }
}

public IRoutingState Router { get; protected set; }

public AppBootstrapper(IKernel kernel = null, IRoutingState router = null)
Expand Down
14 changes: 13 additions & 1 deletion RepoRepairTool/ViewModels/DropRepoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string UrlPathSegment {

public IScreen HostScreen { get; protected set; }

public DropRepoViewModel(IScreen hostScreen)
public DropRepoViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;

Expand Down Expand Up @@ -86,6 +86,18 @@ public DropRepoViewModel(IScreen hostScreen)

scanResult.Select(x => x != null ? x.Item1 : null).ToProperty(this, x => x.CurrentRepoPath);
scanResult.Select(x => x != null ? x.Item2 : null).ToProperty(this, x => x.RepoAnalysis);

this.WhenAny(x => x.RepoAnalysis, x => x.Value != null ? Visibility.Visible : Visibility.Hidden)
.ToProperty(this, x => x.RepairButtonVisibility);

RepairButton = new ReactiveCommand();
RepairButton.Subscribe(_ => {
appState.BranchInformation = RepoAnalysis.Keys.Where(x => x != "Working Directory").ToDictionary(x => x, x => RepoAnalysis[x]);
appState.WorkingDirectoryInformation = RepoAnalysis["Working Directory"];
appState.CurrentRepo = CurrentRepoPath;
HostScreen.Router.Navigate.Execute(RxApp.GetService<IRepairViewModel>());
});
}

IEnumerable<string> allFilesInDirectory(string rootPath)
Expand Down
9 changes: 9 additions & 0 deletions RepoRepairTool/ViewModels/RepairViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using ReactiveUI.Routing;

namespace RepoRepairTool.ViewModels
{
public interface IRepairViewModel : IRoutableViewModel
{
}
}

0 comments on commit d54ef91

Please sign in to comment.