Dreamine.FullKit.Wpf.Tests 1.0.0.0
Dreamine.FullKit.Wpf.Tests 기능을 검증하는 자동화 테스트 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
LocatorsWpfTests.cs
이 파일의 문서화 페이지로 가기
1using System.Windows.Controls;
2using Dreamine.MVVM.Locators.Wpf;
3
5
14public sealed class LocatorsWpfTests
15{
24 [Fact]
26 {
27 RunSta(() =>
28 {
29 RegionBinder.Clear();
30 var control = new ContentControl();
31
32 RegionBinder.SetRegionName(control, "StoresRegionName_Main");
33
34 Assert.Equal("StoresRegionName_Main", RegionBinder.GetRegionName(control));
35 RegionBinder.Clear();
36 });
37 }
38
47 [Fact]
49 {
50 RunSta(() =>
51 {
52 RegionBinder.Clear();
53 var control = new ContentControl();
54 var viewModel = new SampleViewModel();
55
56 RegionBinder.SetRegionName(control, "NavigateCurrent_Main");
57 RegionBinder.SetRegionName(control, "NavigateCurrent_Secondary");
58
59 var exception = Assert.Throws<InvalidOperationException>(
60 () => RegionBinder.Navigate("NavigateCurrent_Main", viewModel));
61 Assert.Equal("Region \"NavigateCurrent_Main\" is not registered.", exception.Message);
62
63 RegionBinder.Navigate("NavigateCurrent_Secondary", viewModel);
64
65 Assert.IsType<SampleView>(control.Content);
66 RegionBinder.Clear();
67 });
68 }
69
78 [Fact]
80 {
81 RunSta(() =>
82 {
83 RegionBinder.Clear();
84
85 var exception = Assert.Throws<InvalidOperationException>(
86 () => RegionBinder.Navigate("Missing", new SampleViewModel()));
87
88 Assert.Equal("Region \"Missing\" is not registered.", exception.Message);
89 Assert.DoesNotContain("\u274c", exception.Message);
90 });
91 }
92
101 [Fact]
103 {
104 RunSta(() =>
105 {
106 RegionBinder.Clear();
107 var root = new Grid();
108 var region = new ContentControl();
109
110 RegionBinder.SetRegionName(region, "FindRegionControl_Main");
111 root.Children.Add(region);
112
113 ContentControl? found = RegionBinderHelper.FindRegionControl(root, "FindRegionControl_Main");
114
115 Assert.Same(region, found);
116 RegionBinder.Clear();
117 });
118 }
119
128 [Fact]
130 {
131 Assert.Throws<ArgumentNullException>(
132 () => RegionBinderHelper.FindRegionControl(null!, "FindRegionControl_Main"));
133 }
134
143 [Fact]
145 {
146 RunSta(() =>
147 {
148 var root = new Grid();
149
150 Assert.Throws<ArgumentException>(
151 () => RegionBinderHelper.FindRegionControl(root, ""));
152 });
153 }
154
163 [Fact]
165 {
166 RunSta(() =>
167 {
168 var viewModel = new SampleViewModel();
169
170 var view = ViewModelBinder.ResolveView(viewModel);
171
172 Assert.IsType<SampleView>(view);
173 Assert.Same(viewModel, view.DataContext);
174 });
175 }
176
193 private static void RunSta(Action action)
194 {
195 Exception? exception = null;
196 var thread = new Thread(() =>
197 {
198 try
199 {
200 action();
201 }
202 catch (Exception ex)
203 {
204 exception = ex;
205 }
206 });
207
208 thread.SetApartmentState(ApartmentState.STA);
209 thread.Start();
210 thread.Join();
211
212 if (exception is not null)
213 {
214 throw exception;
215 }
216 }
217}
218
227public sealed class SampleViewModel
228{
229}
230
239public sealed class SampleView : UserControl
240{
241}