-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
706aa9d
commit b832326
Showing
4 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Sequence.WaaS.Authentication; | ||
|
||
namespace Sequence.WaaS.Tests | ||
{ | ||
public class SessionManagementTests | ||
{ | ||
private WaaSWallet _wallet; | ||
|
||
public SessionManagementTests(WaaSWallet wallet) | ||
{ | ||
_wallet = wallet; | ||
} | ||
|
||
public async Task TestSessionManagement() | ||
{ | ||
try | ||
{ | ||
WaaSTestHarness.TestStarted?.Invoke(); | ||
WaaSSession[] sessions = await TestListSessions(); | ||
if (sessions == null) | ||
{ | ||
return; | ||
} | ||
|
||
await TestDropInactiveSession(sessions); | ||
|
||
await _wallet.DropThisSession(); | ||
} | ||
catch (Exception e) | ||
{ | ||
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(nameof(TestSessionManagement), e.Message)); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
WaaSSession[] sessions = await _wallet.ListSessions(); | ||
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(nameof(TestSessionManagement), "Expected an exception. Session was likely not dropped.")); | ||
} | ||
catch (Exception e) | ||
{ | ||
WaaSTestHarness.TestPassed?.Invoke(); | ||
} | ||
} | ||
|
||
private async Task<WaaSSession[]> TestListSessions() | ||
{ | ||
try | ||
{ | ||
WaaSSession[] sessions = await _wallet.ListSessions(); | ||
if (sessions == null || sessions.Length == 0) | ||
{ | ||
throw new Exception("No sessions found."); | ||
} | ||
|
||
return sessions; | ||
} | ||
catch (Exception e) | ||
{ | ||
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(nameof(TestListSessions), | ||
e.Message)); | ||
return null; | ||
} | ||
} | ||
|
||
private async Task TestDropInactiveSession(WaaSSession[] sessions) | ||
{ | ||
try | ||
{ | ||
int sessionCount = sessions.Length; | ||
for (int i = 0; i < sessionCount; i++) | ||
{ | ||
if (sessions[i].id != _wallet.SessionId) | ||
{ | ||
await _wallet.DropSession(sessions[i].id); | ||
break; | ||
} | ||
} | ||
|
||
if (sessionCount > 1) | ||
{ | ||
sessions = await TestListSessions(); | ||
int newSessionCount = sessions.Length; | ||
CustomAssert.IsTrue(newSessionCount == sessionCount - 1, nameof(TestSessionManagement)); | ||
} | ||
} | ||
catch(Exception e) | ||
{ | ||
WaaSTestHarness.TestFailed?.Invoke(new WaaSTestFailed(nameof(TestDropInactiveSession), e.Message)); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters