5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 using System.Reflection;
30 namespace MonoTests.System.Configuration.Util {
32 public static class TestUtil {
34 public static void RunWithTempFile (Action<string> action)
36 var filename = Path.GetTempFileName ();
39 File.Delete (filename);
42 if (File.Exists (filename))
43 File.Delete (filename);
47 // Action<T1,T2> doesn't exist in .NET 2.0
48 public delegate void MyAction<T1,T2> (T1 t1, T2 t2);
50 public static void RunWithTempFiles (MyAction<string,string> action)
52 var file1 = Path.GetTempFileName ();
53 var file2 = Path.GetTempFileName ();
58 action (file1, file2);
60 if (File.Exists (file1))
62 if (File.Exists (file2))
67 public static string ThisDllName {
69 var asm = Assembly.GetCallingAssembly ();
70 return Path.GetFileName (asm.Location);
74 public static string ThisConfigFileName {
76 var asm = Assembly.GetCallingAssembly ();
77 var exe = Path.GetFileName (asm.Location);
78 return exe + ".config";