Skip to content

Commit cde5aa9

Browse files
committed
Modify NUnitlite to enable run in non-privileged.
1 parent c8e9be0 commit cde5aa9

4 files changed

Lines changed: 82 additions & 25 deletions

File tree

test/NUnitLite/NUnitFramework/framework/Env.cs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// ***********************************************************************
2323

2424
using System;
25+
using System.Runtime.CompilerServices;
26+
using System.Security;
2527
using System.Text;
2628

2729
namespace NUnit
@@ -47,18 +49,56 @@ public class Env
4749
/// <summary>
4850
/// Path to the 'My Documents' folder
4951
/// </summary>
50-
#if PocketPC || WindowsCE || NETCF || PORTABLE
51-
public static string DocumentFolder = @"\My Documents";
52-
#else
53-
public static string DocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
54-
#endif
52+
public static string DocumentFolder = GetDocumentFolder();
53+
5554
/// <summary>
5655
/// Directory used for file output if not specified on commandline.
5756
/// </summary>
58-
#if SILVERLIGHT || PocketPC || WindowsCE || NETCF || PORTABLE
59-
public static readonly string DefaultWorkDirectory = DocumentFolder;
57+
public static readonly string DefaultWorkDirectory = GetDefaultWorkDirectory();
58+
59+
private static string GetDocumentFolder()
60+
{
61+
try
62+
{
63+
return GetDocumentFolderCore();
64+
}
65+
catch ( SecurityException )
66+
{
67+
// For restricted Silverlight environment.
68+
return null;
69+
}
70+
}
71+
72+
[MethodImpl(MethodImplOptions.NoInlining)]
73+
private static string GetDocumentFolderCore()
74+
{
75+
#if PocketPC || WindowsCE || NETCF || PORTABLE
76+
return @"\My Documents";
77+
#else
78+
return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
79+
#endif
80+
}
81+
private static string GetDefaultWorkDirectory()
82+
{
83+
try
84+
{
85+
return GetDefaultWorkDirectoryCore();
86+
}
87+
catch ( SecurityException )
88+
{
89+
// For restricted Silverlight environment.
90+
return null;
91+
}
92+
}
93+
94+
[MethodImpl( MethodImplOptions.NoInlining )]
95+
private static string GetDefaultWorkDirectoryCore()
96+
{
97+
#if PocketPC || WindowsCE || NETCF || PORTABLE
98+
return @"\My Documents";
6099
#else
61-
public static readonly string DefaultWorkDirectory = Environment.CurrentDirectory;
100+
return Environment.GetFolderPath( Environment.SpecialFolder.Personal );
62101
#endif
102+
}
63103
}
64104
}

test/NUnitLite/NUnitFramework/framework/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/NUnitLite/NUnitFramework/nunitlite/CommandLineOptions.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
using System;
2525
using System.Collections.Generic;
2626
using System.IO;
27+
using System.Runtime.CompilerServices;
28+
using System.Security;
29+
2730
using NUnit.Options;
2831

2932
namespace NUnit.Common
@@ -39,14 +42,7 @@ namespace NUnit.Common
3942
/// </summary>
4043
public class CommandLineOptions : OptionSet
4144
{
42-
private static readonly string DEFAULT_WORK_DIRECTORY =
43-
#if NETCF || PORTABLE
44-
@"\My Documents";
45-
#elif SILVERLIGHT
46-
Environment.GetFolderPath(Environment.SpecialFolder.Personal);
47-
#else
48-
Environment.CurrentDirectory;
49-
#endif
45+
private static readonly string DEFAULT_WORK_DIRECTORY = GetDefaultWorkDirectory();
5046

5147
private bool validated;
5248
#if !PORTABLE
@@ -73,10 +69,35 @@ public CommandLineOptions(params string[] args)
7369
if (args != null)
7470
Parse(args);
7571
}
76-
77-
#endregion
78-
79-
#region Properties
72+
73+
private static string GetDefaultWorkDirectory()
74+
{
75+
try
76+
{
77+
return GetDefaultWorkDirectoryCore();
78+
}
79+
catch ( SecurityException )
80+
{
81+
// For restricted Silverlight environment.
82+
return null;
83+
}
84+
}
85+
86+
[MethodImpl(MethodImplOptions.NoInlining)]
87+
private static string GetDefaultWorkDirectoryCore()
88+
{
89+
#if NETCF || PORTABLE
90+
return @"\My Documents";
91+
#elif SILVERLIGHT
92+
return Environment.GetFolderPath(Environment.SpecialFolder.Personal);
93+
#else
94+
return Environment.CurrentDirectory;
95+
#endif
96+
}
97+
98+
#endregion
99+
100+
#region Properties
80101

81102
// Action to Perform
82103

test/NUnitLite/NUnitFramework/nunitlite/Silverlight/TextBlockWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public override void WriteLabelLine(string label, object option)
175175
public override void WriteLabel(string label, object option, ColorStyle valueStyle)
176176
{
177177
Write(ColorStyle.Label, label);
178-
Write(valueStyle, option.ToString());
178+
Write(valueStyle, option == null ? "<null>" : option.ToString());
179179
}
180180

181181
/// <summary>

0 commit comments

Comments
 (0)