Skip to content

Commit 0076a73

Browse files
committed
Moved KeepOpenOnDispose to Configuration
1 parent 43fe94e commit 0076a73

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

src/TestStack.White/Application.cs

+1-14
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public class Application : IDisposable
2424
private readonly WindowFactory windowFactory;
2525
private static readonly ILogger Logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(Application));
2626

27-
/// <summary>
28-
/// Flag to indicate to keep the application open when disposing the object
29-
/// </summary>
30-
public virtual bool KeepOpenOnDispose { get; set; }
31-
3227
protected Application()
3328
{
3429
}
@@ -288,7 +283,7 @@ public override int GetHashCode()
288283

289284
public virtual void Dispose()
290285
{
291-
if (!KeepOpenOnDispose)
286+
if (!CoreAppXmlConfiguration.Instance.KeepOpenOnDispose)
292287
{
293288
Kill();
294289
}
@@ -335,13 +330,5 @@ public virtual void KillAndSaveState()
335330
Kill();
336331
ApplicationSession.Save();
337332
}
338-
339-
/// <summary>
340-
/// Detaches from the current attached process
341-
/// </summary>
342-
public virtual void Detach()
343-
{
344-
KeepOpenOnDispose = true;
345-
}
346333
}
347334
}

src/TestStack.White/Configuration/CoreAppXmlConfiguration.cs

+44-36
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ namespace TestStack.White.Configuration
1111
{
1212
public class CoreAppXmlConfiguration : AssemblyConfiguration, ICoreConfiguration
1313
{
14-
private static ICoreConfiguration instance;
14+
private static ICoreConfiguration instance = new CoreAppXmlConfiguration();
1515
private readonly DynamicProxyInterceptors interceptors = new DynamicProxyInterceptors();
16-
1716
private static readonly Dictionary<string, object> DefaultValues = new Dictionary<string, object>();
1817

1918
static CoreAppXmlConfiguration()
@@ -35,12 +34,12 @@ static CoreAppXmlConfiguration()
3534
DefaultValues.Add("MaxElementSearchDepth", 10);
3635
DefaultValues.Add("DoubleClickInterval", 0);
3736
DefaultValues.Add("MoveMouseToGetStatusOfHourGlass", true);
38-
DefaultValues.Add("InvertMouseButtons", true);
37+
DefaultValues.Add("KeepOpenOnDispose", false);
3938
}
4039

4140
public static ICoreConfiguration Instance
4241
{
43-
get { return instance ?? (instance = new CoreAppXmlConfiguration()); }
42+
get { return instance; }
4443
}
4544

4645
private CoreAppXmlConfiguration()
@@ -51,15 +50,32 @@ private CoreAppXmlConfiguration()
5150
LoggerFactory = new WhiteDefaultLoggerFactory(LoggerLevel.Info);
5251
}
5352

53+
public virtual ILoggerFactory LoggerFactory { get; set; }
54+
55+
public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)
56+
{
57+
var existing = new Dictionary<string, string>(UsedValues);
58+
changes(this);
59+
60+
return new DelegateDisposable(() =>
61+
{
62+
foreach (var value in existing)
63+
{
64+
SetUsedValue(value.Key, value.Value);
65+
}
66+
});
67+
}
68+
5469
private void SetUsedValue(string key, object value)
5570
{
5671
UsedValues[key] = value.ToString();
5772
}
5873

59-
public virtual DirectoryInfo WorkSessionLocation
74+
public virtual IWaitHook AdditionalWaitHook { get; set; }
75+
76+
public virtual DynamicProxyInterceptors Interceptors
6077
{
61-
get { return new DirectoryInfo(UsedValues["WorkSessionLocation"]); }
62-
set { SetUsedValue("WorkSessionLocation", value); }
78+
get { return interceptors; }
6379
}
6480

6581
public virtual int BusyTimeout
@@ -80,9 +96,10 @@ public virtual bool WaitBasedOnHourGlass
8096
set { SetUsedValue("WaitBasedOnHourGlass", value); }
8197
}
8298

83-
public virtual DynamicProxyInterceptors Interceptors
99+
public virtual DirectoryInfo WorkSessionLocation
84100
{
85-
get { return interceptors; }
101+
get { return new DirectoryInfo(UsedValues["WorkSessionLocation"]); }
102+
set { SetUsedValue("WorkSessionLocation", value); }
86103
}
87104

88105
public virtual int UIAutomationZeroWindowBugTimeout
@@ -139,46 +156,37 @@ public virtual bool ComboBoxItemsPopulatedWithoutDropDownOpen
139156
set { SetUsedValue("ComboBoxItemsPopulatedWithoutDropDownOpen", value); }
140157
}
141158

142-
public virtual bool MoveMouseToGetStatusOfHourGlass
143-
{
144-
get { return Convert.ToBoolean(UsedValues["MoveMouseToGetStatusOfHourGlass"]); }
145-
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
146-
}
147-
148-
public virtual ILoggerFactory LoggerFactory { get; set; }
149-
150-
public virtual IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes)
159+
public virtual bool RawElementBasedSearch
151160
{
152-
var existing = new Dictionary<string, string>(UsedValues);
153-
changes(this);
154-
155-
return new DelegateDisposable(() =>
156-
{
157-
foreach (var value in existing)
158-
{
159-
SetUsedValue(value.Key, value.Value);
160-
}
161-
});
161+
get { return Convert.ToBoolean(UsedValues["RawElementBasedSearch"]); }
162+
set { SetUsedValue("RawElementBasedSearch", value); }
162163
}
163164

