Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Removed null check from Result.Resolve (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
rstaib authored Sep 27, 2018
1 parent 171f686 commit 3eeeb32
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 64 deletions.
70 changes: 43 additions & 27 deletions src/Core.Tests/DataLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,34 +346,46 @@ await Assert.ThrowsAsync<InvalidOperationException>(verify)
.ConfigureAwait(false);
}

[InlineData(5, 25, 25, 1, true, true)]
[InlineData(5, 25, 25, 0, true, true)]
[InlineData(5, 25, 25, 0, true, false)]
[InlineData(5, 25, 25, 0, false, true)]
[InlineData(5, 25, 25, 0, false, false)]
[InlineData(100, 1000, 25, 25, true, true)]
[InlineData(100, 1000, 25, 0, true, true)]
[InlineData(100, 1000, 25, 0, true, false)]
[InlineData(100, 1000, 25, 0, false, true)]
[InlineData(100, 1000, 25, 0, false, false)]
[InlineData(1000, 100000, 15, 50, true, true)]
[InlineData(1000, 100000, 15, 0, true, true)]
[InlineData(1000, 100000, 15, 0, true, false)]
[InlineData(1000, 100000, 15, 0, false, true)]
[InlineData(1000, 100000, 15, 0, false, false)]
[InlineData(1500, 10000, 20, 100, true, true)]
[InlineData(1500, 10000, 20, 0, true, true)]
[InlineData(1500, 10000, 20, 0, true, false)]
[InlineData(1500, 10000, 20, 0, false, true)]
[InlineData(1500, 10000, 20, 0, false, false)]
[InlineData(3000, 100000, 10, 250, true, true)]
[InlineData(3000, 100000, 10, 0, true, true)]
[InlineData(3000, 100000, 10, 0, true, false)]
[InlineData(3000, 100000, 10, 0, false, true)]
[InlineData(3000, 100000, 10, 0, false, false)]
[InlineData(5, 25, 25, 1, true, true, 0)]
[InlineData(5, 25, 25, 0, true, true, 0)]
[InlineData(5, 25, 25, 0, true, true, 25)]
[InlineData(5, 25, 25, 0, true, false, 0)]
[InlineData(5, 25, 25, 0, false, true, 0)]
[InlineData(5, 25, 25, 0, false, false, 0)]
[InlineData(100, 1000, 25, 25, true, true, 0)]
[InlineData(100, 1000, 25, 0, true, true, 0)]
[InlineData(100, 1000, 25, 0, true, true, 25)]
[InlineData(100, 1000, 25, 0, true, false, 0)]
[InlineData(100, 1000, 25, 0, false, true, 0)]
[InlineData(100, 1000, 25, 0, false, false, 0)]
[InlineData(1000, 100000, 15, 50, true, true, 0)]
[InlineData(1000, 100000, 15, 0, true, true, 0)]
[InlineData(1000, 100000, 15, 0, true, true, 25)]
[InlineData(1000, 100000, 15, 0, true, false, 0)]
[InlineData(1000, 100000, 15, 0, false, true, 0)]
[InlineData(1000, 100000, 15, 0, false, false, 0)]
[InlineData(1500, 10000, 20, 100, true, true, 0)]
[InlineData(1500, 10000, 20, 0, true, true, 0)]
[InlineData(1500, 10000, 20, 0, true, true, 25)]
[InlineData(1500, 10000, 20, 0, true, false, 0)]
[InlineData(1500, 10000, 20, 0, false, true, 0)]
[InlineData(1500, 10000, 20, 0, false, false, 0)]
[InlineData(3000, 100000, 10, 250, true, true, 0)]
[InlineData(3000, 100000, 10, 0, true, true, 0)]
[InlineData(3000, 100000, 10, 0, true, true, 25)]
[InlineData(3000, 100000, 10, 0, true, false, 0)]
[InlineData(3000, 100000, 10, 0, false, true, 0)]
[InlineData(3000, 100000, 10, 0, false, false, 0)]
[InlineData(10000, 1000000, 10, 100, true, true, 0)]
[InlineData(10000, 1000000, 10, 0, true, true, 0)]
[InlineData(10000, 1000000, 10, 100, true, true, 25)]
[InlineData(10000, 1000000, 10, 0, true, false, 0)]
[InlineData(10000, 1000000, 10, 100, false, true, 0)]
[InlineData(10000, 1000000, 10, 0, false, false, 0)]
[Theory(DisplayName = "LoadAsync: Runs integration tests with different settings")]
public async Task LoadTest(int uniqueKeys, int maxRequests,
int maxDelay, int maxBatchSize, bool caching, bool batching)
int maxDelay, int maxBatchSize, bool caching, bool batching,
int slidingExpirationInMilliseconds)
{
// arrange
var random = new Random();
Expand All @@ -394,11 +406,15 @@ public async Task LoadTest(int uniqueKeys, int maxRequests,

return values;
};
TimeSpan slidingExpiration = (slidingExpirationInMilliseconds > 0)
? TimeSpan.FromMilliseconds(slidingExpirationInMilliseconds)
: TimeSpan.Zero;
var options = new DataLoaderOptions<Guid>
{
Caching = caching,
Batching = batching,
MaxBatchSize = maxBatchSize
MaxBatchSize = maxBatchSize,
SlidingExpiration = slidingExpiration
};
var dataLoader = new DataLoader<Guid, int>(options, fetch);
var keyArray = new Guid[uniqueKeys];
Expand Down
37 changes: 5 additions & 32 deletions src/Core.Tests/ResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,19 @@ public void Reject()

#region Resolve

[Fact(DisplayName = "Resolve: Should throw an argument null exception for value")]
public void ResolveValueNull()
[InlineData(null)]
[InlineData("Foo")]
[Theory(DisplayName = "Resolve: Should return a resolved Result")]
public void Resolve(string value)
{
// arrange
string value = null;

// act
Action verify = () => Result<string>.Resolve(value);

// assert
Assert.Throws<ArgumentNullException>("value", verify);
}

[Fact(DisplayName = "Resolve: Should not throw any exception")]
public void ResolveValueNotNull()
{
// arrange
string value = "Foo";

// act
Action verify = () => Result<string>.Resolve(value);

// assert
Assert.Null(Record.Exception(verify));
}

[Fact(DisplayName = "Resolve: Should return a resolved Result")]
public void Resolve()
{
// arrange
string value = "Foo";

// act
Result<string> result = Result<string>.Resolve(value);

// assert
Assert.NotNull(result);
Assert.Null(result.Error);
Assert.False(result.IsError);
Assert.Equal("Foo", result.Value);
Assert.Equal(value, result.Value);
}

#endregion
Expand Down
5 changes: 0 additions & 5 deletions src/Core/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public static Result<TValue> Reject(Exception error)
/// <returns>A value result.</returns>
public static Result<TValue> Resolve(TValue value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

var result = new Result<TValue>();

result.Value = value;
Expand Down

0 comments on commit 3eeeb32

Please sign in to comment.