Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 6fe73d8

Browse files
Merge branch 'fixes/repository-manager-tests' into enhancements/repository-watcher-refactor
2 parents 6f14401 + 2256998 commit 6fe73d8

File tree

8 files changed

+74
-486
lines changed

8 files changed

+74
-486
lines changed

docs/contributing/how-to-test.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Unit and Integration tests for Unity can be found under `src/tests/`.
3+
4+
## Testing requirements
5+
Tests currently run with NUnit 2.6.4.
6+
7+
## Running tests
8+
Tests can be run after building the Unity project. To run the tests execute `test.cmd` on Windows or `test.sh` on Mac.
9+
10+
We use [Appveyor](https://ci.appveyor.com/project/github-windows/unity/build/tests) as the CI for this project to run tests, but it is also necessary to run tests locally when making code changes.

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private int ProcessEvents(Event[] fileEvents)
157157
break;
158158
}
159159

160-
//Logger.Trace(fileEvent.Describe());
160+
Logger.Trace(fileEvent.Describe());
161161

162162
var eventDirectory = new NPath(fileEvent.Directory);
163163
var fileA = eventDirectory.Combine(fileEvent.FileA);

src/tests/IntegrationTests/BaseGitEnvironmentTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace IntegrationTests
99
class BaseGitEnvironmentTest : BaseGitRepoTest
1010
{
1111
protected async Task<IEnvironment> Initialize(NPath repoPath, NPath environmentPath = null,
12-
bool enableEnvironmentTrace = false)
12+
bool enableEnvironmentTrace = false, bool initializeRepository = true)
1313
{
1414
TaskManager = new TaskManager();
1515
SyncContext = new ThreadSynchronizationContext(TaskManager.Token);
@@ -34,8 +34,11 @@ protected async Task<IEnvironment> Initialize(NPath repoPath, NPath environmentP
3434
RepositoryManager = GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, repoPath);
3535
RepositoryManager.Initialize();
3636

37-
Environment.Repository = new Repository(repoPath, cacheContainer);
38-
Environment.Repository.Initialize(RepositoryManager);
37+
if (initializeRepository)
38+
{
39+
Environment.Repository = new Repository(repoPath, cacheContainer);
40+
Environment.Repository.Initialize(RepositoryManager);
41+
}
3942

4043
RepositoryManager.Start();
4144

src/tests/IntegrationTests/Events/RepositoryManagerTests.cs

Lines changed: 17 additions & 470 deletions
Large diffs are not rendered by default.

src/tests/IntegrationTests/SetUpFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Setup()
1414

1515
Logging.LogAdapter = new MultipleLogAdapter(
1616
new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log")
17-
//, new ConsoleLogAdapter()
17+
, new ConsoleLogAdapter()
1818
);
1919
}
2020
}

