-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Timeout - Task Cancelled Exception / OperationCancelled Ex. (#184)
- Loading branch information
1 parent
a0b6fbf
commit 9345754
Showing
3 changed files
with
114 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Collections.Generic; | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
using System.IO; | ||
|
||
using System.Net.Http; | ||
|
||
using System.Threading; | ||
|
||
using System.Threading.Tasks; | ||
|
||
using Moq; | ||
|
||
using Moq.Protected; | ||
|
||
using NUnit.Framework; | ||
|
||
|
||
|
||
|
||
namespace NugetUtility.Tests | ||
|
||
{ | ||
|
||
[ExcludeFromCodeCoverage] | ||
|
||
[TestFixture] | ||
|
||
public class MoqMethodTests | ||
|
||
{ | ||
|
||
private string _projectPath = @"../../../"; | ||
|
||
[TestCase("BenchmarkDotNet", "0.12.1", "https://dummy.com/test", "MIT")] | ||
|
||
[Test] | ||
|
||
public async Task ExportLicenseTextMoqHttpResponse_Timeout(string packageName, string packageVersion, string licenseUrl, string licenseType) | ||
|
||
{ | ||
|
||
var mockMessageHandler = new Mock<HttpMessageHandler>(); | ||
|
||
mockMessageHandler.Protected().Setup<Task<HttpResponseMessage>>("SendAsync",ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()).ThrowsAsync(new TaskCanceledException("Timeout Exception")); | ||
|
||
|
||
|
||
|
||
var methods = new Methods(new PackageOptions | ||
|
||
{ | ||
|
||
ProjectDirectory = _projectPath, | ||
|
||
Timeout = 2, | ||
|
||
ExportLicenseTexts = true, | ||
|
||
},new HttpClient(mockMessageHandler.Object)); | ||
|
||
|
||
|
||
|
||
List<LibraryInfo> infos = new List<LibraryInfo>(); | ||
|
||
infos.Add(new LibraryInfo() | ||
|
||
{ | ||
|
||
PackageName = packageName, | ||
|
||
PackageVersion = packageVersion, | ||
|
||
LicenseUrl = licenseUrl, | ||
|
||
LicenseType = licenseType, | ||
|
||
}); | ||
|
||
await methods.ExportLicenseTexts(infos); | ||
|
||
var directory = methods.GetExportDirectory(); | ||
|
||
var outpath = Path.Combine(directory, packageName + "_" + packageVersion + ".txt"); | ||
|
||
var outpathhtml = Path.Combine(directory, packageName + "_" + packageVersion + ".html"); | ||
|
||
// file not generated | ||
|
||
Assert.That(!File.Exists(outpath) || !File.Exists(outpathhtml)); | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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