-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,849 additions
and
1,822 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
using System.Net; | ||
|
||
namespace Downloader.DummyHttpServer | ||
namespace Downloader.DummyHttpServer; | ||
|
||
public class DummyApiException : WebException | ||
{ | ||
public class DummyApiException : WebException | ||
public DummyApiException(string message) | ||
: base(message, WebExceptionStatus.Timeout) | ||
{ | ||
public DummyApiException(string message) | ||
: base(message, WebExceptionStatus.Timeout) | ||
{ | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Downloader.DummyHttpServer/DummyApiExceptionFilterAttribute.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,21 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using System.Net; | ||
using static System.Console; | ||
|
||
namespace Downloader.DummyHttpServer; | ||
|
||
public class DummyApiExceptionFilterAttribute : ExceptionFilterAttribute | ||
{ | ||
public override void OnException(ExceptionContext context) | ||
{ | ||
if (context.Exception is DummyApiException) | ||
{ | ||
context.Result = new StatusCodeResult((int)HttpStatusCode.RequestedRangeNotSatisfiable); | ||
} | ||
else | ||
{ | ||
WriteLine($"Exception on {context.ActionDescriptor.DisplayName}: {context.Exception.Message}"); | ||
} | ||
} | ||
} |
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,4 @@ | ||
using Fody; | ||
|
||
[assembly: ConfigureAwait(false)] | ||
namespace Downloader.Test; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<AssertMessage /> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
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 |
---|---|---|
@@ -1,37 +1,35 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Downloader.Test.Helper | ||
namespace Downloader.Test.Helper; | ||
|
||
public static class AssertHelper | ||
{ | ||
public static class AssertHelper | ||
public static void DoesNotThrow<T>(Action action) where T : Exception | ||
{ | ||
public static void DoesNotThrow<T>(Action action) where T : Exception | ||
try | ||
{ | ||
try | ||
{ | ||
action(); | ||
} | ||
catch (T) | ||
{ | ||
Assert.Fail("Expected no {0} to be thrown", typeof(T).Name); | ||
} | ||
catch | ||
{ | ||
return; | ||
} | ||
action(); | ||
} | ||
|
||
public static void AreEquals(Chunk source, Chunk destination) | ||
catch (T) | ||
{ | ||
Assert.IsNotNull(source); | ||
Assert.IsNotNull(destination); | ||
Assert.Fail("Expected no {0} to be thrown", typeof(T).Name); | ||
} | ||
catch | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
public static void AreEquals(Chunk source, Chunk destination) | ||
{ | ||
Assert.IsNotNull(source); | ||
Assert.IsNotNull(destination); | ||
|
||
foreach (var prop in typeof(Chunk).GetProperties().Where(p => p.CanRead && p.CanWrite)) | ||
{ | ||
Assert.AreEqual(prop.GetValue(source), prop.GetValue(destination), prop.Name); | ||
} | ||
foreach (var prop in typeof(Chunk).GetProperties().Where(p => p.CanRead && p.CanWrite)) | ||
{ | ||
Assert.AreEqual(prop.GetValue(source), prop.GetValue(destination), prop.Name); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,34 +1,33 @@ | ||
using System; | ||
|
||
namespace Downloader.Test.Helper | ||
namespace Downloader.Test.Helper; | ||
|
||
public class DownloadServiceEventsState | ||
{ | ||
public class DownloadServiceEventsState | ||
{ | ||
public bool DownloadStarted { get; set; } | ||
public string ActualFileName { get; set; } | ||
public bool DownloadSuccessfullCompleted { get; set; } | ||
public bool IsDownloadCancelled { get; set; } | ||
public bool DownloadProgressIsCorrect { get; set; } = true; | ||
public int DownloadProgressCount { get; set; } = 0; | ||
public Exception DownloadError { get; set; } | ||
public bool DownloadStarted { get; set; } | ||
public string ActualFileName { get; set; } | ||
public bool DownloadSuccessfullCompleted { get; set; } | ||
public bool IsDownloadCancelled { get; set; } | ||
public bool DownloadProgressIsCorrect { get; set; } = true; | ||
public int DownloadProgressCount { get; set; } = 0; | ||
public Exception DownloadError { get; set; } | ||
|
||
public DownloadServiceEventsState(IDownloadService downloadService) | ||
{ | ||
downloadService.DownloadStarted += (s, e) => { | ||
DownloadStarted = true; | ||
ActualFileName = e.FileName; | ||
}; | ||
public DownloadServiceEventsState(IDownloadService downloadService) | ||
{ | ||
downloadService.DownloadStarted += (s, e) => { | ||
DownloadStarted = true; | ||
ActualFileName = e.FileName; | ||
}; | ||
|
||
downloadService.DownloadProgressChanged += (s, e) => { | ||
DownloadProgressCount++; | ||
DownloadProgressIsCorrect &= e.ProgressPercentage == downloadService.Package.SaveProgress; | ||
}; | ||
downloadService.DownloadProgressChanged += (s, e) => { | ||
DownloadProgressCount++; | ||
DownloadProgressIsCorrect &= e.ProgressPercentage == downloadService.Package.SaveProgress; | ||
}; | ||
|
||
downloadService.DownloadFileCompleted += (s, e) => { | ||
DownloadSuccessfullCompleted = e.Error == null && !e.Cancelled; | ||
DownloadError = e.Error; | ||
IsDownloadCancelled = DownloadSuccessfullCompleted == false && DownloadError == null; | ||
}; | ||
} | ||
downloadService.DownloadFileCompleted += (s, e) => { | ||
DownloadSuccessfullCompleted = e.Error == null && !e.Cancelled; | ||
DownloadError = e.Error; | ||
IsDownloadCancelled = DownloadSuccessfullCompleted == false && DownloadError == null; | ||
}; | ||
} | ||
} |
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.