src/tests/TestUtils/Events/IRepositoryManagerListener.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace TestUtils.Events
1010
interface IRepositoryManagerListener
1111
{
1212
void OnIsBusyChanged(bool busy);
13-
void OnStatusUpdated(GitStatus status);
14-
void OnLocksUpdated(IEnumerable<GitLock> locks);
1513
void OnLocalBranchListUpdated(Dictionary<string, ConfigBranch> branchList);
1614
void OnRemoteBranchListUpdated(Dictionary<string, ConfigRemote> remotesList, Dictionary<string, Dictionary<string, ConfigBranch>> remoteBranchList);
1715
void OnCurrentBranchAndRemoteUpdated(ConfigBranch? configBranch, ConfigRemote? configRemote);
@@ -21,7 +19,6 @@ class RepositoryManagerEvents
2119
{
2220
public EventWaitHandle OnIsBusy { get; } = new AutoResetEvent(false);
2321
public EventWaitHandle OnIsNotBusy { get; } = new AutoResetEvent(false);
24-
public EventWaitHandle OnStatusUpdated { get; } = new AutoResetEvent(false);
2522
public EventWaitHandle OnLocksUpdated { get; } = new AutoResetEvent(false);
2623
public EventWaitHandle OnCurrentBranchAndRemoteUpdated { get; } = new AutoResetEvent(false);
2724
public EventWaitHandle OnHeadUpdated { get; } = new AutoResetEvent(false);
@@ -32,7 +29,6 @@ public void Reset()
3229
{
3330
OnIsBusy.Reset();
3431
OnIsNotBusy.Reset();
35-
OnStatusUpdated.Reset();
3632
OnLocksUpdated.Reset();
3733
OnCurrentBranchAndRemoteUpdated.Reset();
3834
OnHeadUpdated.Reset();
@@ -46,11 +42,6 @@ public void WaitForNotBusy(int seconds = 1)
4642
OnIsNotBusy.WaitOne(TimeSpan.FromSeconds(seconds));
4743
}
4844

49-
public void WaitForStatusUpdated(int seconds = 1)
50-
{
51-
OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(seconds));
52-
}
53-
5445
public void WaitForHeadUpdated(int seconds = 1)
5546
{
5647
OnHeadUpdated.WaitOne(TimeSpan.FromSeconds(seconds));
@@ -95,8 +86,6 @@ public static void AttachListener(this IRepositoryManagerListener listener,
9586
public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener repositoryManagerListener)
9687
{
9788
repositoryManagerListener.DidNotReceive().OnIsBusyChanged(Args.Bool);
98-
repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus);
99-
repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock);
10089
repositoryManagerListener.DidNotReceive().OnCurrentBranchAndRemoteUpdated(Arg.Any<ConfigBranch?>(), Arg.Any<ConfigRemote?>());
10190
repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any<Dictionary<string, ConfigBranch>>());
10291
repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any<Dictionary<string, ConfigRemote>>(), Arg.Any<Dictionary<string, Dictionary<string, ConfigBranch>>>());

test.cmd

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
setlocal
3+
4+
set Config=Debug
5+
if not %1.==. (
6+
set Config=%1
7+
)
8+
9+
set Exclude=''
10+
if not %2.==. (
11+
set Exclude=%2
12+
)
13+
14+
:: make sure at Unity project root directory
15+
set NunitDirectory=packages\NUnit.Runners.2.6.4\tools
16+
echo %NunitDirectory%
17+
set ConsoleRunner=%NunitDirectory%\nunit-console.exe
18+
echo %ConsoleRunner%
19+
20+
:: run tests
21+
echo Running "build\IntegrationTests\IntegrationTests.dll" "build\IntegrationTests\TestUtils.dll" "build\TaskSystemIntegrationTests\TaskSystemIntegrationTests.dll" "build\UnitTests\TestUtils.dll" "build\UnitTests\UnitTests.dll" "src\tests\TestUtils\bin\%Config%\TestUtils.dll" /exclude=%Exclude%
22+
call %ConsoleRunner% "build\IntegrationTests\IntegrationTests.dll" "build\IntegrationTests\TestUtils.dll" "build\TaskSystemIntegrationTests\TaskSystemIntegrationTests.dll" "build\UnitTests\TestUtils.dll" "build\UnitTests\UnitTests.dll" "src\tests\TestUtils\bin\%Config%\TestUtils.dll" /exclude=%Exclude%
23+
24+
endlocal

test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh -eu
2+
Configuration="Debug"
3+
if [ $# -gt 0 ]; then
4+
Configuration=$1
5+
fi
6+
7+
Exclude=""
8+
if [ $# -gt 1 ]; then
9+
Exclude="/exclude=$2"
10+
fi
11+
12+
NunitDirectory="packages\NUnit.Runners.2.6.4\tools"
13+
ConsoleRunner="$NunitDirectory\nunit-console.exe"
14+
15+
$ConsoleRunner "build\IntegrationTests\IntegrationTests.dll" "build\IntegrationTests\TestUtils.dll" "build\TaskSystemIntegrationTests\TaskSystemIntegrationTests.dll" "build\UnitTests\TestUtils.dll" "build\UnitTests\UnitTests.dll" "src\tests\TestUtils\bin\\$Configuration\TestUtils.dll" $Exclude

0 commit comments

Comments
 (0)