-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow controlling the disposal of provided transport and HTTP client …
…instances (#487) * Add parameter to control disposal of provided HTTP client when creating transport. * Add a parameter to control disposal of provided instance when creating DB client. * Simplify tests by using Mock instances.
- Loading branch information
Showing
5 changed files
with
206 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.Transport; | ||
using Moq; | ||
using Moq.Protected; | ||
using System.Net.Http; | ||
using Xunit; | ||
|
||
namespace ArangoDBNetStandardTest | ||
{ | ||
public class ArangoDBClientTest | ||
{ | ||
public ArangoDBClientTest() | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Dispose_ShouldDisposeTransport_WhenTransportDisposalIsNotSuppressed() | ||
{ | ||
var mockTransport = new Mock<IApiClientTransport>(); | ||
|
||
var dbClient = new ArangoDBClient( | ||
mockTransport.Object, | ||
suppressTransportDisposal: false); | ||
|
||
// Act | ||
dbClient.Dispose(); | ||
|
||
// Assert | ||
mockTransport.Verify(client => client.Dispose(), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public void Dispose_ShouldNotDisposeTransport_WhenTransportDisposalIsSuppressed() | ||
{ | ||
var mockTransport = new Mock<IApiClientTransport>(); | ||
|
||
var dbClient = new ArangoDBClient( | ||
mockTransport.Object, | ||
suppressTransportDisposal: true); | ||
|
||
// Act | ||
dbClient.Dispose(); | ||
|
||
// Assert | ||
mockTransport.Verify(transport => transport.Dispose(), Times.Never); | ||
} | ||
|
||
[Fact] | ||
public void Dispose_ShouldDisposeHttpClient_WhenClientDisposalIsNotSuppressed() | ||
{ | ||
var mockMessageHandler = new Mock<HttpMessageHandler>(); | ||
|
||
var httpClient = new HttpClient(mockMessageHandler.Object); | ||
|
||
var dbClient = new ArangoDBClient( | ||
httpClient, | ||
suppressClientDisposal: false); | ||
|
||
// Act | ||
dbClient.Dispose(); | ||
|
||
// Assert | ||
mockMessageHandler.Protected().Verify("Dispose", Times.Once(), true, true); | ||
} | ||
|
||
[Fact] | ||
public void Dispose_ShouldNotDisposeHttpClient_WhenClientDisposalIsSuppressed() | ||
{ | ||
var mockMessageHandler = new Mock<HttpMessageHandler>(); | ||
|
||
var httpClient = new HttpClient(mockMessageHandler.Object); | ||
|
||
var dbClient = new ArangoDBClient( | ||
httpClient, | ||
suppressClientDisposal: true); | ||
|
||
// Act | ||
dbClient.Dispose(); | ||
|
||
// Assert | ||
mockMessageHandler.Protected().Verify("Dispose", Times.Never(), true, true); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.