Skip to content

Commit

Permalink
Merge branch 'release/v2.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Feb 23, 2022
2 parents f0c1f81 + 39532e1 commit f21b987
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 94 deletions.
53 changes: 0 additions & 53 deletions src/Downloader.Test/ExceptionHelperTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Downloader.Test
namespace Downloader.Test.Helper
{
public class DownloadServiceEventsState
{
Expand All @@ -21,7 +21,7 @@ public DownloadServiceEventsState(IDownloadService downloadService)

downloadService.DownloadProgressChanged += (s, e) => {
DownloadProgressCount++;
DownloadProgressIsCorrect &= (e.ProgressPercentage == downloadService.Package.SaveProgress);
DownloadProgressIsCorrect &= e.ProgressPercentage == downloadService.Package.SaveProgress;
};

downloadService.DownloadFileCompleted += (s, e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Threading;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
public abstract class DownloadIntegrationTest
{
Expand Down Expand Up @@ -314,7 +314,7 @@ public void SpeedLimitTest()
Config.MaximumBytesPerSecond = 256; // 256 Byte/s
var downloader = new DownloadService(Config);
downloader.DownloadProgressChanged += (s, e) => {
averageSpeed = ((averageSpeed * progressCounter) + e.BytesPerSecondSpeed) / (progressCounter + 1);
averageSpeed = (averageSpeed * progressCounter + e.BytesPerSecondSpeed) / (progressCounter + 1);
progressCounter++;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Downloader.Test.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class DownloadServiceMockHelperTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using System.Net;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class DownloadServiceTest : DownloadService
Expand Down Expand Up @@ -121,7 +121,7 @@ public void TestPackageChunksDataAfterDispose()
Assert.IsNotNull(Package.Chunks);
foreach (var chunk in Package.Chunks)
{
Assert.IsTrue(DummyFileHelper.AreEqual(dummyData, chunk.Storage.OpenRead()));
Assert.IsTrue(dummyData.AreEqual(chunk.Storage.OpenRead()));
}

Package.Clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class ParallelOnTheFlyDownloadIntegrationTest : DownloadIntegrationTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class ParallelOnTheTempDownloadIntegrationTest : DownloadIntegrationTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class SerialOnTheFlyDownloadIntegrationTest : DownloadIntegrationTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.IntegrationTests
{
[TestClass]
public class SerialOnTheTempDownloadIntegrationTest : DownloadIntegrationTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Threading;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class BandwidthTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Downloader.Test.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class ChunkDownloaderTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class ChunkHubTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public abstract class ChunkTest
Expand Down Expand Up @@ -145,7 +145,7 @@ public void IsValidPositionOnOverflowTest()
// assert
Assert.IsFalse(isValidPosition);
}

[TestMethod]
public void IsValidPositionWithEqualStorageSizeTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.IO;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class DownloadBuilderTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.IO;
using System.Reflection;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class DownloadConfigurationTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public abstract class DownloadPackageTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Net;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class DummyFileControllerTest
Expand Down Expand Up @@ -36,7 +36,7 @@ public void GetFileWithNameTest()
byte[] bytes = new byte[size];
string filename = "testfilename.dat";
string url = DummyFileHelper.GetFileWithNameUrl(filename, size);
var dummyData = Helper.DummyData.GenerateOrderedBytes(size);
var dummyData = DummyData.GenerateOrderedBytes(size);

// act
var headers = ReadAndGetHeaders(url, bytes);
Expand All @@ -55,7 +55,7 @@ public void GetFileWithoutHeaderTest()
byte[] bytes = new byte[size];
string filename = "testfilename.dat";
string url = DummyFileHelper.GetFileWithoutHeaderUrl(filename, size);
var dummyData = Helper.DummyData.GenerateOrderedBytes(size);
var dummyData = DummyData.GenerateOrderedBytes(size);

// act
var headers = ReadAndGetHeaders(url, bytes);
Expand All @@ -74,7 +74,7 @@ public void GetFileWithContentDispositionTest()
byte[] bytes = new byte[size];
string filename = "testfilename.dat";
string url = DummyFileHelper.GetFileWithContentDispositionUrl(filename, size);
var dummyData = Helper.DummyData.GenerateOrderedBytes(size);
var dummyData = DummyData.GenerateOrderedBytes(size);

// act
var headers = ReadAndGetHeaders(url, bytes);
Expand Down
84 changes: 84 additions & 0 deletions src/Downloader.Test/UnitTests/ExceptionHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Net.Http;

namespace Downloader.Test.UnitTests
{
[TestClass]
public class ExceptionHelperTest
{
[TestMethod]
public void HasSourceFromThisNamespaceTest()
{
// arrange
Exception exception = ExceptionThrower.GetException();
var exceptionSource = exception.Source;
var currentNamespace = "Downloader.Test";

// act
bool hasThisNamespace = exception.HasSource(currentNamespace);

// assert
Assert.IsTrue(hasThisNamespace,
$"Exception.Source: {exceptionSource}, CurrentNamespace: {currentNamespace}");
}

[TestMethod]
public void HasSourceFromNonOccurrenceNamespaceTest()
{
// arrange
Exception exception = ExceptionThrower.GetException();

// act
bool hasSocketsNamespace = exception.HasSource("System.Net.Sockets");
bool hasSecurityNamespace = exception.HasSource("System.Net.Security");

// assert
Assert.IsFalse(hasSocketsNamespace);
Assert.IsFalse(hasSecurityNamespace);
}
}

public static class ExceptionThrower
{
public static Exception GetException()
{
try
{
ThrowException();
return new Exception(); // This code will never run.
}
catch (Exception e)
{
return e;
}
}
private static void ThrowException()
{
try
{
ThrowIoException();
}
catch (Exception e)
{
throw new Exception("High level exception", e);
}
}
private static void ThrowIoException()
{
try
{
ThrowHttpRequestException();
}
catch (Exception e)
{
throw new IOException("Mid level exception", e);
}
}
private static void ThrowHttpRequestException()
{
throw new HttpRequestException("Low level exception");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class FileChunkTest : ChunkTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class FileDownloadPackageTest : DownloadPackageTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Downloader.Test.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class FileHelperTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class FileStorageTest : StorageTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class MemoryChunkTest : ChunkTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class MemoryDownloadPackageTest : DownloadPackageTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Downloader.Test
namespace Downloader.Test.UnitTests
{
[TestClass]
public class MemoryStorageTest : StorageTest
Expand Down
Loading

0 comments on commit f21b987

Please sign in to comment.