diff --git a/.github/workflows/Compile.yml b/.github/workflows/Compile.yml index 7c921af..33866fb 100644 --- a/.github/workflows/Compile.yml +++ b/.github/workflows/Compile.yml @@ -32,5 +32,5 @@ jobs: working-directory: ./csharp/IotaWalletNet - name: Test - run: dotnet test --configuration Release --no-build --verbosity normal + run: dotnet test --configuration Release --no-build --verbosity normal -p:ParallelizeTestCollections=false working-directory: ./csharp/IotaWalletNet diff --git a/.github/workflows/GithubNuget.yml b/.github/workflows/GithubNuget.yml index 2f3918f..6f6ab16 100644 --- a/.github/workflows/GithubNuget.yml +++ b/.github/workflows/GithubNuget.yml @@ -46,7 +46,7 @@ jobs: working-directory: ./csharp/IotaWalletNet - name: Test - run: dotnet test --configuration Release --no-build --verbosity normal + run: dotnet test --configuration Release --no-build --verbosity normal -p:ParallelizeTestCollections=false working-directory: ./csharp/IotaWalletNet - name: Get Version diff --git a/.github/workflows/Nuget.yml b/.github/workflows/Nuget.yml index 1bc0872..7812198 100644 --- a/.github/workflows/Nuget.yml +++ b/.github/workflows/Nuget.yml @@ -46,7 +46,7 @@ jobs: working-directory: ./csharp/IotaWalletNet - name: Test - run: dotnet test --configuration Release --no-build --verbosity normal + run: dotnet test --configuration Release --no-build --verbosity normal -p:ParallelizeTestCollections=false working-directory: ./csharp/IotaWalletNet - name: Get Version diff --git a/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Interfaces/IWallet.cs b/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Interfaces/IWallet.cs index 7c79c73..5a6702d 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Interfaces/IWallet.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Interfaces/IWallet.cs @@ -4,7 +4,7 @@ namespace IotaWalletNet.Application.Common.Interfaces { - public interface IWallet : IRustBridgeCommunicator + public interface IWallet : IRustBridgeCommunicator, IDisposable { ClientOptionsBuilder ConfigureClientOptions(); SecretManagerOptionsBuilder ConfigureSecretManagerOptions(); diff --git a/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Options/ClientOptions.cs b/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Options/ClientOptions.cs index f09a44f..1140b01 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Options/ClientOptions.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Application/Common/Options/ClientOptions.cs @@ -10,6 +10,8 @@ public class ClientOptions public bool FallbackToLocalPow { get; set; } = true; + //public bool Offline { get; set; } = true; + } public class ClientOptionsBuilder diff --git a/csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs b/csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs index cb7afa3..fe8a486 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs @@ -15,7 +15,7 @@ namespace IotaWalletNet.Application { - public class Wallet : RustBridgeCommunicator, IWallet, IDisposable + public class Wallet : RustBridgeCommunicator, IWallet { #region Variables @@ -135,6 +135,7 @@ public SecretManagerOptionsBuilder ConfigureSecretManagerOptions() public WalletOptionsBuilder ConfigureWalletOptions() => new WalletOptionsBuilder(this); + public void Dispose() { CloseIotaWallet(_walletHandle); diff --git a/csharp/IotaWalletNet/IotaWalletNet.Tests/Common/Interfaces/DependencyTestBase.cs b/csharp/IotaWalletNet/IotaWalletNet.Tests/Common/Interfaces/DependencyTestBase.cs index a45d1d9..bc13ff1 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Tests/Common/Interfaces/DependencyTestBase.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Tests/Common/Interfaces/DependencyTestBase.cs @@ -6,6 +6,8 @@ namespace IotaWalletNet.Tests.Common.Interfaces public class DependencyTestBase : IDisposable { protected IServiceScope _serviceScope; + protected const String STRONGHOLD_PATH = "./stronghold"; + protected const string DATABASE_PATH = "./walletdb"; public DependencyTestBase() { @@ -19,9 +21,30 @@ public DependencyTestBase() _serviceScope = serviceProvider.CreateScope(); } + public void StrongholdCleanup(string path=STRONGHOLD_PATH) + { + if(File.Exists(path)) + File.Delete(path); + } + + public void DatabaseCleanup(string path=DATABASE_PATH) + { + if(Directory.Exists(path)) + Directory.Delete(path, true); + } public void Dispose() { _serviceScope.Dispose(); + + //Force garbage collection + GC.Collect(); + + //Give enough time for services to close + Thread.Sleep(100); + + StrongholdCleanup(); + DatabaseCleanup(); + } } } diff --git a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/ClientOptionsTest.cs b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/ClientOptionsTest.cs index e8cc25c..ae1ed8f 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/ClientOptionsTest.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/ClientOptionsTest.cs @@ -6,6 +6,7 @@ namespace IotaWalletNet.Tests.Wallet { + [Collection("Sequential")] public class ClientOptionsTest : DependencyTestBase { @@ -21,6 +22,8 @@ public void ClientOptionsBuilderShouldReturnWalletWhenBuild() .ThenBuild(); wallet.Should().NotBeNull(); + + } [Fact] @@ -41,6 +44,8 @@ public void AddingDuplicateNodesShouldBeTreatedAsSingle() clientOptions.Nodes.Should().HaveCount(1); clientOptions.Nodes.First().Equals(nodeUrl); + + } [Fact] @@ -63,6 +68,8 @@ public void AddingNonDuplicateNodesShouldBeTreatedAsMultiple() clientOptions.Nodes.Should().HaveCount(2); clientOptions.Nodes.First().Equals(nodeUrl); clientOptions.Nodes.ToList()[1].Equals(secondNodeUrl); + + } [Fact] @@ -99,6 +106,7 @@ public void ClientOptionsShouldBeConfigurableByBuilder() clientOptions.Nodes.Should().HaveCount(1); clientOptions.Nodes.First().Equals(nodeUrl); + } } } \ No newline at end of file diff --git a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/SecretManagerOptionsTest.cs b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/SecretManagerOptionsTest.cs index 83e9a52..3eb5a06 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/SecretManagerOptionsTest.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/SecretManagerOptionsTest.cs @@ -6,6 +6,7 @@ namespace IotaWalletNet.Tests.Wallet { + [Collection("Sequential")] public class SecretManagerOptionsTest : DependencyTestBase { [Fact] @@ -14,31 +15,33 @@ public void SecretManagerOptionBuilderShouldReturnWalletWhenBuild() IWallet wallet = _serviceScope.ServiceProvider.GetRequiredService(); wallet = wallet .ConfigureSecretManagerOptions() - .SetSnapshotPath("./snapshot") + .SetSnapshotPath(STRONGHOLD_PATH) .SetPassword("password") .ThenBuild(); wallet.Should().NotBeNull(); + + } [Fact] public void SecretManagerOptionShouldBeConfigurableByBuilder() { IWallet wallet = _serviceScope.ServiceProvider.GetRequiredService(); - string snapshotPath = "./snapshot"; string password = "password"; wallet = wallet .ConfigureSecretManagerOptions() - .SetSnapshotPath(snapshotPath) + .SetSnapshotPath(STRONGHOLD_PATH) .SetPassword(password) .ThenBuild(); SecretManagerOptions secretManagerOptions = wallet.GetWalletOptions().SecretManager; - secretManagerOptions.Stronghold.SnapshotPath.Equals(snapshotPath); + secretManagerOptions.Stronghold.SnapshotPath.Equals(STRONGHOLD_PATH); secretManagerOptions.Stronghold.Password.Equals(password); + } } } diff --git a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/WalletTest.cs b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/WalletTest.cs index 76cb63b..26f8154 100644 --- a/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/WalletTest.cs +++ b/csharp/IotaWalletNet/IotaWalletNet.Tests/Wallet/WalletTest.cs @@ -7,8 +7,10 @@ namespace IotaWalletNet.Tests.Wallet { + [Collection("Sequential")] public class WalletTest : DependencyTestBase { + [Fact] public void WalletShouldBeInitializedWithBasicConfigurations() { @@ -29,6 +31,8 @@ public void WalletShouldBeInitializedWithBasicConfigurations() .Invoking(w => w = w.ThenInitialize()) .Should() .NotThrow(); + + } [Fact] @@ -39,7 +43,7 @@ public void WalletShouldBeInitializedWithAdvancedConfigurations() wallet = wallet .ConfigureWalletOptions() .SetCoinType(WalletOptions.TypeOfCoin.Shimmer) - .SetStoragePath("./walletdb") + .SetStoragePath(DATABASE_PATH) .ThenBuild() .ConfigureClientOptions() .AddNodeUrl("https://api.testnet.shimmer.network") @@ -48,13 +52,15 @@ public void WalletShouldBeInitializedWithAdvancedConfigurations() .ThenBuild() .ConfigureSecretManagerOptions() .SetPassword("password") - .SetSnapshotPath("./mystronghold") + .SetSnapshotPath(STRONGHOLD_PATH) .ThenBuild(); wallet .Invoking(w => w = w.ThenInitialize()) .Should() .NotThrow(); + + } } }