-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use client test fixture to speedup tests (#81)
This PR introduces a client test fixture. The previous tests instantiated the client in test class constructors. That is, we used this pattern: ```csharp public class MyTests { public MyTests() { // Instantiate some things } public void Test_Something() { // tests } public void Test_Otherthing() { // tests } } ``` Data instantiated in the constructor will be setup and torn down for *each* test method, not just for the class as a whole. This is not the same thing `setUp` from jUnit. In Fixtures.cs we create a client fixture and register it to be available across all test classes. Other tests modified appropriately.
- Loading branch information
Showing
4 changed files
with
159 additions
and
132 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,46 @@ | ||
namespace MomentoIntegrationTest | ||
{ | ||
/// <summary> | ||
/// A cache client fixture. | ||
/// Use this when not testing client-building edge cases: | ||
/// re-using the client drops overall integration test time down ~5X. | ||
/// </summary> | ||
public class SimpleCacheClientFixture : IDisposable | ||
{ | ||
public SimpleCacheClient Client { get; private set; } | ||
public string AuthToken { get; private set; } | ||
|
||
public const string CacheName = "client-sdk-csharp"; | ||
public const uint DefaultTtlSeconds = 10; | ||
|
||
public SimpleCacheClientFixture() | ||
{ | ||
AuthToken = Environment.GetEnvironmentVariable("TEST_AUTH_TOKEN") ?? | ||
throw new NullReferenceException("TEST_AUTH_TOKEN environment variable must be set."); | ||
Client = new(AuthToken, defaultTtlSeconds: DefaultTtlSeconds); | ||
|
||
try | ||
{ | ||
Client.CreateCache(CacheName); | ||
} | ||
catch (AlreadyExistsException) | ||
{ | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Client.DeleteCache(CacheName); | ||
Client.Dispose(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Register the fixture in xUnit. | ||
/// </summary> | ||
[CollectionDefinition("SimpleCacheClient")] | ||
public class SimpleCacheClientCollection : ICollectionFixture<SimpleCacheClientFixture> | ||
{ | ||
|
||
} | ||
} |
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
Oops, something went wrong.