@@ -148,7 +148,7 @@ public void SwitchStream(Version version, int subStorageCount)
148
148
[ DataRow ( Version . V4 , 1 ) ]
149
149
[ DataRow ( Version . V4 , 2 ) ]
150
150
[ DataRow ( Version . V4 , 32 ) ] // Required 2 sectors including root
151
- public void SwitchFile ( Version version , int subStorageCount )
151
+ public void SwitchToFile ( Version version , int subStorageCount )
152
152
{
153
153
string fileName = Path . GetTempFileName ( ) ;
154
154
@@ -177,6 +177,52 @@ public void SwitchFile(Version version, int subStorageCount)
177
177
}
178
178
}
179
179
180
+ [ TestMethod ]
181
+ [ DataRow ( Version . V3 , 0 ) ]
182
+ [ DataRow ( Version . V3 , 1 ) ]
183
+ [ DataRow ( Version . V3 , 2 ) ]
184
+ [ DataRow ( Version . V3 , 4 ) ]
185
+ [ DataRow ( Version . V4 , 0 ) ]
186
+ [ DataRow ( Version . V4 , 1 ) ]
187
+ [ DataRow ( Version . V4 , 2 ) ]
188
+ [ DataRow ( Version . V4 , 4 ) ]
189
+ public void SwitchToWritableStream ( Version version , int streamCount )
190
+ {
191
+ string fileName = Path . GetTempFileName ( ) ;
192
+
193
+ var data = TestData . CreateByteArray ( 1024 ) ;
194
+
195
+ try
196
+ {
197
+ using ( var rootStorage = RootStorage . CreateInMemory ( version ) )
198
+ {
199
+ for ( int i = 0 ; i < streamCount ; i ++ )
200
+ {
201
+ using CfbStream stream = rootStorage . CreateStream ( $ "Test{ i } ") ;
202
+ stream . Write ( data , 0 , data . Length ) ;
203
+ }
204
+
205
+ rootStorage . SwitchTo ( fileName ) ;
206
+ }
207
+
208
+ using MemoryStream memoryStream = new ( ) ;
209
+ using ( var rootStorage = RootStorage . OpenRead ( fileName ) )
210
+ {
211
+ rootStorage . SwitchTo ( memoryStream ) ;
212
+
213
+ IEnumerable < EntryInfo > entries = rootStorage . EnumerateEntries ( ) ;
214
+ Assert . AreEqual ( streamCount , entries . Count ( ) ) ;
215
+
216
+ for ( int i = 0 ; i < streamCount ; i ++ )
217
+ rootStorage . Delete ( $ "Test{ i } ") ;
218
+ }
219
+ }
220
+ finally
221
+ {
222
+ try { File . Delete ( fileName ) ; } catch { }
223
+ }
224
+ }
225
+
180
226
[ TestMethod ]
181
227
[ DataRow ( Version . V3 , 0 ) ]
182
228
[ DataRow ( Version . V3 , 1 ) ]