@@ -197,49 +197,38 @@ public void GenerateSitemapXml_DoesNotIncludeErrorRoutes()
197197 }
198198
199199 [ Fact ]
200- public void GenerateAndSerializeSitemapXml_CreatesFileSuccessfully ( )
200+ public void GenerateSitemapXml_UsesLastModifiedDateFromSiteMapping ( )
201201 {
202202 // Arrange
203- var logger = _Factory . Services . GetRequiredService < ILogger < SitemapXmlHelpersTests > > ( ) ;
204203 var tempDir = new DirectoryInfo ( Path . GetTempPath ( ) ) ;
205- var siteMappings = new List < SiteMapping > { CreateSiteMapping ( 1 , 1 , true ) } ;
206204 var baseUrl = "https://test.example.com/" ;
205+ var specificLastModified = new DateTime ( 2023 , 5 , 15 , 10 , 30 , 0 , DateTimeKind . Utc ) ;
207206
208- // Clean up any existing file
209- var expectedXmlPath = Path . Combine ( tempDir . FullName , "sitemap.xml" ) ;
210- File . Delete ( expectedXmlPath ) ;
211-
212- try
213- {
214- // Act
215- var routeConfigurationService = _Factory . Services . GetRequiredService < IRouteConfigurationService > ( ) ;
216- SitemapXmlHelpers . GenerateAndSerializeSitemapXml (
217- tempDir ,
218- siteMappings ,
219- logger ,
220- routeConfigurationService ,
221- baseUrl ) ;
222-
223- // Assert
224- Assert . True ( File . Exists ( expectedXmlPath ) ) ;
225-
226- var xmlContent = File . ReadAllText ( expectedXmlPath ) ;
227- Assert . Contains ( "<?xml" , xmlContent ) ;
228- Assert . Contains ( "<urlset" , xmlContent ) ;
229- Assert . Contains ( baseUrl , xmlContent ) ;
230- }
231- finally
207+ var siteMappings = new List < SiteMapping >
232208 {
233- // Clean up
234- File . Delete ( expectedXmlPath ) ;
235- }
209+ CreateSiteMapping ( 1 , 1 , true , "test-page-1" , specificLastModified )
210+ } ;
211+
212+ // Act
213+ var routeConfigurationService = _Factory . Services . GetRequiredService < IRouteConfigurationService > ( ) ;
214+ SitemapXmlHelpers . GenerateSitemapXml (
215+ tempDir ,
216+ siteMappings ,
217+ routeConfigurationService ,
218+ baseUrl ,
219+ out var nodes ) ;
220+
221+ // Assert
222+ var siteMappingNode = nodes . First ( node => node . Url . Contains ( "test-page-1" ) ) ;
223+ Assert . Equal ( specificLastModified , siteMappingNode . LastModificationDate ) ;
236224 }
237225
238226 private static SiteMapping CreateSiteMapping (
239227 int chapterNumber ,
240228 int pageNumber ,
241229 bool includeInSitemapXml ,
242- string key = "test-key" )
230+ string key = "test-key" ,
231+ DateTime ? lastModified = null )
243232 {
244233 return new SiteMapping (
245234 keys : [ key ] ,
@@ -253,7 +242,8 @@ private static SiteMapping CreateSiteMapping(
253242 anchorId : key ,
254243 indentLevel : 1 ,
255244 contentHash : "TestHash123" ,
256- includeInSitemapXml : includeInSitemapXml
245+ includeInSitemapXml : includeInSitemapXml ,
246+ lastModified : lastModified
257247 ) ;
258248 }
259249}
0 commit comments