Skip to content

Commit d2ec356

Browse files
author
Lee Fine
committed
initial-integration-tests
1 parent d7763cd commit d2ec356

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

RemoteFileIntegrationTests/BaseRFPEMTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ public abstract class BaseRFPEMTest : BaseTest
1717
private static string pemCertificate = string.Empty;
1818
private static string pemKey = string.Empty;
1919

20-
public void CreateStore(string fileName, bool withExtKeyFile, bool withCertificate, STORE_ENVIRONMENT_ENUM storeEnvironment)
20+
21+
public static void CreateStore(string fileName, bool withExtKeyFile, bool withCertificate, STORE_ENVIRONMENT_ENUM storeEnvironment)
2122
{
2223
string storeContents = withCertificate ? (withExtKeyFile ? pemCertificate : pemCertificate + System.Environment.NewLine + pemKey) : string.Empty;
2324
CreateFile($"{fileName}.pem", Encoding.ASCII.GetBytes(storeContents), storeEnvironment);
2425
if (withExtKeyFile)
2526
CreateFile($"{fileName}.key", Encoding.ASCII.GetBytes(withCertificate ? pemKey : string.Empty), storeEnvironment);
2627
}
2728

28-
public void RemoveStore(string fileName, bool withExtKeyFile, STORE_ENVIRONMENT_ENUM storeEnvironment)
29+
public static void RemoveStore(string fileName, bool withExtKeyFile, STORE_ENVIRONMENT_ENUM storeEnvironment)
2930
{
3031
RemoveFile($"{fileName}.pem", storeEnvironment);
3132
if (withExtKeyFile)
3233
RemoveFile($"{fileName}.key", storeEnvironment);
3334
}
3435

