Dreamine.FullKit.Wpf.Tests
1.0.0.0
Dreamine.FullKit.Wpf.Tests 기능을 검증하는 자동화 테스트 프로젝트입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
ThreadingWpfTests.cs
이 파일의 문서화 페이지로 가기
1
using
System.Globalization;
2
using
System.Windows.Data;
3
using
System.Windows.Media;
4
using
Dreamine.Threading.Models;
5
using
Dreamine.Threading.Interfaces;
6
using
Dreamine.Threading.Windows.Services;
7
using
Dreamine.Threading.Wpf.Converters;
8
using
Dreamine.Threading.Wpf.Services;
9
using
Dreamine.Threading.Wpf.ViewModels;
10
using
System.Windows.Threading;
11
12
namespace
Dreamine.FullKit.Wpf.Tests.Threading
;
13
22
public
sealed
class
ThreadingWpfTests
23
{
32
[Fact]
33
public
void
ThreadConverters_MapKnownValues
()
34
{
35
var statusConverter =
new
ThreadStatusBrushConverter();
36
var priorityConverter =
new
ThreadPriorityTextConverter();
37
38
Assert.Same(Brushes.ForestGreen, statusConverter.Convert(DreamineThreadStatus.Running, typeof(Brush),
null
!, CultureInfo.InvariantCulture));
39
Assert.Same(Brushes.Crimson, statusConverter.Convert(DreamineThreadStatus.Faulted, typeof(Brush),
null
!, CultureInfo.InvariantCulture));
40
Assert.Same(Brushes.Gray, statusConverter.Convert(
"bad"
, typeof(Brush),
null
!, CultureInfo.InvariantCulture));
41
Assert.Equal(
"High"
, priorityConverter.Convert(DreamineThreadPriority.High, typeof(
string
),
null
!, CultureInfo.InvariantCulture));
42
Assert.Equal(
string
.Empty, priorityConverter.Convert(
"bad"
, typeof(
string
),
null
!, CultureInfo.InvariantCulture));
43
Assert.Same(Binding.DoNothing, priorityConverter.ConvertBack(
""
, typeof(DreamineThreadPriority),
null
!, CultureInfo.InvariantCulture));
44
}
45
54
[Fact]
55
public
void
ThreadInfoRow_UpdatesChangedFieldsAndDerivedFlags
()
56
{
57
var row =
new
ThreadInfoRow(
CreateInfo
(DreamineThreadStatus.Created, cycles: 1));
58
var changed =
new
List<string?>();
59
row.PropertyChanged += (_, args) => changed.Add(args.PropertyName);
60
61
var updated = row.UpdateFrom(
CreateInfo
(DreamineThreadStatus.Running, cycles: 2));
62
63
Assert.True(updated);
64
Assert.Equal(DreamineThreadStatus.Running, row.Status);
65
Assert.True(row.IsRunning);
66
Assert.Contains(nameof(ThreadInfoRow.Status), changed);
67
Assert.Contains(nameof(ThreadInfoRow.CycleCount), changed);
68
Assert.Contains(nameof(ThreadInfoRow.IsRunning), changed);
69
}
70
79
[Fact]
80
public
void
WindowsCpuInfoProvider_ReportsValidProcessorRange
()
81
{
82
ICpuInfoProvider provider =
new
WindowsCpuInfoProvider();
83
84
Assert.True(provider.GetLogicalProcessorCount() >= 1);
85
Assert.True(provider.IsValidCoreIndex(0));
86
Assert.False(provider.IsValidCoreIndex(-1));
87
Assert.False(provider.IsValidCoreIndex(provider.GetLogicalProcessorCount()));
88
}
89
98
[Fact]
99
public
void
ThreadMonitorViewModel_AcceptsDispatcherAbstraction
()
100
{
101
using
var viewModel =
new
DreamineThreadMonitorViewModel(
102
new
TestThreadManager
(),
103
new
TestThreadUiDispatcher
(),
104
TimeSpan.FromSeconds(1));
105
106
Assert.Empty(viewModel.Threads);
107
}
108
141
private
static
DreamineThreadInfo
CreateInfo
(DreamineThreadStatus status,
long
cycles)
142
{
143
return
new
DreamineThreadInfo(
144
"Worker"
,
145
status,
146
DreamineThreadPriority.Normal,
147
intervalMs: 10,
148
coreIndex:
null
,
149
useAffinity:
false
,
150
jobCount: 1,
151
cycleCount: cycles,
152
startedAt:
null
,
153
stoppedAt:
null
,
154
lastErrorMessage:
null
);
155
}
156
165
private
sealed
class
TestThreadUiDispatcher
: IThreadUiDispatcher
166
{
175
public
Dispatcher
Dispatcher
{
get
; } =
Dispatcher
.CurrentDispatcher;
176
193
public
void
Invoke
(Action action)
194
{
195
action();
196
}
197
214
public
void
BeginInvoke
(Action action)
215
{
216
action();
217
}
218
}
219
228
private
sealed
class
TestThreadManager
: IDreamineThreadManager
229
{
270
public
IDreamineThreadJob
Register
(DreamineThreadOptions options, Func<CancellationToken, ValueTask> action)
271
{
272
throw
new
NotSupportedException();
273
}
274
299
public
bool
Start
(
string
threadName) =>
true
;
300
325
public
bool
Stop
(
string
threadName) =>
true
;
326
351
public
ValueTask<bool>
StopAsync
(
string
threadName) => ValueTask.FromResult(
true
);
352
377
public
bool
Pause
(
string
threadName) =>
true
;
378
403
public
bool
Resume
(
string
threadName) =>
true
;
404
413
public
void
StartAll
()
414
{
415
}
416
425
public
void
StopAll
()
426
{
427
}
428
445
public
ValueTask
StopAllAsync
() => ValueTask.CompletedTask;
446
455
public
void
PauseAll
()
456
{
457
}
458
467
public
void
ResumeAll
()
468
{
469
}
470
503
public
bool
TryGetThread
(
string
threadName, out IDreamineThread? thread)
504
{
505
thread =
null
;
506
return
false
;
507
}
508
525
public
IReadOnlyList<IDreamineThread>
GetThreads
() => Array.Empty<IDreamineThread>();
526
543
public
IReadOnlyList<DreamineThreadInfo>
GetThreadInfos
() => Array.Empty<DreamineThreadInfo>();
544
553
public
void
Dispose
()
554
{
555
}
556
}
557
}
Dreamine.FullKit.Wpf.Tests.Threading
Definition
ThreadingWpfTests.cs:12
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests
Definition
ThreadingWpfTests.cs:23
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.ThreadConverters_MapKnownValues
void ThreadConverters_MapKnownValues()
Definition
ThreadingWpfTests.cs:33
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.CreateInfo
static DreamineThreadInfo CreateInfo(DreamineThreadStatus status, long cycles)
Definition
ThreadingWpfTests.cs:141
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.WindowsCpuInfoProvider_ReportsValidProcessorRange
void WindowsCpuInfoProvider_ReportsValidProcessorRange()
Definition
ThreadingWpfTests.cs:80
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.ThreadMonitorViewModel_AcceptsDispatcherAbstraction
void ThreadMonitorViewModel_AcceptsDispatcherAbstraction()
Definition
ThreadingWpfTests.cs:99
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.ThreadInfoRow_UpdatesChangedFieldsAndDerivedFlags
void ThreadInfoRow_UpdatesChangedFieldsAndDerivedFlags()
Definition
ThreadingWpfTests.cs:55
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadUiDispatcher
Definition
ThreadingWpfTests.cs:166
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadUiDispatcher.Invoke
void Invoke(Action action)
Definition
ThreadingWpfTests.cs:193
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadUiDispatcher.Dispatcher
Dispatcher Dispatcher
Definition
ThreadingWpfTests.cs:175
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadUiDispatcher.BeginInvoke
void BeginInvoke(Action action)
Definition
ThreadingWpfTests.cs:214
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager
Definition
ThreadingWpfTests.cs:229
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Resume
bool Resume(string threadName)
Definition
ThreadingWpfTests.cs:403
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.ResumeAll
void ResumeAll()
Definition
ThreadingWpfTests.cs:467
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.PauseAll
void PauseAll()
Definition
ThreadingWpfTests.cs:455
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.GetThreadInfos
IReadOnlyList< DreamineThreadInfo > GetThreadInfos()
Definition
ThreadingWpfTests.cs:543
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.GetThreads
IReadOnlyList< IDreamineThread > GetThreads()
Definition
ThreadingWpfTests.cs:525
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.StopAsync
ValueTask< bool > StopAsync(string threadName)
Definition
ThreadingWpfTests.cs:351
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Dispose
void Dispose()
Definition
ThreadingWpfTests.cs:553
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Pause
bool Pause(string threadName)
Definition
ThreadingWpfTests.cs:377
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Stop
bool Stop(string threadName)
Definition
ThreadingWpfTests.cs:325
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Register
IDreamineThreadJob Register(DreamineThreadOptions options, Func< CancellationToken, ValueTask > action)
Definition
ThreadingWpfTests.cs:270
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.StopAll
void StopAll()
Definition
ThreadingWpfTests.cs:425
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.StartAll
void StartAll()
Definition
ThreadingWpfTests.cs:413
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.TryGetThread
bool TryGetThread(string threadName, out IDreamineThread? thread)
Definition
ThreadingWpfTests.cs:503
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.StopAllAsync
ValueTask StopAllAsync()
Definition
ThreadingWpfTests.cs:445
Dreamine.FullKit.Wpf.Tests.Threading.ThreadingWpfTests.TestThreadManager.Start
bool Start(string threadName)
Definition
ThreadingWpfTests.cs:299
Threading
ThreadingWpfTests.cs
다음에 의해 생성됨 :
1.17.0