Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/GreenDonut/src/GreenDonut/BatchDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static void CopyResults(
}
else
{
results[i] = null;
results[i] = Result<TValue?>.Resolve(default);
}
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ private static void CopyResults(
}
else
{
results[i] = null;
results[i] = Result<TValue?>.Resolve(default);
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,44 @@
Assert.Equal(1, dataLoader.ExecutionCount);
}

[Fact]
public async Task BatchDataLoader_MissingKey_Should_Be_ResultResolveDefault()
{
// arrange
var loader = new TestBatchLoader();
var keys = new[] { 1, 2 };
var results = new Result<string?>[2];

// act
await loader.FetchAsync(keys, results, default, CancellationToken.None);

Assert.Equal("one", results[0].Value);
Assert.Equal(ResultKind.Value, results[0].Kind);

// assert
Assert.Null(results[1].Value);
Assert.Equal(ResultKind.Value, results[1].Kind);
}

[Fact]
public async Task StatefulBatchDataLoader_MissingKey_Should_Be_ResultResolveDefault()
{
// arrange
var loader = new TestStatefulBatchLoader();
var keys = new[] { 1, 2 };
var results = new Result<string?>[2];

// act
await loader.FetchAsync(keys, results, default, CancellationToken.None);

Assert.Equal("one", results[0].Value);
Assert.Equal(ResultKind.Value, results[0].Kind);

// assert
Assert.Null(results[1].Value);
Assert.Equal(ResultKind.Value, results[1].Kind);
}

[Fact]
public async Task Null_Result()
{
Expand Down Expand Up @@ -114,6 +152,35 @@
}
}

public class TestBatchLoader : BatchDataLoader<int, string>
{
public TestBatchLoader()
: base(new TestBatchScheduler(), new DataLoaderOptions()) { }

Check failure on line 158 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run GreenDonut.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 158 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run GreenDonut.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 158 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run HotChocolate.ApolloFederation.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 158 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run HotChocolate.ApolloFederation.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

protected override Task<IReadOnlyDictionary<int, string>> LoadBatchAsync(
IReadOnlyList<int> keys,
CancellationToken cancellationToken)
{
return Task.FromResult<IReadOnlyDictionary<int, string>>(
new Dictionary<int, string> { { 1, "one" } });
}
}

public class TestStatefulBatchLoader : StatefulBatchDataLoader<int, string>
{
public TestStatefulBatchLoader()
: base(new TestBatchScheduler(), new DataLoaderOptions()) { }

Check failure on line 172 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run GreenDonut.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 172 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run GreenDonut.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 172 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run HotChocolate.ApolloFederation.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 172 in src/GreenDonut/test/GreenDonut.Tests/BatchDataLoaderTests.cs

View workflow job for this annotation

GitHub Actions / Run HotChocolate.ApolloFederation.Tests

The type or namespace name 'TestBatchScheduler' could not be found (are you missing a using directive or an assembly reference?)

protected override Task<IReadOnlyDictionary<int, string>> LoadBatchAsync(
IReadOnlyList<int> keys,
DataLoaderFetchContext<string> context,
CancellationToken cancellationToken)
{
return Task.FromResult<IReadOnlyDictionary<int, string>>(
new Dictionary<int, string> { { 1, "one" } });
}
}

public sealed class InstantDispatcher : IBatchScheduler
{
public void Schedule(Batch batch)
Expand Down
Loading