Skip to content

Commit

Permalink
fixed name conventions to camelcase protected members
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Sep 18, 2024
1 parent a7d590e commit dcd2ae2
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 277 deletions.
4 changes: 2 additions & 2 deletions src/Downloader.DummyHttpServer/DummyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Downloader.DummyHttpServer;
[ExcludeFromCodeCoverage]
public static class DummyData
{
private static Random _rand = new Random(DateTime.Now.GetHashCode());
private static Random Rand = new Random(DateTime.Now.GetHashCode());

/// <summary>
/// Generates random bytes
Expand All @@ -21,7 +21,7 @@ public static byte[] GenerateRandomBytes(int length)
throw new ArgumentException("length has to be > 0");

byte[] buffer = new byte[length];
_rand.NextBytes(buffer);
Rand.NextBytes(buffer);
return buffer;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Downloader.DummyHttpServer/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Downloader.DummyHttpServer;
[ExcludeFromCodeCoverage]
public class HttpServer
{
private static IMemoryCache _cache = new MemoryCache(new MemoryCacheOptions());
private static IMemoryCache Cache = new MemoryCache(new MemoryCacheOptions());
private static IWebHost Server;
public static int Port { get; set; } = 3333;
public static CancellationTokenSource CancellationToken { get; set; }
Expand All @@ -31,7 +31,7 @@ public static void Run(int port)
if (CancellationToken.IsCancellationRequested)
return;

Server ??= _cache.GetOrCreate("DownloaderWebHost", e => {
Server ??= Cache.GetOrCreate("DownloaderWebHost", e => {
var host = CreateHostBuilder(port);
host.RunAsync(CancellationToken.Token).ConfigureAwait(false);
return host;
Expand Down
4 changes: 2 additions & 2 deletions src/Downloader.Test/HelperTests/AssertHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void TestChunksAreNotEquals()
};

// act
void testAssertHelper() => AssertHelper.AreEquals(chunk1, chunk2);
void TestAssertHelper() => AssertHelper.AreEquals(chunk1, chunk2);

// assert
Assert.ThrowsAny<Exception>(testAssertHelper);
Assert.ThrowsAny<Exception>(TestAssertHelper);
Assert.NotEqual(chunk1, chunk2);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Downloader.Test/HelperTests/DummyDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public void GenerateOrderedBytesLessThan1Test()
int size = 0;

// act
void act() => DummyData.GenerateOrderedBytes(size);
void Act() => DummyData.GenerateOrderedBytes(size);

// assert
Assert.ThrowsAny<ArgumentException>(act);
Assert.ThrowsAny<ArgumentException>(Act);
}

[Fact]
Expand All @@ -56,10 +56,10 @@ public void GenerateRandomBytesLessThan1Test()
int size = 0;

// act
void act() => DummyData.GenerateRandomBytes(size);
void Act() => DummyData.GenerateRandomBytes(size);

// assert
Assert.ThrowsAny<ArgumentException>(act);
Assert.ThrowsAny<ArgumentException>(Act);
}

[Fact]
Expand Down
80 changes: 40 additions & 40 deletions src/Downloader.Test/HelperTests/DummyFileControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Downloader.Test.HelperTests;

public class DummyFileControllerTest
{
private readonly string contentType = "application/octet-stream";
private WebHeaderCollection headers;
private readonly string _contentType = "application/octet-stream";
private WebHeaderCollection _headers;

[Fact]
public void GetFileTest()
Expand All @@ -27,8 +27,8 @@ public void GetFileTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
}

[Fact]
Expand All @@ -46,8 +46,8 @@ public void GetFileWithNameTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
}

[Fact]
Expand All @@ -67,8 +67,8 @@ public void GetSingleByteFileWithNameTest()
// assert
Assert.True(bytes.All(i => i == fillByte));
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
}

[Fact]
Expand All @@ -86,8 +86,8 @@ public void GetFileWithoutHeaderTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Null(headers["Content-Length"]);
Assert.Null(headers["Content-Type"]);
Assert.Null(_headers["Content-Length"]);
Assert.Null(_headers["Content-Type"]);
}

[Fact]
Expand All @@ -107,8 +107,8 @@ public void GetSingleByteFileWithoutHeaderTest()
// assert
Assert.True(bytes.All(i => i == fillByte));
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Null(headers["Content-Length"]);
Assert.Null(headers["Content-Type"]);
Assert.Null(_headers["Content-Length"]);
Assert.Null(_headers["Content-Type"]);
}

