Skip to content

Commit

Permalink
Merge branch 'release/0.102.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Nov 18, 2023
2 parents 10e8cb7 + 2a449d5 commit 70ac0ec
Show file tree
Hide file tree
Showing 18 changed files with 5,815 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "3.0.0",
"version": "3.2.0",
"commands": [
"dotnet-cake"
]
Expand Down
25 changes: 15 additions & 10 deletions Source/StrongGrid.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using System.Linq;

namespace StrongGrid.Benchmark
{
class Program
{
static void Main(string[] args)
{
/*
* Handy code to generate the 'JsonSerializable' attributes for StrongGridJsonSerializerContext
//var serializerContext = GenerateAttributesForSerializerContext();

IConfig config = null;

// To debug
//config = new DebugInProcessConfig();

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
}

private static string GenerateAttributesForSerializerContext()
{
// Handy code to generate the 'JsonSerializable' attributes for StrongGridJsonSerializerContext
var baseNamespace = "StrongGrid.Models";
var allTypes = System.Reflection.Assembly
.GetAssembly(typeof(Client))
Expand Down Expand Up @@ -44,14 +56,7 @@ static void Main(string[] args)
var nullableAttributes = string.Join("\r\n", typesSortedAlphabetically.Where(t => !string.IsNullOrEmpty(t.JsonSerializeAttributeNullable)).Select(t => t.JsonSerializeAttributeNullable));

var result = string.Join("\r\n\r\n", new[] { simpleAttributes, arrayAttributes, nullableAttributes });
*/

IConfig config = null;

// To debug
//config = new DebugInProcessConfig();

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
return result;
}
}
}
2,101 changes: 2,101 additions & 0 deletions Source/StrongGrid.UnitTests/InboudEmailTestData/raw_email.txt

Large diffs are not rendered by default.

3,322 changes: 3,322 additions & 0 deletions Source/StrongGrid.UnitTests/InboudEmailTestData/raw_email_with_attachments.txt

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions Source/StrongGrid.UnitTests/MockSystemClock.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Moq;
using StrongGrid.Utilities;
using System;

namespace StrongGrid.UnitTests
{
internal class MockSystemClock : Mock<ISystemClock>
internal class MockSystemClock : ISystemClock
{
public MockSystemClock(DateTime currentDateTime) :
this(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day, currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second, currentDateTime.Millisecond)
{ }
private readonly DateTime _now;

public MockSystemClock(int year, int month, int day, int hour, int minute, int second, int millisecond) :
base(MockBehavior.Strict)
public DateTime Now => _now;

public DateTime UtcNow => _now;

public MockSystemClock(int year, int month, int day, int hour, int minute, int second, int millisecond)
{
SetupGet(m => m.Now).Returns(new DateTime(year, month, day, hour, minute, second, millisecond, DateTimeKind.Utc));
SetupGet(m => m.UtcNow).Returns(new DateTime(year, month, day, hour, minute, second, millisecond, DateTimeKind.Utc));
_now = new DateTime(year, month, day, hour, minute, second, millisecond, DateTimeKind.Utc);
}
}
}
14 changes: 0 additions & 14 deletions Source/StrongGrid.UnitTests/Resources/AccessManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public async Task GetAccessHistory()
var result = await accessManagement.GetAccessHistoryAsync(20, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
result.ShouldNotBeNull();
result.Length.ShouldBe(2);
}
Expand All @@ -147,8 +145,6 @@ public async Task GetWhitelistedIpAddresses()
var result = await accessManagement.GetWhitelistedIpAddressesAsync(null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
result.ShouldNotBeNull();
result.Length.ShouldBe(3);
}
Expand All @@ -169,8 +165,6 @@ public async Task AddIpAddressToWhitelist()
var result = await accessManagement.AddIpAddressToWhitelistAsync(ip, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
result.ShouldNotBeNull();
}

Expand All @@ -190,8 +184,6 @@ public async Task AddIpAddressesToWhitelist()
var result = await accessManagement.AddIpAddressesToWhitelistAsync(ips, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
result.ShouldNotBeNull();
result.Length.ShouldBe(3);
}
Expand All @@ -212,8 +204,6 @@ public async Task RemoveIpAddressFromWhitelistAsync()
await accessManagement.RemoveIpAddressFromWhitelistAsync(id, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
}

[Fact]
Expand All @@ -232,8 +222,6 @@ public async Task RemoveIpAddressesFromWhitelistAsync()
await accessManagement.RemoveIpAddressesFromWhitelistAsync(ids, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
}

[Fact]
Expand All @@ -254,8 +242,6 @@ public async Task GetWhitelistedIpAddressAsync()
var result = await accessManagement.GetWhitelistedIpAddressAsync(id, null, CancellationToken.None).ConfigureAwait(false);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
mockHttp.VerifyNoOutstandingRequest();
result.ShouldNotBeNull();
}
}
Expand Down
12 changes: 11 additions & 1 deletion Source/StrongGrid.UnitTests/StrongGrid.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down Expand Up @@ -41,6 +45,12 @@
<None Update="InboudEmailTestData\email_with_attachments.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="InboudEmailTestData\raw_email_with_attachments.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="InboudEmailTestData\raw_email.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions Source/StrongGrid.UnitTests/Utilities/SendGridRetryStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void ShouldRetry_returns_false_when_previous_response_is_null()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = (HttpResponseMessage)null;

// Act
Expand All @@ -34,7 +34,7 @@ public void ShouldRetry_returns_true_when_statuscode_429()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage((HttpStatusCode)429);

// Act
Expand All @@ -50,7 +50,7 @@ public void ShouldRetry_returns_false_when_statuscode_not_429()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage(HttpStatusCode.BadGateway);

// Act
Expand All @@ -66,7 +66,7 @@ public void GetNextDelay_with_null_HttpHeaders()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = (HttpResponseMessage)null;

// Act
Expand All @@ -82,7 +82,7 @@ public void CalculateDelay_without_XRateLimitReset()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage((HttpStatusCode)428);

// Act
Expand All @@ -98,7 +98,7 @@ public void CalculateDelay_with_too_small_XRateLimitReset()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage((HttpStatusCode)428);
response.Headers.Add("X-RateLimit-Reset", "-1");

Expand All @@ -115,9 +115,9 @@ public void CalculateDelay_with_reasonable_XRateLimitReset()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage((HttpStatusCode)428);
response.Headers.Add("X-RateLimit-Reset", mockSystemClock.Object.UtcNow.AddSeconds(3).ToUnixTime().ToString());
response.Headers.Add("X-RateLimit-Reset", mockSystemClock.UtcNow.AddSeconds(3).ToUnixTime().ToString());

// Act
var result = sendGridRetryStrategy.GetDelay(1, response);
Expand All @@ -132,9 +132,9 @@ public void CalculateDelay_with_too_large_XRateLimitReset()
// Arrange
var maxAttempts = 5;
var mockSystemClock = new MockSystemClock(2016, 11, 11, 13, 14, 0, 0);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock.Object);
var sendGridRetryStrategy = new SendGridRetryStrategy(maxAttempts, mockSystemClock);
var response = new HttpResponseMessage((HttpStatusCode)428);
response.Headers.Add("X-RateLimit-Reset", mockSystemClock.Object.UtcNow.AddHours(1).ToUnixTime().ToString());
response.Headers.Add("X-RateLimit-Reset", mockSystemClock.UtcNow.AddHours(1).ToUnixTime().ToString());

// Act
var result = sendGridRetryStrategy.GetDelay(1, response);
Expand Down
Loading

0 comments on commit 70ac0ec

Please sign in to comment.