@@ -37,6 +37,11 @@ public class HttpProjectConfigManagerTest
37
37
private Mock < TestNotificationCallbacks > NotificationCallbackMock =
38
38
new Mock < TestNotificationCallbacks > ( ) ;
39
39
40
+ private const string ExpectedRfc1123DateTime = "Thu, 03 Nov 2022 16:00:00 GMT" ;
41
+
42
+ private readonly DateTime _pastLastModified =
43
+ new DateTimeOffset ( new DateTime ( 2022 , 11 , 3 , 16 , 0 , 0 , DateTimeKind . Utc ) ) . UtcDateTime ;
44
+
40
45
[ SetUp ]
41
46
public void Setup ( )
42
47
{
@@ -100,22 +105,29 @@ public void TestSettingIfModifiedSinceInRequestHeader()
100
105
statusCode : HttpStatusCode . NotModified ,
101
106
responseContentHeaders : new Dictionary < string , string >
102
107
{
103
- { "Last-Modified" , new DateTime ( 2050 , 10 , 10 ) . ToString ( "R " ) } ,
108
+ { "Last-Modified" , _pastLastModified . ToString ( "r " ) } ,
104
109
}
105
110
) ;
106
111
107
112
var httpManager = new HttpProjectConfigManager . Builder ( )
108
- . WithDatafile ( string . Empty )
113
+ . WithSdkKey ( "QBw9gFM8oTn7ogY9ANCC1z" )
109
114
. WithLogger ( LoggerMock . Object )
110
115
. WithPollingInterval ( TimeSpan . FromMilliseconds ( 1000 ) )
111
116
. WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 2000 ) )
112
117
. WithStartByDefault ( )
113
118
. Build ( defer : true ) ;
114
- httpManager . LastModifiedSince = new DateTime ( 2020 , 4 , 4 ) . ToString ( "R " ) ;
119
+ httpManager . LastModifiedSince = _pastLastModified . ToString ( "r " ) ;
115
120
t . Wait ( 3000 ) ;
116
121
122
+ HttpClientMock . Verify ( _ => _ . SendAsync (
123
+ It . Is < HttpRequestMessage > ( requestMessage =>
124
+ requestMessage . Headers . IfModifiedSince . HasValue &&
125
+ requestMessage . Headers . IfModifiedSince . Value . UtcDateTime . ToString ( "r" ) ==
126
+ ExpectedRfc1123DateTime
127
+ ) ) , Times . Once ) ;
117
128
LoggerMock . Verify (
118
- _ => _ . Log ( LogLevel . DEBUG , "Set If-Modified-Since in request header." ) ,
129
+ _ => _ . Log ( LogLevel . DEBUG ,
130
+ $ "Set If-Modified-Since in request header: { ExpectedRfc1123DateTime } ") ,
119
131
Times . AtLeastOnce ) ;
120
132
121
133
httpManager . Dispose ( ) ;
@@ -125,22 +137,24 @@ public void TestSettingIfModifiedSinceInRequestHeader()
125
137
public void TestSettingLastModifiedFromResponseHeader ( )
126
138
{
127
139
MockSendAsync (
140
+ datafile : TestData . Datafile ,
128
141
statusCode : HttpStatusCode . OK ,
129
142
responseContentHeaders : new Dictionary < string , string >
130
143
{
131
- { "Last-Modified" , new DateTime ( 2050 , 10 , 10 ) . ToString ( "R " ) } ,
144
+ { "Last-Modified" , _pastLastModified . ToString ( "r " ) } ,
132
145
}
133
146
) ;
134
147
var httpManager = new HttpProjectConfigManager . Builder ( )
135
- . WithUrl ( "https://cdn.optimizely.com/datafiles/ QBw9gFM8oTn7ogY9ANCC1z.json ")
148
+ . WithSdkKey ( " QBw9gFM8oTn7ogY9ANCC1z")
136
149
. WithLogger ( LoggerMock . Object )
137
150
. WithPollingInterval ( TimeSpan . FromMilliseconds ( 1000 ) )
138
151
. WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 500 ) )
139
152
. WithStartByDefault ( )
140
153
. Build ( ) ;
141
154
142
155
LoggerMock . Verify (
143
- _ => _ . Log ( LogLevel . DEBUG , "Set LastModifiedSince from response header." ) ,
156
+ _ => _ . Log ( LogLevel . DEBUG ,
157
+ $ "Set LastModifiedSince from response header: { ExpectedRfc1123DateTime } ") ,
144
158
Times . AtLeastOnce ) ;
145
159
146
160
httpManager . Dispose ( ) ;
0 commit comments