@@ -224,6 +224,140 @@ Result:
224224<!-- endSnippet -->
225225
226226
227+ ### Create Method
228+
229+ Creates a new temporary file with optional extension and encoding.
230+
231+ <!-- snippet: TempFileCreate -->
232+ <a id =' snippet-TempFileCreate ' ></a >
233+ ``` cs
234+ using var temp = TempFile .Create ();
235+
236+ File .WriteAllText (temp , " content" );
237+
238+ // file automatically deleted here
239+ ```
240+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L620-L628 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreate ' title =' Start of snippet ' >anchor</a ></sup >
241+ <!-- endSnippet -->
242+
243+
244+ #### With Extension
245+
246+ Create a temporary file with a specific extension:
247+
248+ <!-- snippet: TempFileCreateWithExtension -->
249+ <a id =' snippet-TempFileCreateWithExtension ' ></a >
250+ ``` cs
251+ using var temp = TempFile .Create (" .txt" );
252+
253+ File .WriteAllText (temp , " content" );
254+ ```
255+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L635-L641 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateWithExtension ' title =' Start of snippet ' >anchor</a ></sup >
256+ <!-- endSnippet -->
257+
258+
259+ #### With Encoding
260+
261+ Create a temporary file with a specific text encoding and BOM:
262+
263+ <!-- snippet: TempFileCreateWithEncoding -->
264+ <a id =' snippet-TempFileCreateWithEncoding ' ></a >
265+ ``` cs
266+ using var temp = TempFile .Create (" .txt" , Encoding .UTF8 );
267+
268+ File .Exists (temp .Path );
269+ ```
270+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L649-L655 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateWithEncoding ' title =' Start of snippet ' >anchor</a ></sup >
271+ <!-- endSnippet -->
272+
273+
274+ ### CreateText Method
275+
276+ Creates a new temporary file with text content asynchronously.
277+
278+ <!-- snippet: TempFileCreateText -->
279+ <a id =' snippet-TempFileCreateText ' ></a >
280+ ``` cs
281+ using var temp = await TempFile .CreateText (" Hello, World!" );
282+
283+ var content = await File .ReadAllTextAsync (temp );
284+ Assert .Equal (" Hello, World!" , content );
285+ ```
286+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L661-L668 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateText ' title =' Start of snippet ' >anchor</a ></sup >
287+ <!-- endSnippet -->
288+
289+
290+ #### With Extension
291+
292+ <!-- snippet: TempFileCreateTextWithExtension -->
293+ <a id =' snippet-TempFileCreateTextWithExtension ' ></a >
294+ ``` cs
295+ var json = """
296+ {
297+ "name": "test",
298+ "value": 123
299+ }
300+ """ ;
301+
302+ using var temp = await TempFile .CreateText (json , " .json" );
303+
304+ var content = await File .ReadAllTextAsync (temp );
305+ Assert .Equal (json , content );
306+ ```
307+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L674-L688 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateTextWithExtension ' title =' Start of snippet ' >anchor</a ></sup >
308+ <!-- endSnippet -->
309+
310+
311+ #### With Encoding
312+
313+ Create a text file with specific encoding:
314+
315+ <!-- snippet: TempFileCreateTextWithEncoding -->
316+ <a id =' snippet-TempFileCreateTextWithEncoding ' ></a >
317+ ``` cs
318+ using var temp = await TempFile .CreateText (
319+ " Content with special chars: äöü" ,
320+ " .txt" ,
321+ Encoding .UTF8 );
322+
323+ var content = await File .ReadAllTextAsync (temp , Encoding .UTF8 );
324+ Assert .Equal (" Content with special chars: äöü" , content );
325+ ```
326+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L694-L704 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateTextWithEncoding ' title =' Start of snippet ' >anchor</a ></sup >
327+ <!-- endSnippet -->
328+
329+
330+ ### CreateBinary Method
331+
332+ Creates a new temporary file with binary content asynchronously.
333+
334+ <!-- snippet: TempFileCreateBinary -->
335+ <a id =' snippet-TempFileCreateBinary ' ></a >
336+ ``` cs
337+ byte [] data = [0x 01 , 0x 02 , 0x 03 , 0x 04 ];
338+
339+ using var temp = await TempFile .CreateBinary (data );
340+
341+ var readData = await File .ReadAllBytesAsync (temp );
342+ Assert .Equal (data , readData );
343+ ```
344+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L712-L721 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateBinary ' title =' Start of snippet ' >anchor</a ></sup >
345+ <!-- endSnippet -->
346+
347+
348+ #### With Extension
349+
350+ <!-- snippet: TempFileCreateBinaryWithExtension -->
351+ <a id =' snippet-TempFileCreateBinaryWithExtension ' ></a >
352+ ``` cs
353+ using var temp = await TempFile .CreateBinary (imageBinaryData , " .png" );
354+
355+ // Process the temporary image file
356+ ```
357+ <sup ><a href =' /src/Verify.Tests/TempFileTests.cs#L729-L735 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-TempFileCreateBinaryWithExtension ' title =' Start of snippet ' >anchor</a ></sup >
358+ <!-- endSnippet -->
359+
360+
227361### Debugging
228362
229363Given ` TempFile ` deletes the file on test completion (even failure), it can be difficult to debug what caused the failure.
0 commit comments