forked from MahApps/MahApps.Metro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(MahAppsGH-3376) Use IClassFixture for NumericUpDown tests
- Loading branch information
Showing
2 changed files
with
179 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Controls.Primitives; | ||
using MahApps.Metro.Controls; | ||
using MahApps.Metro.Tests.TestHelpers; | ||
using Xunit; | ||
|
||
namespace MahApps.Metro.Tests | ||
{ | ||
public class NumericUpDownFixture : IAsyncLifetime | ||
{ | ||
public NumericUpDownWindow Window { get; private set; } | ||
|
||
public TextBox TextBox { get; private set; } | ||
|
||
public RepeatButton NumUp { get; private set; } | ||
|
||
public RepeatButton NumDown { get; private set; } | ||
|
||
/// <summary> | ||
/// Called immediately after the class has been created, before it is used. | ||
/// </summary> | ||
public async Task InitializeAsync() | ||
{ | ||
await TestHost.SwitchToAppThread(); | ||
|
||
this.Window = await WindowHelpers.CreateInvisibleWindowAsync<NumericUpDownWindow>().ConfigureAwait(false); | ||
this.TextBox = this.Window.TheNUD.FindChild<TextBox>(); | ||
this.NumUp = this.Window.TheNUD.FindChild<RepeatButton>("PART_NumericUp"); | ||
this.NumDown = this.Window.TheNUD.FindChild<RepeatButton>("PART_NumericDown"); | ||
} | ||
|
||
public static IEnumerable<DependencyProperty> EnumerateDependencyProperties(DependencyObject obj) | ||
{ | ||
if (obj != null) | ||
{ | ||
LocalValueEnumerator lve = obj.GetLocalValueEnumerator(); | ||
while (lve.MoveNext()) | ||
{ | ||
yield return lve.Current.Property; | ||
} | ||
} | ||
} | ||
|
||
public async Task PrepareForTestAsync() | ||
{ | ||
await TestHost.SwitchToAppThread(); | ||
|
||
foreach (var property in EnumerateDependencyProperties(this.Window.TheNUD)) | ||
{ | ||
this.Window.TheNUD.ClearValue(property); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Called when an object is no longer needed. Called just before <see cref="M:System.IDisposable.Dispose" /> | ||
/// if the class also implements that. | ||
/// </summary> | ||
public Task DisposeAsync() | ||
{ | ||
this.TextBox = null; | ||
this.NumUp = null; | ||
this.NumDown = null; | ||
this.Window = null; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters