Skip to content

Commit 1524ef0

Browse files
committed
Small change to AsContainer
Small change to AsContainer. Avoid double checking with "is" and then "as". Do a Cast and then check on null. The Check for WindowsFramework.Wpf is moved to UIItem.cs
1 parent 1b023ef commit 1524ef0

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/TestStack.White/UIItems/UIItem.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public virtual bool Visible
201201
/// <returns></returns>
202202
public virtual string ErrorProviderMessage(Window window)
203203
{
204-
AutomationElement element =
204+
var element =
205205
AutomationElement.FromPoint(automationElement.Current.BoundingRectangle.ImmediateExteriorEast());
206206
if (element == null) return null;
207-
Rect errorProviderBounds = element.Current.BoundingRectangle;
207+
var errorProviderBounds = element.Current.BoundingRectangle;
208208
if (automationElement.Current.BoundingRectangle.Right != errorProviderBounds.Left) return null;
209209
mouse.Location = errorProviderBounds.Center();
210210
actionListener.ActionPerformed(Action.WindowMessage);
@@ -421,8 +421,16 @@ protected virtual void EnterData(string value)
421421
}
422422
}
423423

424-
internal virtual IUIItemContainer AsContainer()
424+
/// <summary>
425+
/// Make an <see cref="IUIItemContainer"/> out of the <see cref="IUIItem"/>
426+
/// </summary>
427+
/// <returns>Returns an <c><see cref="IUIItemContainer"/></c> if possibe</returns>
428+
public virtual IUIItemContainer AsContainer()
425429
{
430+
if (Framework != WindowsFramework.Wpf)
431+
{
432+
Logger.Warn("Only WPF items should be treated as container items");
433+
}
426434
return new UIItemContainer(AutomationElement, ActionListener);
427435
}
428436

src/TestStack.White/UIItems/WPFUIItems/WPFUIItem.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Castle.Core.Logging;
2-
using TestStack.White.Configuration;
31
using TestStack.White.UIItems.Finders;
42

53
namespace TestStack.White.UIItems.WPFUIItems
@@ -9,8 +7,6 @@ namespace TestStack.White.UIItems.WPFUIItems
97
/// </summary>
108
public static class WPFUIItem
119
{
12-
static readonly ILogger Logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof (WPFUIItem));
13-
1410
#region Get Single UI Item
1511

1612
/// <summary>
@@ -143,15 +139,12 @@ public static bool Exists(this IUIItem uiItem, SearchCriteria searchCriteria)
143139

144140
private static IUIItemContainer GetUiItemContainer(IUIItem uiItem)
145141
{
146-
if (!(uiItem is UIItem))
142+
var item = uiItem as UIItem;
143+
if (item == null)
147144
{
148145
throw new WhiteException("Cannot get UI Item container, uiItem must be an instance of UIItem");
149146
}
150-
if (uiItem.Framework != WindowsFramework.Wpf)
151-
{
152-
Logger.Warn("Only WPF items should be treated as container items");
153-
}
154-
return ((UIItem) uiItem).AsContainer();
147+
return item.AsContainer();
155148
}
156149

157150
#endregion

0 commit comments

Comments
 (0)