@@ -59,6 +59,132 @@ public void TestWriteAndReadLines()
5959 Assert . Equal ( contents [ i ] , read [ i ] ) ;
6060 }
6161
62+ [ Fact ]
63+ public void TestAppendToNewFileAndReadText ( )
64+ {
65+ const string file = "./testdata/Text.txt" ;
66+ const string contents = "This is a test" ;
67+
68+ context . CakeContext . FileAppendText ( file , contents ) ;
69+
70+ var read = context . CakeContext . FileReadText ( file ) ;
71+
72+ Assert . Equal ( contents , read ) ;
73+ }
74+
75+ [ Fact ]
76+ public void TestAppendToExistingFileAndReadText ( )
77+ {
78+ const string file = "./testdata/Text.txt" ;
79+ const string contents1 = "This is " ;
80+ const string contents2 = "a test" ;
81+
82+ context . CakeContext . FileAppendText ( file , contents1 ) ;
83+ context . CakeContext . FileAppendText ( file , contents2 ) ;
84+
85+ var read = context . CakeContext . FileReadText ( file ) ;
86+
87+ Assert . Equal ( contents1 + contents2 , read ) ;
88+ }
89+
90+ [ Fact ]
91+ public void TestAppendToNewFileAndReadTextWithUTF8Encoding ( )
92+ {
93+ const string file = "./testdata/Text.txt" ;
94+ const string contents = "Monkey🐒" ;
95+
96+ context . CakeContext . FileAppendText ( file , Encoding . UTF8 , contents ) ;
97+
98+ var read = context . CakeContext . FileReadText ( file , Encoding . UTF8 ) ;
99+
100+ Assert . Equal ( contents , read ) ;
101+ }
102+
103+ [ Fact ]
104+ public void TestAppendToExistingFileAndReadTextWithUTF8Encoding ( )
105+ {
106+ const string file = "./testdata/Text.txt" ;
107+ const string contents1 = "Monkey" ;
108+ const string contents2 = "🐒" ;
109+
110+ context . CakeContext . FileAppendText ( file , Encoding . UTF8 , contents1 ) ;
111+ context . CakeContext . FileAppendText ( file , Encoding . UTF8 , contents2 ) ;
112+
113+ var read = context . CakeContext . FileReadText ( file , Encoding . UTF8 ) ;
114+
115+ Assert . Equal ( contents1 + contents2 , read ) ;
116+ }
117+
118+ [ Fact ]
119+ public void TestAppendLinesToNewFileAndReadLines ( )
120+ {
121+ const string file = "./testdata/Text.txt" ;
122+ var contents = new [ ] { "This" , "is" , "a" , "test" } ;
123+
124+ context . CakeContext . FileAppendLines ( file , contents ) ;
125+
126+ var read = context . CakeContext . FileReadLines ( file ) ;
127+
128+ Assert . Equal ( contents . Length , read . Length ) ;
129+
130+ for ( int i = 0 ; i < read . Length ; i ++ )
131+ Assert . Equal ( contents [ i ] , read [ i ] ) ;
132+ }
133+
134+ [ Fact ]
135+ public void TestAppendLinesToExistingFileAndReadLines ( )
136+ {
137+ const string file = "./testdata/Text.txt" ;
138+ var contents = new [ ] { "This" , "is" , "a" , "test" } ;
139+ var contents1 = new [ ] { contents [ 0 ] , contents [ 1 ] } ;
140+ var contents2 = new [ ] { contents [ 2 ] , contents [ 3 ] } ;
141+
142+ context . CakeContext . FileAppendLines ( file , contents1 ) ;
143+ context . CakeContext . FileAppendLines ( file , contents2 ) ;
144+
145+ var read = context . CakeContext . FileReadLines ( file ) ;
146+
147+ Assert . Equal ( contents . Length , read . Length ) ;
148+
149+ for ( int i = 0 ; i < read . Length ; i ++ )
150+ Assert . Equal ( contents [ i ] , read [ i ] ) ;
151+ }
152+
153+ [ Fact ]
154+ public void TestAppendLinesToNewFileAndReadLinesWithUTF8Encoding ( )
155+ {
156+ const string file = "./testdata/Text.txt" ;
157+ var contents = new [ ] { "This is a test" , "Monkey🐒" } ;
158+
159+ context . CakeContext . FileAppendLines ( file , Encoding . UTF8 , contents ) ;
160+
161+ var read = context . CakeContext . FileReadLines ( file , Encoding . UTF8 ) ;
162+
163+ Assert . Equal ( contents . Length , read . Length ) ;
164+
165+ for ( int i = 0 ; i < read . Length ; i ++ )
166+ Assert . Equal ( contents [ i ] , read [ i ] ) ;
167+ }
168+
169+ [ Fact ]
170+ public void TestAppendLinesToExistingFileAndReadLinesWithUTF8Encoding ( )
171+ {
172+ const string file = "./testdata/Text.txt" ;
173+ var contents = new [ ] { "This is a test" , "Monkey🐒" } ;
174+ var contents1 = new [ ] { contents [ 0 ] } ;
175+ var contents2 = new [ ] { contents [ 1 ] } ;
176+
177+ context . CakeContext . FileAppendLines ( file , Encoding . UTF8 , contents1 ) ;
178+ context . CakeContext . FileAppendLines ( file , Encoding . UTF8 , contents2 ) ;
179+
180+ var read = context . CakeContext . FileReadLines ( file , Encoding . UTF8 ) ;
181+
182+ Assert . Equal ( contents . Length , read . Length ) ;
183+
184+ for ( int i = 0 ; i < read . Length ; i ++ )
185+ Assert . Equal ( contents [ i ] , read [ i ] ) ;
186+ }
187+
62188 [ Fact ]
63189 public void FindTextInFilesGlob ( )
64190 {
0 commit comments