File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . Toolkit . Uwp . UI ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using System ;
4+ using System . Threading . Tasks ;
5+
6+ namespace UnitTests . Extensions
7+ {
8+ [ TestClass ]
9+ public class Test_DispatcherQueueTimerExtensions
10+ {
11+ [ TestCategory ( "DispatcherQueueTimerExtensions" ) ]
12+ [ TestMethod ]
13+ public async Task Test_DispatcherQueueTimerExtensions_Debounce ( )
14+ {
15+ var debounceTimer = App . DispatcherQueue . CreateTimer ( ) ;
16+
17+ var triggeredCount = 0 ;
18+ string triggeredValue = null ;
19+
20+ var value = "He" ;
21+ debounceTimer . Debounce (
22+ ( ) =>
23+ {
24+ triggeredCount ++ ;
25+ triggeredValue = value ;
26+ } ,
27+ TimeSpan . FromMilliseconds ( 60 ) ) ;
28+
29+ await Task . Delay ( TimeSpan . FromMilliseconds ( 10 ) ) ;
30+
31+ value = "Hello" ;
32+ debounceTimer . Debounce (
33+ ( ) =>
34+ {
35+ triggeredCount ++ ;
36+ triggeredValue = value ;
37+ } ,
38+ TimeSpan . FromMilliseconds ( 60 ) ) ;
39+
40+ await Task . Delay ( TimeSpan . FromMilliseconds ( 110 ) ) ;
41+
42+ Assert . AreEqual ( false , debounceTimer . IsRunning , "Expected to stop the timer." ) ;
43+ Assert . AreEqual ( value , triggeredValue , "Expected to execute the last action." ) ;
44+ Assert . AreEqual ( 1 , triggeredCount , "Expected to postpone execution." ) ;
45+ }
46+ }
47+ }
Original file line number Diff line number Diff line change 165165 <Compile Include =" Converters\Test_StringFormatConverter.cs" />
166166 <Compile Include =" Converters\Test_TypeToObjectConverter.cs" />
167167 <Compile Include =" Extensions\Helpers\ObjectWithNullableBoolProperty.cs" />
168+ <Compile Include =" Extensions\Test_DispatcherQueueTimerExtensions.cs" />
168169 <Compile Include =" Extensions\Test_StringExtensions.cs" />
169170 <Compile Include =" Extensions\Test_UIElementExtensions_Coordinates.cs" />
170171 <Compile Include =" Extensions\Test_VisualTreeExtensions.cs" />
You can’t perform that action at this time.
0 commit comments