@@ -234,6 +234,149 @@ public void UpdateChapterListingNumbers_GitStorageManager_ListingsWithinListMiss
234234 }
235235 #endregion GitStorageManager
236236 #region UsingOSStorageManager
237+ [ Fact ]
238+ public void UpdateChapterListingNumbers_OSStorageManager_FileScopedNamespacesUpdated ( )
239+ {
240+ ICollection < string > filesToMake = new List < string >
241+ {
242+ Path . Join ( "Chapter42" , "Listing42.06.cs" ) ,
243+ } ;
244+
245+ ICollection < string > expectedFiles = new List < string >
246+ {
247+ Path . Join ( "Chapter42" , "Listing42.01.cs" )
248+ } ;
249+
250+ IEnumerable < string > toWrite = new List < string >
251+ {
252+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06;" ,
253+ " using System;" ,
254+ " using System.Reflection;" ,
255+ " public class Program { }" ,
256+ } ;
257+
258+ IEnumerable < string > expectedToWrite = new List < string >
259+ {
260+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter42.Listing42_01;" ,
261+ " using System;" ,
262+ " using System.Reflection;" ,
263+ " public class Program { }" ,
264+ } ;
265+ DirectoryInfo tempDir = CreateTempDirectory ( ) ;
266+ DirectoryInfo chapterDir = CreateTempDirectory ( tempDir , name : "Chapter42" ) ;
267+ CreateTempDirectory ( tempDir , name : "Chapter42.Tests" ) ;
268+ WriteFiles ( tempDir , filesToMake , toWrite ) ;
269+ expectedFiles = ConvertFileNamesToFullPath ( expectedFiles , tempDir ) . ToList ( ) ;
270+
271+ ListingManager listingManager = new ( tempDir , new OSStorageManager ( ) ) ;
272+ listingManager . UpdateChapterListingNumbers ( chapterDir ) ;
273+
274+ List < string > files = FileManager . GetAllFilesAtPath ( tempDir . FullName , true )
275+ . Where ( x => Path . GetExtension ( x ) == ".cs" ) . OrderBy ( x => x ) . ToList ( ) ;
276+
277+ // Assert
278+ string expectedFile = Assert . Single ( files ) ;
279+ Assert . Equivalent ( expectedFiles , files ) ;
280+
281+ Assert . Equal ( string . Join ( Environment . NewLine , expectedToWrite ) + Environment . NewLine , File . ReadAllText ( expectedFile ) ) ;
282+ }
283+
284+ [ Fact ]
285+ public void UpdateChapterListingNumbers_OSStorageManager_FileScopedNamespaceWithSpacesUpdated ( )
286+ {
287+ ICollection < string > filesToMake = new List < string >
288+ {
289+ Path . Join ( "Chapter42" , "Listing42.06.cs" ) ,
290+ } ;
291+
292+ ICollection < string > expectedFiles = new List < string >
293+ {
294+ Path . Join ( "Chapter42" , "Listing42.01.cs" )
295+ } ;
296+
297+ IEnumerable < string > toWrite = new List < string >
298+ {
299+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06 ;" ,
300+ " using System;" ,
301+ " using System.Reflection;" ,
302+ " public class Program { }" ,
303+ } ;
304+
305+ IEnumerable < string > expectedToWrite = new List < string >
306+ {
307+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter42.Listing42_01 ;" ,
308+ " using System;" ,
309+ " using System.Reflection;" ,
310+ " public class Program { }" ,
311+ } ;
312+ DirectoryInfo tempDir = CreateTempDirectory ( ) ;
313+ DirectoryInfo chapterDir = CreateTempDirectory ( tempDir , name : "Chapter42" ) ;
314+ CreateTempDirectory ( tempDir , name : "Chapter42.Tests" ) ;
315+ WriteFiles ( tempDir , filesToMake , toWrite ) ;
316+ expectedFiles = ConvertFileNamesToFullPath ( expectedFiles , tempDir ) . ToList ( ) ;
317+
318+ ListingManager listingManager = new ( tempDir , new OSStorageManager ( ) ) ;
319+ listingManager . UpdateChapterListingNumbers ( chapterDir ) ;
320+
321+ List < string > files = FileManager . GetAllFilesAtPath ( tempDir . FullName , true )
322+ . Where ( x => Path . GetExtension ( x ) == ".cs" ) . OrderBy ( x => x ) . ToList ( ) ;
323+
324+ // Assert
325+ string expectedFile = Assert . Single ( files ) ;
326+ Assert . Equivalent ( expectedFiles , files ) ;
327+
328+ Assert . Equal ( string . Join ( Environment . NewLine , expectedToWrite ) + Environment . NewLine , File . ReadAllText ( expectedFile ) ) ;
329+ }
330+
331+ [ Fact ]
332+ public void UpdateChapterListingNumbers_OSStorageManager_NamespacesWithCurlyBraceOnSameLineUpdated ( )
333+ {
334+ ICollection < string > filesToMake = new List < string >
335+ {
336+ Path . Join ( "Chapter42" , "Listing42.06.cs" ) ,
337+ } ;
338+
339+ ICollection < string > expectedFiles = new List < string >
340+ {
341+ Path . Join ( "Chapter42" , "Listing42.01.cs" )
342+ } ;
343+
344+ IEnumerable < string > toWrite = new List < string >
345+ {
346+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06 {" ,
347+ " using System;" ,
348+ " using System.Reflection;" ,
349+ " public class Program { }" ,
350+ "}"
351+ } ;
352+
353+ IEnumerable < string > expectedToWrite = new List < string >
354+ {
355+ "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter42.Listing42_01 {" ,
356+ " using System;" ,
357+ " using System.Reflection;" ,
358+ " public class Program { }" ,
359+ "}" ,
360+ } ;
361+ DirectoryInfo tempDir = CreateTempDirectory ( ) ;
362+ DirectoryInfo chapterDir = CreateTempDirectory ( tempDir , name : "Chapter42" ) ;
363+ CreateTempDirectory ( tempDir , name : "Chapter42.Tests" ) ;
364+ WriteFiles ( tempDir , filesToMake , toWrite ) ;
365+ expectedFiles = ConvertFileNamesToFullPath ( expectedFiles , tempDir ) . ToList ( ) ;
366+
367+ ListingManager listingManager = new ( tempDir , new OSStorageManager ( ) ) ;
368+ listingManager . UpdateChapterListingNumbers ( chapterDir ) ;
369+
370+ List < string > files = FileManager . GetAllFilesAtPath ( tempDir . FullName , true )
371+ . Where ( x => Path . GetExtension ( x ) == ".cs" ) . OrderBy ( x => x ) . ToList ( ) ;
372+
373+ // Assert
374+ string expectedFile = Assert . Single ( files ) ;
375+ Assert . Equivalent ( expectedFiles , files ) ;
376+
377+ Assert . Equal ( string . Join ( Environment . NewLine , expectedToWrite ) + Environment . NewLine , File . ReadAllText ( expectedFile ) ) ;
378+ }
379+
237380 [ Fact ]
238381 public void UpdateChapterListingNumbers_ListingsWithinListMissing_ListingsRenumbered ( )
239382 {
0 commit comments