164-
public virtual IWaitHook AdditionalWaitHook { get; set; }
165-
166165
public virtual int MaxElementSearchDepth
167166
{
168167
get { return Convert.ToInt32(UsedValues["MaxElementSearchDepth"]); }
169168
set { SetUsedValue("MaxElementSearchDepth", value); }
170169
}
171170

172-
public virtual bool RawElementBasedSearch
173-
{
174-
get { return Convert.ToBoolean(UsedValues["RawElementBasedSearch"]); }
175-
set { SetUsedValue("RawElementBasedSearch", value); }
176-
}
177-
178171
public virtual int DoubleClickInterval
179172
{
180173
get { return Convert.ToInt32(UsedValues["DoubleClickInterval"]); }
181174
set { SetUsedValue("DoubleClickInterval", value); }
182175
}
176+
177+
public virtual bool MoveMouseToGetStatusOfHourGlass
178+
{
179+
get { return Convert.ToBoolean(UsedValues["MoveMouseToGetStatusOfHourGlass"]); }
180+
set { SetUsedValue("MoveMouseToGetStatusOfHourGlass", value); }
181+
}
182+
183+
/// <summary>
184+
/// Implements <see cref="ICoreConfiguration.KeepOpenOnDispose"/>
185+
/// </summary>
186+
public virtual bool KeepOpenOnDispose
187+
{
188+
get { return Convert.ToBoolean(UsedValues["KeepOpenOnDispose"]); }
189+
set { SetUsedValue("KeepOpenOnDispose", value); }
190+
}
183191
}
184192
}

src/TestStack.White/Configuration/CoreConfiguration.cs src/TestStack.White/Configuration/ICoreConfiguration.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ namespace TestStack.White.Configuration
1111
/// </summary>
1212
public interface ICoreConfiguration
1313
{
14+
ILoggerFactory LoggerFactory { get; set; }
15+
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
16+
IWaitHook AdditionalWaitHook { get; set; }
17+
DynamicProxyInterceptors Interceptors { get; }
18+
1419
/// <summary>
1520
/// In Milliseconds
1621
/// </summary>
1722
int BusyTimeout { get; set; }
1823
int FindWindowTimeout { get; set; }
1924
bool WaitBasedOnHourGlass { get; set; }
20-
DynamicProxyInterceptors Interceptors { get; }
2125
DirectoryInfo WorkSessionLocation { get; set; }
2226
int UIAutomationZeroWindowBugTimeout { get; set; }
2327
int PopupTimeout { get; set; }
@@ -28,12 +32,14 @@ public interface ICoreConfiguration
2832
int DragStepCount { get; set; }
2933
bool InProc { get; set; }
3034
bool ComboBoxItemsPopulatedWithoutDropDownOpen { get; set; }
31-
IWaitHook AdditionalWaitHook { get; set; }
32-
int MaxElementSearchDepth { get; set; }
3335
bool RawElementBasedSearch { get; set; }
36+
int MaxElementSearchDepth { get; set; }
3437
int DoubleClickInterval { get; set; }
3538
bool MoveMouseToGetStatusOfHourGlass { get; set; }
36-
ILoggerFactory LoggerFactory { get; set; }
37-
IDisposable ApplyTemporarySetting(Action<ICoreConfiguration> changes);
39+
/// <summary>
40+
/// Flag to allow keeping the <see cref="TestStack.White.Application"/> and <see cref="TestStack.White.UIItems.WindowItems.Window" />
41+
/// open after White has disposed it's objects.
42+
/// </summary>
43+
bool KeepOpenOnDispose { get;set;}
3844
}
3945
}

src/TestStack.White/TestStack.White.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<Compile Include="AutomationException.cs" />
112112
<Compile Include="CacheMode.cs" />
113113
<Compile Include="Configuration\CoreAppXmlConfiguration.cs" />
114-
<Compile Include="Configuration\CoreConfiguration.cs" />
114+
<Compile Include="Configuration\ICoreConfiguration.cs" />
115115
<Compile Include="Configuration\IWaitHook.cs" />
116116
<Compile Include="Configuration\UIItemIdAppXmlConfiguration.cs" />
117117
<Compile Include="Configuration\UIItemIdConfiguration.cs" />

src/TestStack.White/UIItems/WindowItems/Window.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public abstract class Window : UIItemContainer, IDisposable
4343

4444
public delegate bool WaitTillDelegate();
4545

46-
/// <summary>
47-
/// Flag to indicate to keep the window open when disposing the object
48-
/// </summary>
49-
public virtual bool KeepOpenOnDispose { get; set; }
50-
5146
static Window()
5247
{
5348
WindowStates.Add(DisplayState.Maximized, WindowVisualState.Maximized);
@@ -370,7 +365,7 @@ public override string ToString()
370365

371366
public virtual void Dispose()
372367
{
373-
if (!KeepOpenOnDispose)
368+
if (!CoreAppXmlConfiguration.Instance.KeepOpenOnDispose)
374369
{
375370
Close();
376371
}

0 commit comments

Comments
 (0)