Skip to content

Commit 8a961cc

Browse files
authored
Merge pull request #20 from dotnet-campus/t/lindexi/UITest
加入界面单元测试
2 parents 4cea870 + d14b2d1 commit 8a961cc

File tree

19 files changed

+404
-21
lines changed

19 files changed

+404
-21
lines changed

.github/workflows/dotnet-build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
- name: Checkout
1717
uses: actions/checkout@v2
1818

19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: |
23+
3.1.x
24+
5.0.x
25+
6.0.x
26+
1927
- name: Build
2028
run: dotnet build --configuration $env:Configuration
2129
env:

.github/workflows/nuget-push.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ jobs:
1212
- name: Checkout
1313
uses: actions/checkout@v2
1414

15+
- name: Setup .NET
16+
uses: actions/setup-dotnet@v1
17+
with:
18+
dotnet-version: |
19+
3.1.x
20+
5.0.x
21+
6.0.x
22+
1523
- name: Install tool
1624
run: dotnet tool install -g dotnetCampus.TagToVersion
1725

MSTest.Extensions.sln

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2026
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSTest.Extensions", "src\MSTest.Extensions\MSTest.Extensions.csproj", "{055E6C63-3CC7-427E-B14F-69C85D7E971A}"
77
EndProject
@@ -19,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_Solution
1919
LICENSE = LICENSE
2020
EndProjectSection
2121
EndProject
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.UITest.WPF", "src\dotnetCampus.UITest.WPF\dotnetCampus.UITest.WPF.csproj", "{E62C4947-CD69-411D-8749-78C8B2C25ACE}"
23+
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.UITest.WPF.Demo", "demo\dotnetCampus.UITest.WPF.Demo\dotnetCampus.UITest.WPF.Demo.csproj", "{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF}"
25+
EndProject
2226
Global
2327
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2428
Debug|Any CPU = Debug|Any CPU
@@ -33,13 +37,23 @@ Global
3337
{7AB54453-67E4-46BC-A314-EBA72C082E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3438
{7AB54453-67E4-46BC-A314-EBA72C082E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3539
{7AB54453-67E4-46BC-A314-EBA72C082E7E}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{E62C4947-CD69-411D-8749-78C8B2C25ACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{E62C4947-CD69-411D-8749-78C8B2C25ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{E62C4947-CD69-411D-8749-78C8B2C25ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{E62C4947-CD69-411D-8749-78C8B2C25ACE}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF}.Release|Any CPU.Build.0 = Release|Any CPU
3648
EndGlobalSection
3749
GlobalSection(SolutionProperties) = preSolution
3850
HideSolutionNode = FALSE
3951
EndGlobalSection
4052
GlobalSection(NestedProjects) = preSolution
4153
{055E6C63-3CC7-427E-B14F-69C85D7E971A} = {1C4D72B5-A7C1-4AAE-A66F-4DDAC5979C28}
4254
{7AB54453-67E4-46BC-A314-EBA72C082E7E} = {DA39C42F-B4EA-43F0-AB8C-40987B63F4D6}
55+
{E62C4947-CD69-411D-8749-78C8B2C25ACE} = {1C4D72B5-A7C1-4AAE-A66F-4DDAC5979C28}
56+
{F1D52FE3-2E23-4C7D-AA64-CAC204B4EBBF} = {DA39C42F-B4EA-43F0-AB8C-40987B63F4D6}
4357
EndGlobalSection
4458
GlobalSection(ExtensibilityGlobals) = postSolution
4559
SolutionGuid = {21BFBA8A-2901-4A78-A722-0DDA95D3773F}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
[zh-chs]: /docs/zh-chs/README.zh-chs.md
77
[zh-cht]: /docs/zh-cht/README.zh-cht.md
88

9-
![.NET Build & Test](https://github.com/dotnet-campus/CUnit/workflows/.NET%20Build%20&%20Test/badge.svg) ![NuGet Push](https://github.com/dotnet-campus/CUnit/workflows/NuGet%20Push/badge.svg) [![](https://img.shields.io/nuget/v/MSTestEnhancer.svg)](https://www.nuget.org/packages/MSTestEnhancer)
9+
![.NET Build & Test](https://github.com/dotnet-campus/CUnit/workflows/.NET%20Build%20&%20Test/badge.svg) ![NuGet Push](https://github.com/dotnet-campus/CUnit/workflows/NuGet%20Push/badge.svg)
10+
11+
12+
| Name | NuGet|
13+
|--|--|
14+
|MSTestEnhancer|[![](https://img.shields.io/nuget/v/MSTestEnhancer.svg)](https://www.nuget.org/packages/MSTestEnhancer)|
15+
|dotnetCampus.UITest.WPF|[![](https://img.shields.io/nuget/v/dotnetCampus.UITest.WPF.svg)](https://www.nuget.org/packages/dotnetCampus.UITest.WPF)|
1016

1117
# CUnit
1218

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="dotnetCampus.UITest.WPF.Demo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:dotnetCampus.UITest.WPF.Demo"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace dotnetCampus.UITest.WPF.Demo
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Reflection;
2+
using System.Threading.Tasks;
3+
using System.Windows;
4+
using System.Windows.Threading;
5+
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
using MSTest.Extensions.Contracts;
9+
using MSTest.Extensions.Utils;
10+
11+
namespace dotnetCampus.UITest.WPF.Demo
12+
{
13+
[TestClass]
14+
public class FooTest
15+
{
16+
[AssemblyInitialize]
17+
public static void InitializeApplication(TestContext testContext)
18+
{
19+
UITestManager.InitializeApplication(() => new App());
20+
}
21+
22+
[UIContractTestCase]
23+
public void TestAsyncLoad()
24+
{
25+
"Waiting with async Loaded, then it do not lock UI Thread.".Test(async () =>
26+
{
27+
var mainWindow = new MainWindow();
28+
var taskCompletionSource = new TaskCompletionSource();
29+
mainWindow.Loaded += (sender, args) => taskCompletionSource.SetResult();
30+
await mainWindow.Dispatcher.InvokeAsync(mainWindow.Show);
31+
await taskCompletionSource.Task;
32+
});
33+
}
34+
35+
[UIContractTestCase]
36+
public void TestMainWindow()
37+
{
38+
"Test Open MainWindow, MainWindow be opened".Test(() =>
39+
{
40+
Assert.AreEqual(Application.Current.Dispatcher, Dispatcher.CurrentDispatcher);
41+
var mainWindow = new MainWindow();
42+
bool isMainWindowLoaded = false;
43+
mainWindow.Loaded += (sender, args) => isMainWindowLoaded = true;
44+
mainWindow.Show();
45+
Assert.AreEqual(true, isMainWindowLoaded);
46+
});
47+
48+
"Test Close MainWindow, MainWindow be closed".Test(() =>
49+
{
50+
var window = Application.Current.MainWindow;
51+
Assert.AreEqual(true, window is MainWindow);
52+
bool isMainWindowClosed = false;
53+
Assert.IsNotNull(window);
54+
window.Closed += (sender, args) => isMainWindowClosed = true;
55+
window.Close();
56+
Assert.AreEqual(true, isMainWindowClosed);
57+
});
58+
}
59+
}
60+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Window x:Class="dotnetCampus.UITest.WPF.Demo.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:dotnetCampus.UITest.WPF.Demo"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<Grid>
10+
11+
</Grid>
12+
</Window>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace dotnetCampus.UITest.WPF.Demo
17+
{
18+
/// <summary>
19+
/// Interaction logic for MainWindow.xaml
20+
/// </summary>
21+
public partial class MainWindow : Window
22+
{
23+
public MainWindow()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)