This repository was archived by the owner on Sep 5, 2019. It is now read-only.
-
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.
Added tests and improved some internals (#26)
* Used TaskCreationOptions.RunContinuationsAsynchronously for most situations * Improved code documentation for DataLoader * Added package tags * Changed package project url * Wrote tests and put default values into one file
- Loading branch information
Showing
14 changed files
with
193 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using GreenDonut.FakeDataLoaders; | ||
using Xunit; | ||
|
||
namespace GreenDonut | ||
{ | ||
public class DataLoaderBaseTests | ||
{ | ||
#region Constructor() | ||
|
||
[Fact(DisplayName = "Constructor: Should not throw any exception")] | ||
public void ConstructorA() | ||
{ | ||
// arrange | ||
FetchDataDelegate<string, string> fetch = async keys => | ||
await Task.FromResult(new Result<string>[0]) | ||
.ConfigureAwait(false); | ||
|
||
// act | ||
Action verify = () => new EmptyConstructor(); | ||
|
||
// assert | ||
Assert.Null(Record.Exception(verify)); | ||
} | ||
|
||
#endregion | ||
|
||
#region Constructor(cache) | ||
|
||
[Fact(DisplayName = "Constructor: Should throw an argument null exception for cache")] | ||
public void ConstructorBCacheNull() | ||
{ | ||
// arrange | ||
TaskCache<string, string> cache = null; | ||
|
||
// act | ||
Action verify = () => new CacheConstructor(cache); | ||
|
||
// assert | ||
Assert.Throws<ArgumentNullException>("cache", verify); | ||
} | ||
|
||
[Fact(DisplayName = "Constructor: Should not throw any exception")] | ||
public void ConstructorBNoException() | ||
{ | ||
// arrange | ||
var cache = new TaskCache<string, string>(10, TimeSpan.Zero); | ||
|
||
// act | ||
Action verify = () => new CacheConstructor(cache); | ||
|
||
// assert | ||
Assert.Null(Record.Exception(verify)); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace GreenDonut.FakeDataLoaders | ||
{ | ||
internal class CacheConstructor | ||
: DataLoaderBase<string, string> | ||
{ | ||
internal CacheConstructor(TaskCache<string, string> cache) | ||
: base(cache) | ||
{ } | ||
|
||
protected override Task<IReadOnlyList<Result<string>>> Fetch( | ||
IReadOnlyList<string> keys) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace GreenDonut.FakeDataLoaders | ||
{ | ||
internal class EmptyConstructor | ||
: DataLoaderBase<string, string> | ||
{ | ||
internal EmptyConstructor() | ||
: base() | ||
{ } | ||
|
||
protected override Task<IReadOnlyList<Result<string>>> Fetch( | ||
IReadOnlyList<string> keys) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace GreenDonut | ||
{ | ||
internal static class Defaults | ||
{ | ||
public static readonly int CacheSize = 1000; | ||
public static readonly TimeSpan BatchRequestDelay = TimeSpan | ||
.FromMilliseconds(50); | ||
public static readonly int MinimumCacheSize = 10; | ||
public static readonly TimeSpan SlidingExpiration = TimeSpan.Zero; | ||
} | ||
} |
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