35-
public void CreateCertificateAndKey()
36+
public static void CreateCertificateAndKey()
3637
{
3738
if (!string.IsNullOrEmpty(pemCertificate))
3839
return;

RemoteFileIntegrationTests/BaseTest.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace RemoteFileIntegrationTests
99
{
10-
public abstract class BaseTest : IDisposable
10+
public abstract class BaseTest
1111
{
1212
public enum STORE_ENVIRONMENT_ENUM
1313
{
@@ -40,45 +40,28 @@ public static void Init()
4040
{
4141
throw new Exception(".env not found. Make sure .env exists and is being copied to the run folder on compile.");
4242
}
43-
}
44-
45-
public BaseTest()
46-
{
47-
if (Connection != null)
48-
return;
4943

5044
string userId = EnvironmentVariables.LinuxUserId!;
5145
KeyboardInteractiveAuthenticationMethod keyboardAuthentication = new KeyboardInteractiveAuthenticationMethod(userId);
5246
Connection = new ConnectionInfo(EnvironmentVariables.LinuxServer, userId, new PasswordAuthenticationMethod(userId, EnvironmentVariables.LinuxUserPassword), keyboardAuthentication);
53-
54-
SetUp();
5547
}
5648

57-
public void CreateFile(string fileName, byte[] contents, STORE_ENVIRONMENT_ENUM storeEnvironment)
49+
public static void CreateFile(string fileName, byte[] contents, STORE_ENVIRONMENT_ENUM storeEnvironment)
5850
{
5951
if (storeEnvironment == STORE_ENVIRONMENT_ENUM.LINUX)
6052
CreateFileLinux(fileName, contents);
6153
if (storeEnvironment == STORE_ENVIRONMENT_ENUM.WINDOWS)
6254
CreateFileWindows(fileName, contents);
6355
}
6456

65-
public void RemoveFile(string fileName, STORE_ENVIRONMENT_ENUM storeEnvironment)
57+
public static void RemoveFile(string fileName, STORE_ENVIRONMENT_ENUM storeEnvironment)
6658
{
6759
if (storeEnvironment == STORE_ENVIRONMENT_ENUM.LINUX)
6860
RemoveFileLinux(fileName);
6961
if (storeEnvironment == STORE_ENVIRONMENT_ENUM.WINDOWS)
7062
RemoveFileWindows(fileName);
7163
}
7264

73-
public void Dispose()
74-
{
75-
TearDown();
76-
}
77-
78-
public abstract void SetUp();
79-
80-
public abstract void TearDown();
81-
8265
internal Mock<IPAMSecretResolver> GetMockSecretResolver(JobConfiguration config)
8366
{
8467
Mock<IPAMSecretResolver> secretResolver = new Mock<IPAMSecretResolver>();
@@ -92,7 +75,7 @@ internal Mock<IPAMSecretResolver> GetMockSecretResolver(JobConfiguration config)
9275
return secretResolver;
9376
}
9477

95-
private void CreateFileLinux(string fileName, byte[] contents)
78+
private static void CreateFileLinux(string fileName, byte[] contents)
9679
{
9780
using (ScpClient client = new ScpClient(Connection))
9881
{
@@ -113,12 +96,12 @@ private void CreateFileLinux(string fileName, byte[] contents)
11396
};
11497
}
11598

116-
private void CreateFileWindows(string fileName, byte[] contents)
99+
private static void CreateFileWindows(string fileName, byte[] contents)
117100
{
118101

119102
}
120103

121-
private void RemoveFileLinux(string fileName)
104+
private static void RemoveFileLinux(string fileName)
122105
{
123106
using (SftpClient client = new SftpClient(Connection))
124107
{
@@ -135,7 +118,7 @@ private void RemoveFileLinux(string fileName)
135118
};
136119
}
137120

138-
private void RemoveFileWindows(string fileName)
121+
private static void RemoveFileWindows(string fileName)
139122
{
140123

141124
}

RemoteFileIntegrationTests/RFPEMInventoryTests.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
using Org.BouncyCastle.X509;
99
using Org.BouncyCastle.Utilities.IO.Pem;
10+
using static RemoteFileIntegrationTests.BaseTest;
1011

1112
namespace RemoteFileIntegrationTests
1213
{
13-
public class RFPEMInventoryTests : BaseRFPEMTest
14+
public class RFPEMInventoryTests : BaseRFPEMTest, IClassFixture<RFPEMInventoryTestsFixture>
1415
{
1516
[Fact]
1617
public void RFPEM_Inventory_InternalPrivateKey_EmptyStore_Linux_Test0001()
@@ -70,24 +71,6 @@ public void RFPEM_Inventory_InternalPrivateKey_WithCert_Linux_Test0002()
7071
}
7172
}
7273

73-
public override void SetUp()
74-
{
75-
CreateCertificateAndKey();
76-
77-
CreateStore("Test0001", false, false, STORE_ENVIRONMENT_ENUM.LINUX);
78-
CreateStore("Test0002", false, true, STORE_ENVIRONMENT_ENUM.LINUX);
79-
CreateStore("Test0003", true, false, STORE_ENVIRONMENT_ENUM.LINUX);
80-
CreateStore("Test0004", true, true, STORE_ENVIRONMENT_ENUM.LINUX);
81-
}
82-
83-
public override void TearDown()
84-
{
85-
RemoveStore("Test0001", false, STORE_ENVIRONMENT_ENUM.LINUX);
86-
RemoveStore("Test0002", false, STORE_ENVIRONMENT_ENUM.LINUX);
87-
RemoveStore("Test0003", true, STORE_ENVIRONMENT_ENUM.LINUX);
88-
RemoveStore("Test0004", true, STORE_ENVIRONMENT_ENUM.LINUX);
89-
}
90-
9174
private InventoryJobConfiguration BuildBaseInventoryConfig()
9275
{
9376
InventoryJobConfiguration config = new InventoryJobConfiguration();
@@ -101,4 +84,39 @@ private InventoryJobConfiguration BuildBaseInventoryConfig()
10184
return config;
10285
}
10386
}
87+
88+
public class RFPEMInventoryTestsFixture : IDisposable
89+
{
90+
public RFPEMInventoryTestsFixture()
91+
{
92+
SetUp();
93+
}
94+
95+
public void Dispose()
96+
{
97+
TearDown();
98+
}
99+
100+
private void SetUp()
101+
{
102+
BaseRFPEMTest.CreateCertificateAndKey();
103+
104+
BaseRFPEMTest.CreateStore("Test0001", false, false, STORE_ENVIRONMENT_ENUM.LINUX);
105+
BaseRFPEMTest.CreateStore("Test0002", false, true, STORE_ENVIRONMENT_ENUM.LINUX);
106+
BaseRFPEMTest.CreateStore("Test0003", true, false, STORE_ENVIRONMENT_ENUM.LINUX);
107+
BaseRFPEMTest.CreateStore("Test0004", true, true, STORE_ENVIRONMENT_ENUM.LINUX);
108+
}
109+
110+
private void TearDown()
111+
{
112+
BaseRFPEMTest.RemoveStore("Test0001", false, STORE_ENVIRONMENT_ENUM.LINUX);
113+
BaseRFPEMTest.RemoveStore("Test0002", false, STORE_ENVIRONMENT_ENUM.LINUX);
114+
BaseRFPEMTest.RemoveStore("Test0003", true, STORE_ENVIRONMENT_ENUM.LINUX);
115+
BaseRFPEMTest.RemoveStore("Test0004", true, STORE_ENVIRONMENT_ENUM.LINUX);
116+
}
117+
}
118+
119+
120+
121+
104122
}

0 commit comments

Comments
 (0)