-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gai/opt-in-features
- Loading branch information
Showing
202 changed files
with
7,849 additions
and
2,420 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
56 changes: 56 additions & 0 deletions
56
...enDonut/test/Core.Tests/DependencyInjection/DataLoaderServiceCollectionExtensionsTests.cs
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,56 @@ | ||
using GreenDonut; | ||
using Xunit; | ||
using static GreenDonut.TestHelpers; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
public class DataLoaderServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void ImplFactoryIsCalledWhenServiceIsResolved() | ||
{ | ||
// arrange | ||
var factoryCalled = false; | ||
var fetch = CreateFetch<string, string>(); | ||
var services = new ServiceCollection() | ||
.AddScoped<IBatchScheduler, ManualBatchScheduler>() | ||
.AddDataLoader(sp => | ||
{ | ||
factoryCalled = true; | ||
return new DataLoader<string, string>(fetch, sp.GetRequiredService<IBatchScheduler>()); | ||
}); | ||
var scope = services.BuildServiceProvider().CreateScope(); | ||
|
||
// act | ||
var dataLoader = scope.ServiceProvider.GetRequiredService<DataLoader<string, string>>(); | ||
|
||
// assert | ||
Assert.NotNull(dataLoader); | ||
Assert.True(factoryCalled); | ||
} | ||
|
||
[Fact] | ||
public void InterfaceImplFactoryIsCalledWhenServiceIsResolved() | ||
{ | ||
// arrange | ||
var factoryCalled = false; | ||
var fetch = CreateFetch<string, string>(); | ||
var services = new ServiceCollection() | ||
.AddScoped<IBatchScheduler, ManualBatchScheduler>() | ||
.AddDataLoader<IDataLoader<string, string>, DataLoader<string, string>>(sp => | ||
{ | ||
factoryCalled = true; | ||
return new DataLoader<string, string>(fetch, sp.GetRequiredService<IBatchScheduler>()); | ||
}); | ||
var scope = services.BuildServiceProvider().CreateScope(); | ||
|
||
// act | ||
var dataLoader = scope.ServiceProvider.GetRequiredService<DataLoader<string, string>>(); | ||
var asInterface = scope.ServiceProvider.GetRequiredService<IDataLoader<string, string>>(); | ||
|
||
// assert | ||
Assert.NotNull(dataLoader); | ||
Assert.NotNull(asInterface); | ||
Assert.True(factoryCalled); | ||
} | ||
} |
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
Oops, something went wrong.