-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for non-static usage of ServiceProvider
Allow static BinanceHttpClient singleton initializer to be reset and add new tests for @tash649 use case.
- Loading branch information
Showing
4 changed files
with
57 additions
and
10 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
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,45 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Binance.Tests | ||
{ | ||
[Collection("Binance HTTP Client Tests")] | ||
public class DependencyInjectionTests | ||
{ | ||
[Fact] | ||
public Task ServiceProviderDispose() | ||
{ | ||
var serviceProvider = new ServiceCollection() | ||
.AddBinance().BuildServiceProvider(); | ||
|
||
var httpClient = serviceProvider.GetService<IBinanceHttpClient>(); | ||
|
||
serviceProvider.Dispose(); | ||
|
||
// Verify static BinanceHttpClient singleton is disposed. | ||
return Assert.ThrowsAsync<ObjectDisposedException>(() => httpClient.GetAsync("test")); | ||
} | ||
|
||
[Fact] | ||
public void NonStaticServiceProviderUse() | ||
{ | ||
var serviceProvider = new ServiceCollection() | ||
.AddBinance().BuildServiceProvider(); | ||
|
||
var httpClient = serviceProvider.GetService<IBinanceHttpClient>(); | ||
|
||
serviceProvider.Dispose(); | ||
|
||
|
||
serviceProvider = new ServiceCollection() | ||
.AddBinance().BuildServiceProvider(); | ||
|
||
httpClient = serviceProvider.GetService<IBinanceHttpClient>(); | ||
|
||
// Verify the RateLimiter is not disposed (no exception is thrown). | ||
httpClient.RateLimiter.Configure(TimeSpan.FromSeconds(1), 1); | ||
} | ||
} | ||
} |