Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #194 from srottem/feature/dotnet_test_fixes
Browse files Browse the repository at this point in the history
Feature/dotnet test fixes
  • Loading branch information
Vyacheslav authored Aug 17, 2017
2 parents 7fcfdcf + 75c6803 commit 07e7ce3
Show file tree
Hide file tree
Showing 48 changed files with 728 additions and 771 deletions.
10 changes: 3 additions & 7 deletions wrappers/dotnet/indy-sdk-dotnet-test/IndyIntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public abstract class IndyIntegrationTestBase
protected HashSet<Pool> _openedPools = new HashSet<Pool>();

[TestInitialize]
public void SetUp()
public async Task SetUp()
{
InitHelper.Init();
await InitHelper.InitAsync();
StorageUtils.CleanupStorage();
}

Expand All @@ -22,12 +22,8 @@ public async Task TearDown()
{
foreach (var pool in _openedPools)
{
try
{
if(pool != null)
await pool.CloseAsync();
}
catch (IndyException)
{ }
}

_openedPools.Clear();
Expand Down
8 changes: 4 additions & 4 deletions wrappers/dotnet/indy-sdk-dotnet-test/InitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class InitHelper
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);

public static void Init()
public static async Task InitAsync()
{
if (_isInitialized)
return;

LoadIndyDll();
RegisterWalletType();
await RegisterWalletTypeAsync();

_isInitialized = true;
}
Expand All @@ -34,9 +34,9 @@ private static void LoadIndyDll()
SetDllDirectory(dir);
}

private static void RegisterWalletType()
private static async Task RegisterWalletTypeAsync()
{
Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType()).Wait();
await Wallet.RegisterWalletTypeAsync("inmem", new InMemWalletType());
}
}
}
6 changes: 3 additions & 3 deletions wrappers/dotnet/indy-sdk-dotnet-test/PoolUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public static void CreatePoolLedgerConfig(string poolName, int nodesCnt)
var path = Path.GetFullPath(genesisTxnFile).Replace('\\', '/');
var createPoolLedgerConfig = string.Format("{{\"genesis_txn\":\"{0}\"}}", path);

Pool.CreatePoolLedgerConfigAsync(poolName, createPoolLedgerConfig).Wait();
Pool.CreatePoolLedgerConfigAsync(poolName, createPoolLedgerConfig);
}

