@@ -37,6 +37,11 @@ public class HttpProjectConfigManagerTest
3737 private Mock < TestNotificationCallbacks > NotificationCallbackMock =
3838 new Mock < TestNotificationCallbacks > ( ) ;
3939
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+
4045 [ SetUp ]
4146 public void Setup ( )
4247 {
@@ -100,22 +105,29 @@ public void TestSettingIfModifiedSinceInRequestHeader()
100105 statusCode : HttpStatusCode . NotModified ,
101106 responseContentHeaders : new Dictionary < string , string >
102107 {
103- { "Last-Modified" , new DateTime ( 2050 , 10 , 10 ) . ToString ( "R " ) } ,
108+ { "Last-Modified" , _pastLastModified . ToString ( "r " ) } ,
104109 }
105110 ) ;
106111
107112 var httpManager = new HttpProjectConfigManager . Builder ( )
108- . WithDatafile ( string . Empty )
113+ . WithSdkKey ( "QBw9gFM8oTn7ogY9ANCC1z" )
109114 . WithLogger ( LoggerMock . Object )
110115 . WithPollingInterval ( TimeSpan . FromMilliseconds ( 1000 ) )
111116 . WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 2000 ) )
112117 . WithStartByDefault ( )
113118 . Build ( defer : true ) ;
114- httpManager . LastModifiedSince = new DateTime ( 2020 , 4 , 4 ) . ToString ( "R " ) ;
119+ httpManager . LastModifiedSince = _pastLastModified . ToString ( "r " ) ;
115120 t . Wait ( 3000 ) ;
116121
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 ) ;
117128 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 } ") ,
119131 Times . AtLeastOnce ) ;
120132
121133 httpManager . Dispose ( ) ;
@@ -125,22 +137,24 @@ public void TestSettingIfModifiedSinceInRequestHeader()
125137 public void TestSettingLastModifiedFromResponseHeader ( )
126138 {
127139 MockSendAsync (
140+ datafile : TestData . Datafile ,
128141 statusCode : HttpStatusCode . OK ,
129142 responseContentHeaders : new Dictionary < string , string >
130143 {
131- { "Last-Modified" , new DateTime ( 2050 , 10 , 10 ) . ToString ( "R " ) } ,
144+ { "Last-Modified" , _pastLastModified . ToString ( "r " ) } ,
132145 }
133146 ) ;
134147 var httpManager = new HttpProjectConfigManager . Builder ( )
135- . WithUrl ( "https://cdn.optimizely.com/datafiles/ QBw9gFM8oTn7ogY9ANCC1z.json ")
148+ . WithSdkKey ( " QBw9gFM8oTn7ogY9ANCC1z")
136149 . WithLogger ( LoggerMock . Object )
137150 . WithPollingInterval ( TimeSpan . FromMilliseconds ( 1000 ) )
138151 . WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 500 ) )
139152 . WithStartByDefault ( )
140153 . Build ( ) ;
141154
142155 LoggerMock . Verify (
143- _ => _ . Log ( LogLevel . DEBUG , "Set LastModifiedSince from response header." ) ,
156+ _ => _ . Log ( LogLevel . DEBUG ,
157+ $ "Set LastModifiedSince from response header: { ExpectedRfc1123DateTime } ") ,
144158 Times . AtLeastOnce ) ;
145159
146160 httpManager . Dispose ( ) ;
0 commit comments