Skip to content

Commit 77deee2

Browse files
committed
feat: Add user config to specify if servers should be run before tests. By default they will not be run.
1 parent 21a5c74 commit 77deee2

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,6 @@ ASALocalRun/
339339
# BeatPulse healthcheck temp database
340340
healthchecksdb
341341
*.snk
342+
343+
# Ignore user config file
344+
/src/SocketIOClient.Test/user.json
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace SocketIOClient.Test.Configuration
2+
{
3+
public class UserConfig
4+
{
5+
public bool RunServers { get; set; } = false;
6+
public bool StopServersAfterRun { get; set; } = false;
7+
}
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO;
2+
3+
namespace SocketIOClient.Test.Configuration
4+
{
5+
public class UserConfigManager
6+
{
7+
private const string configFileName = "user.json";
8+
9+
public bool Exists => File.Exists(configFileName);
10+
11+
public UserConfig Get()
12+
{
13+
if (!this.Exists)
14+
{
15+
return null;
16+
}
17+
18+
return System.Text.Json.JsonSerializer.Deserialize<UserConfig>(File.ReadAllText(configFileName));
19+
}
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Rename "user_sample.json" to "user.json" and copy to output directory (comment must be removed)
2+
{
3+
"RunServers": true,
4+
"StopServersAfterRun": true
5+
}

src/SocketIOClient.Test/SocketIOClient.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<None Update="Files\tianlongbabu.epub">
2929
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3030
</None>
31+
<None Update="user.json">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</None>
3134
</ItemGroup>
3235

3336
</Project>

src/SocketIOClient.Test/SocketIOTests/AssemblyIntegrationTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using SocketIOClient.Test.Configuration;
23
using SocketIOClient.Test.SocketIOTests.V4;
34
using System;
45
using System.Collections.Generic;
@@ -17,10 +18,14 @@ public class AssemblyIntegrationTest
1718
new ServerV4Manager()
1819
};
1920

21+
private static UserConfig UserConfig => new UserConfigManager().Get() ?? new UserConfig();
22+
23+
private static bool IsRunningOnAzureDevOps => Environment.GetEnvironmentVariable("SYSTEM_DEFINITIONID") != null;
24+
2025
[AssemblyInitialize]
2126
public static void Initialize(TestContext context)
2227
{
23-
if (!IsRunningOnAzureDevOps())
28+
if (!IsRunningOnAzureDevOps && UserConfig.RunServers)
2429
{
2530
foreach (var server in Servers)
2631
{
@@ -35,18 +40,13 @@ public static void Initialize(TestContext context)
3540
[AssemblyCleanup]
3641
public static void Cleanup()
3742
{
38-
if (!IsRunningOnAzureDevOps())
43+
if (!IsRunningOnAzureDevOps && UserConfig.RunServers && UserConfig.StopServersAfterRun)
3944
{
4045
foreach (var server in Servers)
4146
{
4247
server.Destroy();
4348
}
4449
}
4550
}
46-
47-
private static bool IsRunningOnAzureDevOps()
48-
{
49-
return Environment.GetEnvironmentVariable("SYSTEM_DEFINITIONID") != null;
50-
}
5151
}
5252
}

0 commit comments

Comments
 (0)