public static Pool CreateAndOpenPoolLedger()
public static async Task<Pool> CreateAndOpenPoolLedgerAsync()
{
var poolName = PoolUtils.CreatePoolLedgerConfig();
var openPoolLedgerConfig = "{\"refreshOnOpen\":true}";

return Pool.OpenPoolLedgerAsync(poolName, openPoolLedgerConfig).Result;
return await Pool.OpenPoolLedgerAsync(poolName, openPoolLedgerConfig);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
using Indy.Sdk.Dotnet.Test.Wrapper.AgentTests;
using Indy.Sdk.Dotnet.Wrapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;

namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests
{
[TestClass]
public class AgentAddIdentityTest : AgentIntegrationTestBase
{
[TestMethod]
public void TestAgentAddIdentityWorks()
public async Task TestAgentAddIdentityWorks()
{
var endpoint = "127.0.0.1:9601";

var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);
}

[TestMethod]
public void TestAgentAddIdentityWorksForMultiplyKeys()
public async Task TestAgentAddIdentityWorksForMultiplyKeys()
{
var endpoint = "127.0.0.1:9602";

var myDid1 = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDid2 = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDid1 = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");
var myDid2 = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

CreateAndStoreMyDidResult[] didResults = { myDid1, myDid2 };

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

foreach (var didResult in didResults)
{
activeListener.AddIdentityAsync(_pool, _wallet, didResult.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, didResult.Did);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ public async Task TestAgentCloseConnectionWorksForOutgoing()
{
var endpoint = "127.0.0.1:9603";

var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

Signus.StoreTheirDidAsync(_wallet, identityJson).Wait();
await Signus.StoreTheirDidAsync(_wallet, identityJson);

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did);

var connection = Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Result;
var connection = await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver);

connection.CloseAsync().Wait();
await connection.CloseAsync();

var ex = await Assert.ThrowsExceptionAsync<IndyException>(() =>
connection.SendAsync("msg")
Expand All @@ -58,21 +58,21 @@ public async Task TestAgentCloseConnectionWorksForIncoming()
{
var endpoint = "127.0.0.1:9613";

var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

Signus.StoreTheirDidAsync(_wallet, identityJson).Wait();
await Signus.StoreTheirDidAsync(_wallet, identityJson);

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did);

var connection = Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Result;
var connection = await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver);

var serverToClientConnection = _serverToClientConnectionTaskCompletionSource.Task.Result;
serverToClientConnection.CloseAsync().Wait();
var serverToClientConnection = await _serverToClientConnectionTaskCompletionSource.Task;
await serverToClientConnection.CloseAsync();


var ex = await Assert.ThrowsExceptionAsync<IndyException>(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public async Task TestAgentCloseConnectionWorksForOutgoing()
{
var endpoint = "127.0.0.1:9604";

var myDid = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDid = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
myDid.Did, myDid.Pk, myDid.VerKey, endpoint);

Signus.StoreTheirDidAsync(_wallet, identityJson).Wait();
await Signus.StoreTheirDidAsync(_wallet, identityJson);

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, myDid.Did);

Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver).Wait();
await Agent.AgentConnectAsync(_pool, _wallet, myDid.Did, myDid.Did, _messageObserver);

var serverToClientConnection = _serverToClientConnectionTaskCompletionSource.Task.Result;
activeListener.CloseAsync().Wait();
var serverToClientConnection = await _serverToClientConnectionTaskCompletionSource.Task;
await activeListener.CloseAsync();

var ex = await Assert.ThrowsExceptionAsync<IndyException>(() =>
serverToClientConnection.SendAsync("msg")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
using Indy.Sdk.Dotnet.Wrapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;

namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests
{
[TestClass]
public class AgentConnectTest : AgentIntegrationTestBase
{
[TestMethod]
public void TestAgentConnectWorksForRemoteData()
public async Task TestAgentConnectWorksForRemoteData()
{
var endpoint = "127.0.0.1:9605";
var listenerWalletName = "listenerWallet";
var trusteeWalletName = "trusteeWallet";

Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null).Wait();
var listenerWallet = Wallet.OpenWalletAsync(listenerWalletName, null, null).Result;
await Wallet.CreateWalletAsync(_poolName, listenerWalletName, "default", null, null);
var listenerWallet = await Wallet.OpenWalletAsync(listenerWalletName, null, null);

Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null).Wait();
var trusteeWallet = Wallet.OpenWalletAsync(trusteeWalletName, null, null).Result;
await Wallet.CreateWalletAsync(_poolName, trusteeWalletName, "default", null, null);
var trusteeWallet = await Wallet.OpenWalletAsync(trusteeWalletName, null, null);
var senderWallet = trusteeWallet;

var createMyDidResult = Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}").Result;
var createMyDidResult = await Signus.CreateAndStoreMyDidAsync(listenerWallet, "{}");
var listenerDid = createMyDidResult.Did;
var listenerVerkey = createMyDidResult.VerKey;
var listenerPk = createMyDidResult.Pk;

var trusteeDidJson = "{\"seed\":\"000000000000000000000000Trustee1\"}";

var trusteeDidResult = Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson).Result;
var trusteeDidResult = await Signus.CreateAndStoreMyDidAsync(trusteeWallet, trusteeDidJson);
var trusteeDid = trusteeDidResult.Did;
var senderDid = trusteeDid;

var nymRequest = Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null).Result;
Ledger.SignAndSubmitRequestAsync(_pool, trusteeWallet, trusteeDid, nymRequest).Wait();
var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, listenerDid, listenerVerkey, null, null);
await Ledger.SignAndSubmitRequestAsync(_pool, trusteeWallet, trusteeDid, nymRequest);

var attribRequest = Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null,
string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null).Result;
Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest).Wait();
var attribRequest = await Ledger.BuildAttribRequestAsync(listenerDid, listenerDid, null,
string.Format("{{\"endpoint\":{{\"ha\":\"{0}\",\"verkey\":\"{1}\"}}}}", endpoint, listenerPk), null);
await Ledger.SignAndSubmitRequestAsync(_pool, listenerWallet, listenerDid, attribRequest);

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid).Wait();
await activeListener.AddIdentityAsync(_pool, listenerWallet, listenerDid);

