Skip to content

Commit 36fe42f

Browse files
committed
Add unit tests for Repository, RepositoryView and StatusCompressor
1 parent 1c6d5e1 commit 36fe42f

17 files changed

+1060
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ProjectConfiguration>
2+
<Settings>
3+
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
4+
</Settings>
5+
</ProjectConfiguration>

RepoZ.Api/Git/Repository.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace RepoZ.Api.Git
99
{
10-
[DebuggerDisplay("{Name}")]
10+
[DebuggerDisplay("{Name} @{Path}")]
1111
public class Repository
1212
{
1313
public override bool Equals(object obj)
@@ -16,7 +16,19 @@ public override bool Equals(object obj)
1616
if (other == null)
1717
return false;
1818

19-
return string.Equals(other.Path, this.Path);
19+
if (string.IsNullOrEmpty(other.Path))
20+
return string.IsNullOrEmpty(Path);
21+
22+
return string.Equals(Normalize(other.Path), Normalize(Path), StringComparison.OrdinalIgnoreCase);
23+
}
24+
25+
private string Normalize(string path)
26+
{
27+
const string BS = @"\";
28+
29+
path = path.Replace("/", BS);
30+
31+
return System.IO.Path.GetDirectoryName(path + BS);
2032
}
2133

2234
public override int GetHashCode()

RepoZ.Api/RepoZ.Api.v3.ncrunchproject

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ProjectConfiguration>
2+
<Settings>
3+
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
4+
</Settings>
5+
</ProjectConfiguration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ProjectConfiguration>
2+
<Settings>
3+
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
4+
</Settings>
5+
</ProjectConfiguration>

RepoZ.UI/RepoZ.UI.v3.ncrunchproject

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ProjectConfiguration>
2+
<Settings>
3+
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
4+
</Settings>
5+
</ProjectConfiguration>

RepoZ.UI/RepositoryView.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace RepoZ.UI
1111
{
12-
[DebuggerDisplay("{Name}")]
12+
[DebuggerDisplay("{Name} @{Path}")]
1313
public class RepositoryView
1414
{
1515
public RepositoryView(Repository repository)
@@ -20,16 +20,18 @@ public RepositoryView(Repository repository)
2020
Repository = repository;
2121
}
2222

23-
public string Name => Repository.Name;
23+
public string Name => Repository.Name ?? "";
2424

25-
public string Path => Repository.Path;
25+
public string Path => Repository.Path ?? "";
2626

27-
public string CurrentBranch => Repository.CurrentBranch;
27+
public string CurrentBranch => Repository.CurrentBranch ?? "";
2828

2929
public string AheadBy => Repository.AheadBy?.ToString() ?? "";
3030

3131
public string BehindBy => Repository.BehindBy?.ToString() ?? "";
3232

33+
public string[] Branches => Repository.Branches ?? new string[0];
34+
3335
public string LocalUntracked => Repository.LocalUntracked?.ToString() ?? "";
3436

3537
public string LocalModified => Repository.LocalModified?.ToString() ?? "";

RepoZ.UI/StatusCompressor.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace RepoZ.UI
99
{
1010
public static class StatusCompressor
1111
{
12-
const string SIGN_IDENTICAL = "\u2261";
13-
const string SIGN_ARROW_UP = "\u2191";
14-
const string SIGN_ARROW_DOWN = "\u2193";
12+
public const string SIGN_IDENTICAL = "\u2261";
13+
public const string SIGN_ARROW_UP = "\u2191";
14+
public const string SIGN_ARROW_DOWN = "\u2193";
1515

1616
public static string Compress(Repository repository)
1717
{
@@ -49,15 +49,21 @@ public static string Compress(Repository repository)
4949

5050
if (printASR)
5151
{
52-
builder.AppendFormat(" +{0} ~{1} -{2}", repository.LocalAdded ?? 0, repository.LocalStaged ?? 0, repository.LocalRemoved ?? 0);
52+
if (builder.Length > 0)
53+
builder.Append(" ");
54+
55+
builder.AppendFormat("+{0} ~{1} -{2}", repository.LocalAdded ?? 0, repository.LocalStaged ?? 0, repository.LocalRemoved ?? 0);
5356
}
5457

5558
if (printUMM)
5659
{
60+
if (builder.Length > 0)
61+
builder.Append(" ");
62+
5763
if (printASR)
58-
builder.Append(" |");
64+
builder.Append("| ");
5965

60-
builder.AppendFormat(" +{0} ~{1} -{2}", repository.LocalUntracked ?? 0, repository.LocalModified ?? 0, repository.LocalMissing ?? 0);
66+
builder.AppendFormat("+{0} ~{1} -{2}", repository.LocalUntracked ?? 0, repository.LocalModified ?? 0, repository.LocalMissing ?? 0);
6167
}
6268

6369
return builder.ToString();

RepoZ.Win.sln

+74-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26403.3
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepoZ.UI", "RepoZ.UI\RepoZ.UI.csproj", "{5925C073-A5AA-4B9D-92E5-CAC8B5309635}"
77
EndProject
@@ -11,28 +11,100 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepoZ.Api", "RepoZ.Api\Repo
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RepoZ.Api.Win", "RepoZ.Api.Win\RepoZ.Api.Win.csproj", "{85C75358-4E23-4074-9376-8079C874BD1E}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{A6B79146-761A-40C3-951D-7415297792FD}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
19+
Debug|ARM = Debug|ARM
20+
Debug|x64 = Debug|x64
21+
Debug|x86 = Debug|x86
1722
Release|Any CPU = Release|Any CPU
23+
Release|ARM = Release|ARM
24+
Release|x64 = Release|x64
25+
Release|x86 = Release|x86
1826
EndGlobalSection
1927
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2028
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2129
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|ARM.ActiveCfg = Debug|Any CPU
31+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|ARM.Build.0 = Debug|Any CPU
32+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|x64.ActiveCfg = Debug|Any CPU
33+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|x64.Build.0 = Debug|Any CPU
34+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|x86.ActiveCfg = Debug|Any CPU
35+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Debug|x86.Build.0 = Debug|Any CPU
2236
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|Any CPU.ActiveCfg = Release|Any CPU
2337
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|ARM.ActiveCfg = Release|Any CPU
39+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|ARM.Build.0 = Release|Any CPU
40+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|x64.ActiveCfg = Release|Any CPU
41+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|x64.Build.0 = Release|Any CPU
42+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|x86.ActiveCfg = Release|Any CPU
43+
{5925C073-A5AA-4B9D-92E5-CAC8B5309635}.Release|x86.Build.0 = Release|Any CPU
2444
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2545
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|ARM.ActiveCfg = Debug|Any CPU
47+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|ARM.Build.0 = Debug|Any CPU
48+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|x64.ActiveCfg = Debug|Any CPU
49+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|x64.Build.0 = Debug|Any CPU
50+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|x86.ActiveCfg = Debug|Any CPU
51+
{A135F86A-3003-471B-B776-50DB788D3846}.Debug|x86.Build.0 = Debug|Any CPU
2652
{A135F86A-3003-471B-B776-50DB788D3846}.Release|Any CPU.ActiveCfg = Release|Any CPU
2753
{A135F86A-3003-471B-B776-50DB788D3846}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|ARM.ActiveCfg = Release|Any CPU
55+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|ARM.Build.0 = Release|Any CPU
56+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|x64.ActiveCfg = Release|Any CPU
57+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|x64.Build.0 = Release|Any CPU
58+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|x86.ActiveCfg = Release|Any CPU
59+
{A135F86A-3003-471B-B776-50DB788D3846}.Release|x86.Build.0 = Release|Any CPU
2860
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2961
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|ARM.ActiveCfg = Debug|Any CPU
63+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|ARM.Build.0 = Debug|Any CPU
64+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|x64.ActiveCfg = Debug|Any CPU
65+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|x64.Build.0 = Debug|Any CPU
66+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|x86.ActiveCfg = Debug|Any CPU
67+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Debug|x86.Build.0 = Debug|Any CPU
3068
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3169
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|Any CPU.Build.0 = Release|Any CPU
70+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|ARM.ActiveCfg = Release|Any CPU
71+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|ARM.Build.0 = Release|Any CPU
72+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|x64.ActiveCfg = Release|Any CPU
73+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|x64.Build.0 = Release|Any CPU
74+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|x86.ActiveCfg = Release|Any CPU
75+
{8F74519B-B72D-4A5E-B20B-723543676E5E}.Release|x86.Build.0 = Release|Any CPU
3276
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3377
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|ARM.ActiveCfg = Debug|Any CPU
79+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|ARM.Build.0 = Debug|Any CPU
80+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|x64.ActiveCfg = Debug|Any CPU
81+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|x64.Build.0 = Debug|Any CPU
82+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|x86.ActiveCfg = Debug|Any CPU
83+
{85C75358-4E23-4074-9376-8079C874BD1E}.Debug|x86.Build.0 = Debug|Any CPU
3484
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3585
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|ARM.ActiveCfg = Release|Any CPU
87+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|ARM.Build.0 = Release|Any CPU
88+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|x64.ActiveCfg = Release|Any CPU
89+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|x64.Build.0 = Release|Any CPU
90+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|x86.ActiveCfg = Release|Any CPU
91+
{85C75358-4E23-4074-9376-8079C874BD1E}.Release|x86.Build.0 = Release|Any CPU
92+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|ARM.ActiveCfg = Debug|Any CPU
95+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|ARM.Build.0 = Debug|Any CPU
96+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|x64.ActiveCfg = Debug|Any CPU
97+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|x64.Build.0 = Debug|Any CPU
98+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|x86.ActiveCfg = Debug|Any CPU
99+
{A6B79146-761A-40C3-951D-7415297792FD}.Debug|x86.Build.0 = Debug|Any CPU
100+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|Any CPU.Build.0 = Release|Any CPU
102+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|ARM.ActiveCfg = Release|Any CPU
103+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|ARM.Build.0 = Release|Any CPU
104+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|x64.ActiveCfg = Release|Any CPU
105+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|x64.Build.0 = Release|Any CPU
106+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|x86.ActiveCfg = Release|Any CPU
107+
{A6B79146-761A-40C3-951D-7415297792FD}.Release|x86.Build.0 = Release|Any CPU
36108
EndGlobalSection
37109
GlobalSection(SolutionProperties) = preSolution
38110
HideSolutionNode = FALSE

RepoZ.Win.v3.ncrunchsolution

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<SolutionConfiguration>
2+
<Settings>
3+
<AllowParallelTestExecution>True</AllowParallelTestExecution>
4+
<SolutionConfigured>True</SolutionConfigured>
5+
</Settings>
6+
</SolutionConfiguration>

Tests/Git/RepositoryTests.cs

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using FluentAssertions;
7+
using NUnit.Framework;
8+
using RepoZ.Api.Git;
9+
using Tests.Helper;
10+
11+
namespace Tests.Git
12+
{
13+
public class RepositoryTests
14+
{
15+
protected RepositoryBuilder _builder1;
16+
protected RepositoryBuilder _builder2;
17+
18+
[SetUp]
19+
public void Setup()
20+
{
21+
_builder1 = new RepositoryBuilder();
22+
_builder2 = new RepositoryBuilder();
23+
}
24+
25+
public class EqualsMethod : RepositoryTests
26+
{
27+
[Test]
28+
public void Is_Not_Case_Sensitive()
29+
{
30+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ\").Build();
31+
var r2 = _builder2.WithPath(@"c:\develop\repoz\rEPOz\").Build();
32+
33+
r1.Equals(r2).Should().BeTrue();
34+
}
35+
36+
[Test]
37+
public void Ignores_Ending_Slash()
38+
{
39+
var r1 = _builder1.WithPath(@"/c/develop/repoz/repoz").Build();
40+
var r2 = _builder2.WithPath(@"/c/develop/repoz/repoz/").Build();
41+
42+
r1.Equals(r2).Should().BeTrue();
43+
}
44+
45+
[Test]
46+
public void Ignores_Ending_Slashes()
47+
{
48+
var r1 = _builder1.WithPath(@"/c/develop/repoz/repoz/").Build();
49+
var r2 = _builder2.WithPath(@"/c/develop/repoz/repoz///").Build();
50+
51+
r1.Equals(r2).Should().BeTrue();
52+
}
53+
54+
[Test]
55+
public void Ignores_Ending_Backslash()
56+
{
57+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ").Build();
58+
var r2 = _builder2.WithPath(@"C:\Develop\RepoZ\RepoZ\").Build();
59+
60+
r1.Equals(r2).Should().BeTrue();
61+
}
62+
63+
[Test]
64+
public void Ignores_Ending_Backslashes()
65+
{
66+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ\").Build();
67+
var r2 = _builder2.WithPath(@"C:\Develop\RepoZ\RepoZ\\\").Build();
68+
69+
r1.Equals(r2).Should().BeTrue();
70+
}
71+
72+
[Test]
73+
public void Can_Use_Either_Slashes_Or_Backslashes()
74+
{
75+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ\").Build();
76+
var r2 = _builder2.WithPath(@"C:/Develop/RepoZ/RepoZ/").Build();
77+
78+
r1.Equals(r2).Should().BeTrue();
79+
}
80+
81+
[Test]
82+
public void Accepts_Leading_Whitespaces()
83+
{
84+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ").Build();
85+
var r2 = _builder2.WithPath(@" C:\Develop\RepoZ\RepoZ").Build();
86+
87+
r1.Equals(r2).Should().BeTrue();
88+
}
89+
90+
[Test]
91+
public void Accepts_Ending_Whitespaces()
92+
{
93+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ").Build();
94+
var r2 = _builder2.WithPath(@"C:\Develop\RepoZ\RepoZ ").Build();
95+
96+
r1.Equals(r2).Should().BeTrue();
97+
}
98+
99+
[Test]
100+
public void Accepts_Empty_Strings()
101+
{
102+
var r1 = _builder1.WithPath("").Build();
103+
var r2 = _builder2.WithPath("").Build();
104+
105+
r1.Equals(r2).Should().BeTrue();
106+
}
107+
108+
[Test]
109+
public void Can_Handle_Null()
110+
{
111+
var r1 = _builder1.WithPath(@"C:\Develop\RepoZ\RepoZ\").Build();
112+
113+
r1.Equals(null).Should().BeFalse();
114+
}
115+
}
116+
}
117+
}

0 commit comments

Comments
 (0)