Skip to content

Commit 9cc5cb7

Browse files
committed
Changes VM Tests. I was unable to check everything because of the mock provider.
1 parent 9857a8e commit 9cc5cb7

File tree

5 files changed

+355
-37
lines changed

5 files changed

+355
-37
lines changed

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections.ObjectModel;
43
using System.Linq;
54
using System.Windows.Input;
@@ -50,8 +49,21 @@ public ISourceControlProvider Provider
5049
public void RefreshView()
5150
{
5251
OnPropertyChanged("CurrentBranch");
53-
OnPropertyChanged("IncludedChanges");
54-
OnPropertyChanged("UntrackedFiles");
52+
53+
IncludedChanges = Provider == null
54+
? new ObservableCollection<IFileStatusEntry>()
55+
: new ObservableCollection<IFileStatusEntry>(
56+
Provider.Status()
57+
.Where(
58+
stat =>
59+
(stat.FileStatus.HasFlag(FileStatus.Modified) ||
60+
stat.FileStatus.HasFlag(FileStatus.Added)) &&
61+
!ExcludedChanges.Select(f => f.FilePath).Contains(stat.FilePath)));
62+
63+
UntrackedFiles = Provider == null
64+
? new ObservableCollection<IFileStatusEntry>()
65+
: new ObservableCollection<IFileStatusEntry>(
66+
Provider.Status().Where(stat => stat.FileStatus.HasFlag(FileStatus.Untracked)));
5567
}
5668

5769
private void Provider_BranchChanged(object sender, EventArgs e)
@@ -66,35 +78,45 @@ public string CurrentBranch
6678

6779
public CommitAction CommitAction { get; set; }
6880

69-
public IEnumerable<IFileStatusEntry> IncludedChanges
81+
private ObservableCollection<IFileStatusEntry> _includedChanges;
82+
public ObservableCollection<IFileStatusEntry> IncludedChanges
7083
{
71-
get
84+
get { return _includedChanges; }
85+
set
7286
{
73-
return Provider == null
74-
? new ObservableCollection<IFileStatusEntry>()
75-
: new ObservableCollection<IFileStatusEntry>(
76-
Provider.Status()
77-
.Where(stat =>
78-
(stat.FileStatus.HasFlag(FileStatus.Modified) ||
79-
stat.FileStatus.HasFlag(FileStatus.Added)) &&
80-
!ExcludedChanges.Select(f => f.FilePath).Contains(stat.FilePath)));
87+
if (_includedChanges != value)
88+
{
89+
_includedChanges = value;
90+
OnPropertyChanged();
91+
}
8192
}
8293
}
8394

84-
private readonly ObservableCollection<IFileStatusEntry> _excludedChanges = new ObservableCollection<IFileStatusEntry>();
95+
private ObservableCollection<IFileStatusEntry> _excludedChanges = new ObservableCollection<IFileStatusEntry>();
8596
public ObservableCollection<IFileStatusEntry> ExcludedChanges
8697
{
8798
get { return _excludedChanges; }
99+
set
100+
{
101+
if (_excludedChanges != value)
102+
{
103+
_excludedChanges = value;
104+
OnPropertyChanged();
105+
}
106+
}
88107
}
89108

90-
public IEnumerable<IFileStatusEntry> UntrackedFiles
109+
private ObservableCollection<IFileStatusEntry> _untrackedFiles;
110+
public ObservableCollection<IFileStatusEntry> UntrackedFiles
91111
{
92-
get
112+
get { return _untrackedFiles; }
113+
set
93114
{
94-
return Provider == null
95-
? new ObservableCollection<IFileStatusEntry>()
96-
: new ObservableCollection<IFileStatusEntry>(
97-
Provider.Status().Where(stat => stat.FileStatus.HasFlag(FileStatus.Untracked)));
115+
if (_untrackedFiles != value)
116+
{
117+
_untrackedFiles = value;
118+
OnPropertyChanged();
119+
}
98120
}
99121
}
100122

Rubberduck.SourceControl/Branch.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ public class Branch : IBranch
3838
public string TrackingName { get; private set; }
3939