Agent.AgentConnectAsync(_pool, senderWallet, senderDid, listenerDid, _messageObserver).Wait();
await Agent.AgentConnectAsync(_pool, senderWallet, senderDid, listenerDid, _messageObserver);

listenerWallet.CloseAsync().Wait();
Wallet.DeleteWalletAsync(listenerWalletName, null).Wait();
await listenerWallet.CloseAsync();
await Wallet.DeleteWalletAsync(listenerWalletName, null);

trusteeWallet.CloseAsync().Wait();
Wallet.DeleteWalletAsync(trusteeWalletName, null).Wait();
await trusteeWallet.CloseAsync();
await Wallet.DeleteWalletAsync(trusteeWalletName, null);
}

[TestMethod]
public void TestAgentConnectWorksForAllDataInWalletPresent()
public async Task TestAgentConnectWorksForAllDataInWalletPresent()
{
var endpoint = "127.0.0.1:9606";

var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, "{}").Result;
var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, "{}");

var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
Signus.StoreTheirDidAsync(_wallet, identityJson).Wait();
await Signus.StoreTheirDidAsync(_wallet, identityJson);

var activeListener = Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Result;
var activeListener = await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);

activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did).Wait();
await activeListener.AddIdentityAsync(_pool, _wallet, myDidResult.Did);

Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver).Wait();
await Agent.AgentConnectAsync(_pool, _wallet, myDidResult.Did, myDidResult.Did, _messageObserver);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Indy.Sdk.Dotnet.Wrapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;
using static Indy.Sdk.Dotnet.Wrapper.Agent;

namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests
Expand Down Expand Up @@ -30,30 +31,30 @@ public abstract class AgentIntegrationTestBase
};

[TestInitialize]
public void SetUp()
public async Task SetUp()
{
InitHelper.Init();
await InitHelper.InitAsync();
StorageUtils.CleanupStorage();

_poolName = PoolUtils.CreatePoolLedgerConfig();

var config2 = "{}";
_pool = Pool.OpenPoolLedgerAsync(_poolName, config2).Result;
_pool = await Pool.OpenPoolLedgerAsync(_poolName, config2);

Wallet.CreateWalletAsync(_poolName, _walletName, "default", null, null).Wait();
_wallet = Wallet.OpenWalletAsync(_walletName, null, null).Result;
await Wallet.CreateWalletAsync(_poolName, _walletName, "default", null, null);
_wallet = await Wallet.OpenWalletAsync(_walletName, null, null);
}

[TestCleanup]
public void TearDown()
public async Task TearDown()
{
if(_wallet != null)
_wallet.CloseAsync().Wait();
await _wallet.CloseAsync();

Wallet.DeleteWalletAsync(_walletName, null).Wait();
await Wallet.DeleteWalletAsync(_walletName, null);

if(_pool != null)
_pool.CloseAsync().Wait();
await _pool.CloseAsync();

StorageUtils.CleanupStorage();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
using Indy.Sdk.Dotnet.Wrapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;

namespace Indy.Sdk.Dotnet.Test.Wrapper.AgentTests
{
[TestClass]
public class AgentListenTest : AgentIntegrationTestBase
{
[TestMethod]
public void TestAgentListenWorks()
public async Task TestAgentListenWorks()
{
var endpoint = "127.0.0.1:9607";

var didJson = "{\"seed\":\"sovrin_agent_connect_works_for_a\"}";

var myDidResult = Signus.CreateAndStoreMyDidAsync(_wallet, didJson).Result;
var myDidResult = await Signus.CreateAndStoreMyDidAsync(_wallet, didJson);

var identityJson = string.Format("{{\"did\":\"{0}\", \"pk\":\"{1}\", \"verkey\":\"{2}\", \"endpoint\":\"{3}\"}}",
myDidResult.Did, myDidResult.Pk, myDidResult.VerKey, endpoint);
Signus.StoreTheirDidAsync(_wallet, identityJson).Wait();
await Signus.StoreTheirDidAsync(_wallet, identityJson);

Agent.AgentListenAsync(endpoint, _incomingConnectionObserver).Wait();
await Agent.AgentListenAsync(endpoint, _incomingConnectionObserver);
}
}
}
Loading

0 comments on commit 07e7ce3

Please sign in to comment.