re-implement hide of nuget api key in build logs, add more tests for it
[teamcity/dotNetPackagesSupport.git] / nuget-extensions / nuget-tests / src / TempFilesHolder.cs
1 using System;\r
2 using System.IO;\r
3 \r
4 namespace JetBrains.TeamCity.NuGet.Tests\r
5 {\r
6   public static class TempFilesHolder\r
7   {\r
8     public static void WithTempFile(Action<string> action)\r
9     {\r
10       string tmp = Path.GetTempFileName();\r
11       try\r
12       {\r
13         action(tmp);\r
14       } finally\r
15       {\r
16         File.Delete(tmp);\r
17       }\r
18     }\r
19 \r
20     public static T WithTempDirectory<T>(Func<string, T> action)\r
21     {\r
22       string tmp = Path.GetTempFileName();\r
23       File.Delete(tmp);\r
24       Directory.CreateDirectory(tmp);\r
25       try\r
26       {\r
27         return action(tmp);\r
28       }\r
29       finally\r
30       {\r
31         Directory.Delete(tmp, true);\r
32       }\r
33     }\r
34 \r
35     public static void WithTempDirectory(Action<string> action)\r
36     {\r
37       WithTempDirectory(t =>\r
38                           {\r
39                             action(t);\r
40                             return t;\r
41                           });\r
42     }\r
43   }\r
44 }