[Fact]
Expand All @@ -126,9 +126,9 @@ public void GetFileWithContentDispositionTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Contains($"filename={filename};", headers["Content-Disposition"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Contains($"filename={filename};", _headers["Content-Disposition"]);
}

[Fact]
Expand All @@ -148,9 +148,9 @@ public void GetSingleByteFileWithContentDispositionTest()
// assert
Assert.True(bytes.All(i => i == fillByte));
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Contains($"filename={filename};", headers["Content-Disposition"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Contains($"filename={filename};", _headers["Content-Disposition"]);
}

[Fact]
Expand All @@ -167,10 +167,10 @@ public void GetFileWithRangeTest()

// assert
Assert.True(dummyData.Take(512).SequenceEqual(bytes.Take(512)));
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Equal("512", headers["Content-Length"]);
Assert.Equal("bytes 0-511/1024", headers["Content-Range"]);
Assert.Equal("bytes", headers["Accept-Ranges"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Equal("512", _headers["Content-Length"]);
Assert.Equal("bytes 0-511/1024", _headers["Content-Range"]);
Assert.Equal("bytes", _headers["Accept-Ranges"]);
}

[Fact]
Expand All @@ -188,9 +188,9 @@ public void GetFileWithNoAcceptRangeTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Null(headers["Accept-Ranges"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Null(_headers["Accept-Ranges"]);
}

[Fact]
Expand All @@ -210,9 +210,9 @@ public void GetSingleByteFileWithNoAcceptRangeTest()
// assert
Assert.True(bytes.All(i => i == fillByte));
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.Null(headers["Accept-Ranges"]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Null(_headers["Accept-Ranges"]);
}

[Fact]
Expand All @@ -230,9 +230,9 @@ public void GetFileWithNameOnRedirectTest()

// assert
Assert.True(dummyData.SequenceEqual(bytes));
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.NotEqual(url, headers[nameof(WebResponse.ResponseUri)]);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.NotEqual(url, _headers[nameof(WebResponse.ResponseUri)]);
}

[Fact]
Expand All @@ -245,12 +245,12 @@ public void GetFileWithFailureAfterOffsetTest()
string url = DummyFileHelper.GetFileWithFailureAfterOffset(size, failureOffset);

// act
void getHeaders() => ReadAndGetHeaders(url, bytes, false);
void GetHeaders() => ReadAndGetHeaders(url, bytes, false);

// assert
Assert.ThrowsAny<IOException>(getHeaders);
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.ThrowsAny<IOException>(GetHeaders);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Equal(0, bytes[size - 1]);
}

Expand All @@ -264,12 +264,12 @@ public void GetFileWithTimeoutAfterOffsetTest()
string url = DummyFileHelper.GetFileWithTimeoutAfterOffset(size, timeoutOffset);

// act
void getHeaders() => ReadAndGetHeaders(url, bytes, false);
void GetHeaders() => ReadAndGetHeaders(url, bytes, false);

// assert
Assert.ThrowsAny<IOException>(getHeaders);
Assert.Equal(size.ToString(), headers["Content-Length"]);
Assert.Equal(contentType, headers["Content-Type"]);
Assert.ThrowsAny<IOException>(GetHeaders);
Assert.Equal(size.ToString(), _headers["Content-Length"]);
Assert.Equal(_contentType, _headers["Content-Type"]);
Assert.Equal(0, bytes[size - 1]);
}

Expand All @@ -287,7 +287,7 @@ private void ReadAndGetHeaders(string url, byte[] bytes, bool justFirst512Bytes

// keep response headers
downloadResponse.Headers.Add(nameof(WebResponse.ResponseUri), downloadResponse.ResponseUri.ToString());
headers = downloadResponse.Headers;
_headers = downloadResponse.Headers;

// read stream data
var readCount = 1;
Expand Down
8 changes: 4 additions & 4 deletions src/Downloader.Test/HelperTests/DummyLazyStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public void GenerateOrderedBytesStreamLessThan1Test()
int size = 0;

// act
void act() => new DummyLazyStream(DummyDataType.Order, size);
void Act() => new DummyLazyStream(DummyDataType.Order, size);

// assert
Assert.ThrowsAny<ArgumentException>(act);
Assert.ThrowsAny<ArgumentException>(Act);
}

[Fact]
Expand All @@ -58,10 +58,10 @@ public void GenerateRandomBytesLessThan1Test()
int size = 0;

// act
void act() => new DummyLazyStream(DummyDataType.Random, size);
void Act() => new DummyLazyStream(DummyDataType.Random, size);

// assert
Assert.ThrowsAny<ArgumentException>(act);
Assert.ThrowsAny<ArgumentException>(Act);
}

[Fact]
Expand Down
Loading

0 comments on commit dcd2ae2

Please sign in to comment.