Skip to content

Commit

Permalink
Add more accurate assert
Browse files Browse the repository at this point in the history
  • Loading branch information
mikechu-optimizely committed Jul 24, 2023
1 parent e9fa629 commit 0f138e8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class HttpProjectConfigManagerTest
new Mock<TestNotificationCallbacks>();

private const string ExpectedRfc1123DateTime = "Thu, 03 Nov 2022 16:00:00 GMT";
private readonly DateTime _pastLastModified = new DateTime(2022, 11, 3, 16, 0, 0, DateTimeKind.Utc);
private readonly DateTime _pastLastModified = new DateTimeOffset(new DateTime(2022, 11, 3, 16, 0, 0, DateTimeKind.Utc)).UtcDateTime;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -98,26 +98,30 @@ public void TestHttpConfigManagerWithInvalidStatus()
[Test]
public void TestSettingIfModifiedSinceInRequestHeader()
{
var formattedDateTime = new DateTimeOffset(_pastLastModified).UtcDateTime.ToString("r");
var t = MockSendAsync(
datafile: string.Empty,
statusCode: HttpStatusCode.NotModified,
responseContentHeaders: new Dictionary<string, string>
{
{ "Last-Modified", formattedDateTime },
{ "Last-Modified", _pastLastModified.ToString("r") },
}
);

var httpManager = new HttpProjectConfigManager.Builder()
.WithDatafile(string.Empty)
.WithSdkKey("QBw9gFM8oTn7ogY9ANCC1z")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(2000))
.WithStartByDefault()
.Build(defer: true);
httpManager.LastModifiedSince = formattedDateTime;
httpManager.LastModifiedSince = _pastLastModified.ToString("r");
t.Wait(3000);

HttpClientMock.Verify(_ => _.SendAsync(
It.Is<HttpRequestMessage>(requestMessage =>
requestMessage.Headers.IfModifiedSince.HasValue &&
requestMessage.Headers.IfModifiedSince.Value.UtcDateTime.ToString("r") == ExpectedRfc1123DateTime
)), Times.Once);
LoggerMock.Verify(
_ => _.Log(LogLevel.DEBUG, $"Set If-Modified-Since in request header: {ExpectedRfc1123DateTime}"),
Times.AtLeastOnce);
Expand All @@ -128,16 +132,16 @@ public void TestSettingIfModifiedSinceInRequestHeader()
[Test]
public void TestSettingLastModifiedFromResponseHeader()
{
var formattedDateTime = new DateTimeOffset(_pastLastModified).UtcDateTime.ToString("r");
MockSendAsync(
datafile: TestData.Datafile,
statusCode: HttpStatusCode.OK,
responseContentHeaders: new Dictionary<string, string>
{
{ "Last-Modified", formattedDateTime },
{ "Last-Modified", _pastLastModified.ToString("r") },
}
);
var httpManager = new HttpProjectConfigManager.Builder()
.WithUrl("https://cdn.optimizely.com/datafiles/QBw9gFM8oTn7ogY9ANCC1z.json")
.WithSdkKey("QBw9gFM8oTn7ogY9ANCC1z")
.WithLogger(LoggerMock.Object)
.WithPollingInterval(TimeSpan.FromMilliseconds(1000))
.WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500))
Expand Down

0 comments on commit 0f138e8

Please sign in to comment.