@@ -22,8 +22,23 @@ public sealed class JsonFileServiceTests
2222{
2323 private static JsonFileService ? _jsonFileService ;
2424
25+ [ ClassInitialize ]
26+ public static void ClassInitialize ( TestContext context )
27+ {
28+ var configPath = Path . Combine ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config.json" ) ) ;
29+ var configAsyncPath = Path . Combine ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config-async.json" ) ) ;
30+ if ( File . Exists ( configPath ) )
31+ {
32+ File . Delete ( configPath ) ;
33+ }
34+ if ( File . Exists ( configAsyncPath ) )
35+ {
36+ File . Delete ( configAsyncPath ) ;
37+ }
38+ }
39+
2540 [ TestMethod ]
26- public void Case001_Initalize ( )
41+ public void Case001_Initialize ( )
2742 {
2843 _jsonFileService = new JsonFileService ( Directory . GetCurrentDirectory ( ) ) ;
2944 Assert . IsNotNull ( _jsonFileService ) ;
@@ -38,7 +53,7 @@ public void Case002_Load()
3853 Assert . IsFalse ( config . DarkModeEnabled ) ;
3954 Assert . AreEqual ( 900 , config . WindowGeometry . Width ) ;
4055 Assert . AreEqual ( 700 , config . WindowGeometry . Height ) ;
41- Assert . IsFalse ( File . Exists ( "config.json" ) ) ;
56+ Assert . IsFalse ( File . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config.json" ) ) ) ;
4257 }
4358
4459 [ TestMethod ]
@@ -50,7 +65,7 @@ public async Task Case003_LoadAsync()
5065 Assert . IsFalse ( configAsync . DarkModeEnabled ) ;
5166 Assert . AreEqual ( 900 , configAsync . WindowGeometry . Width ) ;
5267 Assert . AreEqual ( 700 , configAsync . WindowGeometry . Height ) ;
53- Assert . IsFalse ( File . Exists ( "config-async.json" ) ) ;
68+ Assert . IsFalse ( File . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config-async.json" ) ) ) ;
5469 }
5570
5671 [ TestMethod ]
@@ -61,7 +76,7 @@ public void Case004_Change()
6176 config . DarkModeEnabled = true ;
6277 Assert . IsTrue ( config . DarkModeEnabled ) ;
6378 Assert . IsTrue ( _jsonFileService . Save ( config ) ) ;
64- Assert . IsTrue ( File . Exists ( "config.json" ) ) ;
79+ Assert . IsTrue ( File . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config.json" ) ) ) ;
6580 }
6681
6782 [ TestMethod ]
@@ -72,7 +87,7 @@ public async Task Case005_ChangeAsync()
7287 configAsync . DarkModeEnabled = true ;
7388 Assert . IsTrue ( configAsync . DarkModeEnabled ) ;
7489 Assert . IsTrue ( await _jsonFileService . SaveAsync ( configAsync , "config-async" ) ) ;
75- Assert . IsTrue ( File . Exists ( "config-async.json" ) ) ;
90+ Assert . IsTrue ( File . Exists ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config-async.json" ) ) ) ;
7691 }
7792
7893 [ TestMethod ]
@@ -96,15 +111,17 @@ public async Task Case007_VerifyAsync()
96111 [ TestMethod ]
97112 public void Case008_Cleanup ( )
98113 {
99- if ( File . Exists ( "config.json" ) )
114+ var configPath = Path . Combine ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config.json" ) ) ;
115+ var configAsyncPath = Path . Combine ( Path . Combine ( Directory . GetCurrentDirectory ( ) , "config-async.json" ) ) ;
116+ if ( File . Exists ( configPath ) )
100117 {
101- File . Delete ( "config.json" ) ;
118+ File . Delete ( configPath ) ;
102119 }
103- if ( File . Exists ( "config-async.json" ) )
120+ if ( File . Exists ( configAsyncPath ) )
104121 {
105- File . Delete ( "config-async.json" ) ;
122+ File . Delete ( configAsyncPath ) ;
106123 }
107- Assert . IsFalse ( File . Exists ( "config.json" ) ) ;
108- Assert . IsFalse ( File . Exists ( "config-async.json" ) ) ;
124+ Assert . IsFalse ( File . Exists ( configPath ) ) ;
125+ Assert . IsFalse ( File . Exists ( configAsyncPath ) ) ;
109126 }
110127}
0 commit comments