4040
public Branch(LibGit2Sharp.Branch branch)
41+
: this(branch.FriendlyName, branch.CanonicalName, branch.IsRemote, branch.IsCurrentRepositoryHead, branch.TrackedBranch)
4142
{
42-
Name = branch.FriendlyName;
43-
CanonicalName = branch.CanonicalName;
44-
IsRemote = branch.IsRemote;
45-
IsCurrentHead = branch.IsCurrentRepositoryHead;
43+
}
44+
45+
public Branch(string friendlyName, string canonicalName, bool isRemote, bool isCurrentRepositoryHead, LibGit2Sharp.Branch trackedBranch)
46+
{
47+
Name = friendlyName;
48+
CanonicalName = canonicalName;
49+
IsRemote = isRemote;
50+
IsCurrentHead = isCurrentRepositoryHead;
4651

47-
if (branch.TrackedBranch != null && branch.TrackedBranch.Tip != null) // make sure the online repo exists
52+
if (trackedBranch != null && trackedBranch.Tip != null) // make sure the online repo exists
4853
{
49-
TrackingName = branch.TrackedBranch.FriendlyName;
54+
TrackingName = trackedBranch.FriendlyName;
5055
}
5156
}
5257
}

RubberduckTests/Inspections/NonReturningFunctionInspectionTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void NonReturningPropertyGet_ReturnsResult()
5050
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
5151
var mockHost = new Mock<IHostApplication>();
5252
mockHost.SetupAllProperties();
53-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
53+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
5454

5555
parser.Parse();
5656
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -226,7 +226,7 @@ public void NonReturningFunction_QuickFixWorks_FunctionHasTypeHint()
226226
var module = project.VBComponents.Item(0).CodeModule;
227227
var mockHost = new Mock<IHostApplication>();
228228
mockHost.SetupAllProperties();
229-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
229+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
230230

231231
parser.Parse();
232232
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -258,7 +258,7 @@ public void NonReturningFunction_QuickFixWorks_FunctionReturnsImplicitVariant()
258258
var module = project.VBComponents.Item(0).CodeModule;
259259
var mockHost = new Mock<IHostApplication>();
260260
mockHost.SetupAllProperties();
261-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
261+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
262262

263263
parser.Parse();
264264
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -290,7 +290,7 @@ public void NonReturningFunction_QuickFixWorks_FunctionHasVariable()
290290
var module = project.VBComponents.Item(0).CodeModule;
291291
var mockHost = new Mock<IHostApplication>();
292292
mockHost.SetupAllProperties();
293-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
293+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
294294

295295
parser.Parse();
296296
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -322,7 +322,7 @@ public void NonReturningFunction_QuickFixWorks_PropertyGet()
322322
var module = project.VBComponents.Item(0).CodeModule;
323323
var mockHost = new Mock<IHostApplication>();
324324
mockHost.SetupAllProperties();
325-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
325+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
326326

327327
parser.Parse();
328328
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -354,7 +354,7 @@ public void NonReturningFunction_QuickFixWorks_PropertyGetHasTypeHint()
354354
var module = project.VBComponents.Item(0).CodeModule;
355355
var mockHost = new Mock<IHostApplication>();
356356
mockHost.SetupAllProperties();
357-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
357+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
358358

359359
parser.Parse();
360360
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -386,7 +386,7 @@ public void NonReturningFunction_QuickFixWorks_PropertyGetReturnsImplicitVariant
386386
var module = project.VBComponents.Item(0).CodeModule;
387387
var mockHost = new Mock<IHostApplication>();
388388
mockHost.SetupAllProperties();
389-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
389+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
390390

391391
parser.Parse();
392392
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }
@@ -418,7 +418,7 @@ public void NonReturningFunction_QuickFixWorks_PropertyGetHasVariable()
418418
var module = project.VBComponents.Item(0).CodeModule;
419419
var mockHost = new Mock<IHostApplication>();
420420
mockHost.SetupAllProperties();
421-
var parser = new RubberduckParser(vbe.Object, new RubberduckParserState());
421+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState());
422422

423423
parser.Parse();
424424
if (parser.State.Status == ParserState.Error) { Assert.Inconclusive("Parser Error"); }

RubberduckTests/RubberduckTests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<Compile Include="Settings\TodoSettingsTests.cs" />
136136
<Compile Include="Settings\UnitTestSettingsTests.cs" />
137137
<Compile Include="SourceControlConfig.cs" />
138+
<Compile Include="SourceControl\ChangesViewModelTests.cs" />
138139
<Compile Include="StringExtensionsTests.cs" />
139140
<Compile Include="TodoControllerTests.cs" />
140141
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -248,9 +249,7 @@
248249
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
249250
</Content>
250251
</ItemGroup>
251-
<ItemGroup>
252-
<Folder Include="SourceControl\" />
253-
</ItemGroup>
252+
<ItemGroup />
254253
<Choose>
255254
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
256255
<ItemGroup>

0 commit comments

Comments
 (0)