Skip to content

Commit 710089a

Browse files
committed
(split from main repo) Execute unit tests
The unit tests can now be invoked from a command line with `-test` switch, e.g.: ``` > .\build.cmd -test ``` Notable changes: * Rename unit tests projects * Ignore unit tests for the external projects and the VSIX
0 parents  commit 710089a

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

Gerrit.Tests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\..\Plugins\Gerrit\Gerrit.csproj" />
5+
<ProjectReference Include="..\..\..\ResourceManager\ResourceManager.csproj" />
6+
</ItemGroup>
7+
8+
</Project>

Properties/AssemblyInfo.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
using CommonTestUtils;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("GerritTests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("GerritTests")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("2f8f55f7-c82f-44fc-ab52-9d0c692996fc")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
38+
[assembly: TestAppSettings]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Gerrit.Server;
7+
using NUnit.Framework;
8+
9+
namespace GerritTests.Server
10+
{
11+
public static class CommandBuilderWithDraftSupportTests
12+
{
13+
[TestCase("a, b, c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
14+
[TestCase("a|b|c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
15+
[TestCase("a b c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
16+
[TestCase("a; b;c", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=a,r=b,r=c")]
17+
[TestCase("q", "fix-7521", ExpectedResult = "refs/for/fix-7521%r=q")]
18+
[TestCase("", "fix-7521", ExpectedResult = "refs/for/fix-7521")]
19+
[TestCase(null, "fix-7521", ExpectedResult = "refs/for/fix-7521")]
20+
public static string Build_WithReviewers_splits_reviewrs_and_builds_expected_command(string reviewer, string branch)
21+
{
22+
var sut = new CommandBuilderWithDraftSupport();
23+
return sut.WithReviewers(reviewer).Build(branch);
24+
}
25+
26+
[Test(ExpectedResult = "refs/drafts/master%r=a")]
27+
public static string Build_when_publishtype_is_drafts_builds_expected_command()
28+
{
29+
var sut = new CommandBuilderWithDraftSupport();
30+
return sut.WithReviewers("a").WithPublishType("drafts").Build("master");
31+
}
32+
33+
[Test(ExpectedResult = "refs/for/fix-7521")]
34+
public static string Build_with_all_values_on_default_builds_expected_command()
35+
{
36+
var sut = new CommandBuilderWithDraftSupport();
37+
return sut.WithReviewers(string.Empty)
38+
.WithCC(string.Empty)
39+
.WithTopic(string.Empty)
40+
.WithPublishType(string.Empty)
41+
.WithHashTag(string.Empty)
42+
.Build("fix-7521");
43+
}
44+
45+
[Test(ExpectedResult = "refs/for/fix-7521%r=mygroup,cc=team2,topic=ABC-123,hashtag=what")]
46+
public static string Build_with_values_for_all_options_builds_expected_command()
47+
{
48+
var sut = new CommandBuilderWithDraftSupport();
49+
return sut.WithReviewers("mygroup")
50+
.WithCC("team2")
51+
.WithTopic("ABC-123")
52+
.WithPublishType(string.Empty)
53+
.WithHashTag("what")
54+
.Build("fix-7521");
55+
}
56+
}
57+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Gerrit.Server;
7+
using NUnit.Framework;
8+
9+
namespace GerritTests.Server
10+
{
11+
public static class CommandBuilderWithPrivateSupportTests
12+
{
13+
[TestCase("", ExpectedResult = "refs/for/mybranch")]
14+
[TestCase("wip", ExpectedResult = "refs/for/mybranch%wip")]
15+
[TestCase("private", ExpectedResult = "refs/for/mybranch%private")]
16+
public static string Build_given_a_publishType_builds_expected_command(string publishType)
17+
{
18+
var sut = new CommandBuilderWithPrivateSupport();
19+
20+
return sut.WithPublishType(publishType).Build("mybranch");
21+
}
22+
23+
[Test]
24+
public static void Build_given_a_set_of_values_builds_expected_command()
25+
{
26+
var sut = new CommandBuilderWithPrivateSupport();
27+
28+
Assert.AreEqual("refs/for/master%r=myteam",
29+
sut.WithReviewers("myteam").WithPublishType(string.Empty).Build("master"));
30+
}
31+
}
32+
}

Server/GerritCapabilityTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Linq;
2+
using Gerrit.Server;
3+
using NUnit.Framework;
4+
5+
namespace GerritTests.Server
6+
{
7+
public static class GerritCapabilityTests
8+
{
9+
[Test]
10+
public static void PublishTypes_for_Version2_15_has_expected_list_of_values()
11+
{
12+
RunTest(GerritCapabilities.Version2_15, new[] { "", "wip", "private" });
13+
}
14+
15+
[Test]
16+
public static void PublishTypes_for_OlderVersion_has_expected_list_of_values()
17+
{
18+
RunTest(GerritCapabilities.OldestVersion, new[] { "", "drafts" });
19+
}
20+
21+
private static void RunTest(GerritCapabilities capability, string[] expectedValues)
22+
{
23+
var publishTypes = capability.PublishTypes
24+
.Select(x => x.Value)
25+
.ToArray();
26+
27+
Assert.That(publishTypes, Is.EqualTo(expectedValues));
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)