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

Commit 3eeeb32

Browse files
authored
Removed null check from Result.Resolve (#25)
1 parent 171f686 commit 3eeeb32

File tree

3 files changed

+48
-64
lines changed

3 files changed

+48
-64
lines changed

src/Core.Tests/DataLoaderTests.cs

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,34 +346,46 @@ await Assert.ThrowsAsync<InvalidOperationException>(verify)
346346
.ConfigureAwait(false);
347347
}
348348

349-
[InlineData(5, 25, 25, 1, true, true)]
350-
[InlineData(5, 25, 25, 0, true, true)]
351-
[InlineData(5, 25, 25, 0, true, false)]
352-
[InlineData(5, 25, 25, 0, false, true)]
353-
[InlineData(5, 25, 25, 0, false, false)]
354-
[InlineData(100, 1000, 25, 25, true, true)]
355-
[InlineData(100, 1000, 25, 0, true, true)]
356-
[InlineData(100, 1000, 25, 0, true, false)]
357-
[InlineData(100, 1000, 25, 0, false, true)]
358-
[InlineData(100, 1000, 25, 0, false, false)]
359-
[InlineData(1000, 100000, 15, 50, true, true)]
360-
[InlineData(1000, 100000, 15, 0, true, true)]
361-
[InlineData(1000, 100000, 15, 0, true, false)]
362-
[InlineData(1000, 100000, 15, 0, false, true)]
363-
[InlineData(1000, 100000, 15, 0, false, false)]
364-
[InlineData(1500, 10000, 20, 100, true, true)]
365-
[InlineData(1500, 10000, 20, 0, true, true)]
366-
[InlineData(1500, 10000, 20, 0, true, false)]
367-
[InlineData(1500, 10000, 20, 0, false, true)]
368-
[InlineData(1500, 10000, 20, 0, false, false)]
369-
[InlineData(3000, 100000, 10, 250, true, true)]
370-
[InlineData(3000, 100000, 10, 0, true, true)]
371-
[InlineData(3000, 100000, 10, 0, true, false)]
372-
[InlineData(3000, 100000, 10, 0, false, true)]
373-
[InlineData(3000, 100000, 10, 0, false, false)]
349+
[InlineData(5, 25, 25, 1, true, true, 0)]
350+
[InlineData(5, 25, 25, 0, true, true, 0)]
351+
[InlineData(5, 25, 25, 0, true, true, 25)]
352+
[InlineData(5, 25, 25, 0, true, false, 0)]
353+
[InlineData(5, 25, 25, 0, false, true, 0)]
354+
[InlineData(5, 25, 25, 0, false, false, 0)]
355+
[InlineData(100, 1000, 25, 25, true, true, 0)]
356+
[InlineData(100, 1000, 25, 0, true, true, 0)]
357+
[InlineData(100, 1000, 25, 0, true, true, 25)]
358+
[InlineData(100, 1000, 25, 0, true, false, 0)]
359+
[InlineData(100, 1000, 25, 0, false, true, 0)]
360+
[InlineData(100, 1000, 25, 0, false, false, 0)]
361+
[InlineData(1000, 100000, 15, 50, true, true, 0)]
362+
[InlineData(1000, 100000, 15, 0, true, true, 0)]
363+
[InlineData(1000, 100000, 15, 0, true, true, 25)]
364+
[InlineData(1000, 100000, 15, 0, true, false, 0)]
365+
[InlineData(1000, 100000, 15, 0, false, true, 0)]
366+
[InlineData(1000, 100000, 15, 0, false, false, 0)]
367+
[InlineData(1500, 10000, 20, 100, true, true, 0)]
368+
[InlineData(1500, 10000, 20, 0, true, true, 0)]
369+
[InlineData(1500, 10000, 20, 0, true, true, 25)]
370+
[InlineData(1500, 10000, 20, 0, true, false, 0)]
371+
[InlineData(1500, 10000, 20, 0, false, true, 0)]
372+
[InlineData(1500, 10000, 20, 0, false, false, 0)]
373+
[InlineData(3000, 100000, 10, 250, true, true, 0)]
374+
[InlineData(3000, 100000, 10, 0, true, true, 0)]
375+
[InlineData(3000, 100000, 10, 0, true, true, 25)]
376+
[InlineData(3000, 100000, 10, 0, true, false, 0)]
377+
[InlineData(3000, 100000, 10, 0, false, true, 0)]
378+
[InlineData(3000, 100000, 10, 0, false, false, 0)]
379+
[InlineData(10000, 1000000, 10, 100, true, true, 0)]
380+
[InlineData(10000, 1000000, 10, 0, true, true, 0)]
381+
[InlineData(10000, 1000000, 10, 100, true, true, 25)]
382+
[InlineData(10000, 1000000, 10, 0, true, false, 0)]
383+
[InlineData(10000, 1000000, 10, 100, false, true, 0)]
384+
[InlineData(10000, 1000000, 10, 0, false, false, 0)]
374385
[Theory(DisplayName = "LoadAsync: Runs integration tests with different settings")]
375386
public async Task LoadTest(int uniqueKeys, int maxRequests,
376-
int maxDelay, int maxBatchSize, bool caching, bool batching)
387+
int maxDelay, int maxBatchSize, bool caching, bool batching,
388+
int slidingExpirationInMilliseconds)
377389
{
378390
// arrange
379391
var random = new Random();
@@ -394,11 +406,15 @@ public async Task LoadTest(int uniqueKeys, int maxRequests,
394406

395407
return values;
396408
};
409+
TimeSpan slidingExpiration = (slidingExpirationInMilliseconds > 0)
410+
? TimeSpan.FromMilliseconds(slidingExpirationInMilliseconds)
411+
: TimeSpan.Zero;
397412
var options = new DataLoaderOptions<Guid>
398413
{
399414
Caching = caching,
400415
Batching = batching,
401-
MaxBatchSize = maxBatchSize
416+
MaxBatchSize = maxBatchSize,
417+
SlidingExpiration = slidingExpiration
402418
};
403419
var dataLoader = new DataLoader<Guid, int>(options, fetch);
404420
var keyArray = new Guid[uniqueKeys];

src/Core.Tests/ResultTests.cs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,19 @@ public void Reject()
5555

5656
#region Resolve
5757

58-
[Fact(DisplayName = "Resolve: Should throw an argument null exception for value")]
59-
public void ResolveValueNull()
58+
[InlineData(null)]
59+
[InlineData("Foo")]
60+
[Theory(DisplayName = "Resolve: Should return a resolved Result")]
61+
public void Resolve(string value)
6062
{
61-
// arrange
62-
string value = null;
63-
64-
// act
65-
Action verify = () => Result<string>.Resolve(value);
66-
67-
// assert
68-
Assert.Throws<ArgumentNullException>("value", verify);
69-
}
70-
71-
[Fact(DisplayName = "Resolve: Should not throw any exception")]
72-
public void ResolveValueNotNull()
73-
{
74-
// arrange
75-
string value = "Foo";
76-
77-
// act
78-
Action verify = () => Result<string>.Resolve(value);
79-
80-
// assert
81-
Assert.Null(Record.Exception(verify));
82-
}
83-
84-
[Fact(DisplayName = "Resolve: Should return a resolved Result")]
85-
public void Resolve()
86-
{
87-
// arrange
88-
string value = "Foo";
89-
9063
// act
9164
Result<string> result = Result<string>.Resolve(value);
9265

9366
// assert
9467
Assert.NotNull(result);
9568
Assert.Null(result.Error);
9669
Assert.False(result.IsError);
97-
Assert.Equal("Foo", result.Value);
70+
Assert.Equal(value, result.Value);
9871
}
9972

10073
#endregion

src/Core/Result.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ public static Result<TValue> Reject(Exception error)
5353
/// <returns>A value result.</returns>
5454
public static Result<TValue> Resolve(TValue value)
5555
{
56-
if (value == null)
57-
{
58-
throw new ArgumentNullException(nameof(value));
59-
}
60-
6156
var result = new Result<TValue>();
6257

6358
result.Value = value;

0 commit comments

Comments
 (0)