-
Notifications
You must be signed in to change notification settings - Fork 140
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
42e27b6
commit 771c7ae
Showing
8 changed files
with
198 additions
and
62 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
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
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
62 changes: 62 additions & 0 deletions
62
Snowflake.Data.Tests/UnitTests/Session/SessionOrCreationTokensTest.cs
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,62 @@ | ||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using Snowflake.Data.Core; | ||
using Snowflake.Data.Core.Session; | ||
|
||
namespace Snowflake.Data.Tests.UnitTests.Session | ||
{ | ||
[TestFixture] | ||
public class SessionOrCreationTokensTest | ||
{ | ||
private SFSession _session = new SFSession("account=test;user=test;password=test", null); | ||
|
||
[Test] | ||
public void TestNoBackgroundSessionsToCreateWhenInitialisedWithSession() | ||
{ | ||
// arrange | ||
var sessionOrTokens = new SessionOrCreationTokens(_session); | ||
|
||
// act | ||
var backgroundCreationTokens = sessionOrTokens.BackgroundSessionCreationTokens(); | ||
|
||
Assert.AreEqual(0, backgroundCreationTokens.Count); | ||
} | ||
|
||
[Test] | ||
public void TestReturnFirstCreationToken() | ||
{ | ||
// arrange | ||
var sessionCreationTokenCounter = new SessionCreationTokenCounter(TimeSpan.FromSeconds(10)); | ||
var tokens = Enumerable.Range(1, 3) | ||
.Select(_ => sessionCreationTokenCounter.NewToken()) | ||
.ToList(); | ||
var sessionOrTokens = new SessionOrCreationTokens(tokens); | ||
|
||
// act | ||
var token = sessionOrTokens.SessionCreationToken(); | ||
|
||
// assert | ||
Assert.AreSame(tokens[0], token); | ||
} | ||
|
||
[Test] | ||
public void TestReturnCreationTokensFromTheSecondOneForBackgroundExecution() | ||
{ | ||
// arrange | ||
var sessionCreationTokenCounter = new SessionCreationTokenCounter(TimeSpan.FromSeconds(10)); | ||
var tokens = Enumerable.Range(1, 3) | ||
.Select(_ => sessionCreationTokenCounter.NewToken()) | ||
.ToList(); | ||
var sessionOrTokens = new SessionOrCreationTokens(tokens); | ||
|
||
// act | ||
var backgroundTokens = sessionOrTokens.BackgroundSessionCreationTokens(); | ||
|
||
// assert | ||
Assert.AreEqual(2, backgroundTokens.Count); | ||
Assert.AreSame(tokens[1], backgroundTokens[0]); | ||
Assert.AreSame(tokens[2], backgroundTokens[1]); | ||
} | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Snowflake.Data.Core.Session | ||
{ | ||
internal class SessionOrCreationTokens | ||
{ | ||
private static readonly List<SessionCreationToken> s_emptySessionCreationTokenList = new List<SessionCreationToken>(); | ||
|
||
public SFSession Session { get; } | ||
public List<SessionCreationToken> SessionCreationTokens { get; } | ||
|
||
public SessionOrCreationTokens(SFSession session) | ||
{ | ||
Session = session ?? throw new Exception("Internal error: missing session"); | ||
SessionCreationTokens = s_emptySessionCreationTokenList; | ||
} | ||
|
||
public SessionOrCreationTokens(List<SessionCreationToken> sessionCreationTokens) | ||
{ | ||
Session = null; | ||
if (sessionCreationTokens == null || sessionCreationTokens.Count == 0) | ||
{ | ||
throw new Exception("Internal error: missing session creation token"); | ||
} | ||
SessionCreationTokens = sessionCreationTokens; | ||
} | ||
|
||
public List<SessionCreationToken> BackgroundSessionCreationTokens() | ||
{ | ||
if (Session == null) | ||
{ | ||
return SessionCreationTokens.Skip(1).ToList(); | ||
} | ||
return SessionCreationTokens; | ||
} | ||
|
||
public SessionCreationToken SessionCreationToken() => SessionCreationTokens.First(); | ||
} | ||
} |
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