1
+ // ---------------------------------------------------------------
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // ---------------------------------------------------------------
4
+
5
+ namespace DurableTask . Core . Tests
6
+ {
7
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
8
+ using System ;
9
+ using System . Collections . Generic ;
10
+
11
+ [ TestClass ]
12
+ public class ScheduleTaskOptionsTests
13
+ {
14
+ [ TestMethod ]
15
+ public void CreateBuilder_ShouldReturnBuilderInstance ( )
16
+ {
17
+ // Act
18
+ ScheduleTaskOptions . Builder builder = ScheduleTaskOptions . CreateBuilder ( ) ;
19
+
20
+ // Assert
21
+ Assert . IsNotNull ( builder ) ;
22
+ Assert . IsInstanceOfType ( builder , typeof ( ScheduleTaskOptions . Builder ) ) ;
23
+ }
24
+
25
+ [ TestMethod ]
26
+ public void Build_ShouldCreateInstanceWithNullProperties ( )
27
+ {
28
+ // Act
29
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( ) . Build ( ) ;
30
+
31
+ // Assert
32
+ Assert . IsNotNull ( options ) ;
33
+ Assert . IsNull ( options . Tags ) ;
34
+ Assert . IsNull ( options . RetryOptions ) ;
35
+ }
36
+
37
+ [ TestMethod ]
38
+ public void WithTags_ShouldSetTagsProperty ( )
39
+ {
40
+ // Arrange
41
+ Dictionary < string , string > tags = new Dictionary < string , string >
42
+ {
43
+ { "key1" , "value1" } ,
44
+ { "key2" , "value2" }
45
+ } ;
46
+
47
+ // Act
48
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
49
+ . WithTags ( tags )
50
+ . Build ( ) ;
51
+
52
+ // Assert
53
+ Assert . IsNotNull ( options . Tags ) ;
54
+ Assert . AreEqual ( 2 , options . Tags . Count ) ;
55
+ Assert . AreEqual ( "value1" , options . Tags [ "key1" ] ) ;
56
+ Assert . AreEqual ( "value2" , options . Tags [ "key2" ] ) ;
57
+ }
58
+
59
+ [ TestMethod ]
60
+ public void AddTag_WithNullTags_ShouldInitializeTagsCollection ( )
61
+ {
62
+ // Act
63
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
64
+ . AddTag ( "key1" , "value1" )
65
+ . Build ( ) ;
66
+
67
+ // Assert
68
+ Assert . IsNotNull ( options . Tags ) ;
69
+ Assert . AreEqual ( 1 , options . Tags . Count ) ;
70
+ Assert . AreEqual ( "value1" , options . Tags [ "key1" ] ) ;
71
+ }
72
+
73
+ [ TestMethod ]
74
+ public void AddTag_WithExistingTags_ShouldAddToCollection ( )
75
+ {
76
+ // Arrange
77
+ Dictionary < string , string > tags = new Dictionary < string , string >
78
+ {
79
+ { "key1" , "value1" }
80
+ } ;
81
+
82
+ // Act
83
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
84
+ . WithTags ( tags )
85
+ . AddTag ( "key2" , "value2" )
86
+ . Build ( ) ;
87
+
88
+ // Assert
89
+ Assert . IsNotNull ( options . Tags ) ;
90
+ Assert . AreEqual ( 2 , options . Tags . Count ) ;
91
+ Assert . AreEqual ( "value1" , options . Tags [ "key1" ] ) ;
92
+ Assert . AreEqual ( "value2" , options . Tags [ "key2" ] ) ;
93
+ }
94
+
95
+ [ TestMethod ]
96
+ public void AddTag_OverwriteExistingKey_ShouldUpdateValue ( )
97
+ {
98
+ // Act
99
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
100
+ . AddTag ( "key1" , "originalValue" )
101
+ . AddTag ( "key1" , "newValue" )
102
+ . Build ( ) ;
103
+
104
+ // Assert
105
+ Assert . IsNotNull ( options . Tags ) ;
106
+ Assert . AreEqual ( 1 , options . Tags . Count ) ;
107
+ Assert . AreEqual ( "newValue" , options . Tags [ "key1" ] ) ;
108
+ }
109
+
110
+ [ TestMethod ]
111
+ public void WithRetryOptions_Instance_ShouldSetRetryOptionsProperty ( )
112
+ {
113
+ // Arrange
114
+ RetryOptions retryOptions = new RetryOptions ( TimeSpan . FromSeconds ( 5 ) , 3 ) ;
115
+
116
+ // Act
117
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
118
+ . WithRetryOptions ( retryOptions )
119
+ . Build ( ) ;
120
+
121
+ // Assert
122
+ Assert . IsNotNull ( options . RetryOptions ) ;
123
+ Assert . AreEqual ( TimeSpan . FromSeconds ( 5 ) , options . RetryOptions . FirstRetryInterval ) ;
124
+ Assert . AreEqual ( 3 , options . RetryOptions . MaxNumberOfAttempts ) ;
125
+ }
126
+
127
+ [ TestMethod ]
128
+ public void WithRetryOptions_Parameters_ShouldCreateAndSetRetryOptions ( )
129
+ {
130
+ // Act
131
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
132
+ . WithRetryOptions ( TimeSpan . FromSeconds ( 5 ) , 3 )
133
+ . Build ( ) ;
134
+
135
+ // Assert
136
+ Assert . IsNotNull ( options . RetryOptions ) ;
137
+ Assert . AreEqual ( TimeSpan . FromSeconds ( 5 ) , options . RetryOptions . FirstRetryInterval ) ;
138
+ Assert . AreEqual ( 3 , options . RetryOptions . MaxNumberOfAttempts ) ;
139
+ Assert . AreEqual ( 1 , options . RetryOptions . BackoffCoefficient ) ;
140
+ Assert . AreEqual ( TimeSpan . MaxValue , options . RetryOptions . MaxRetryInterval ) ;
141
+ }
142
+
143
+ [ TestMethod ]
144
+ public void WithRetryOptions_WithConfigureAction_ShouldConfigureRetryOptions ( )
145
+ {
146
+ // Act
147
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
148
+ . WithRetryOptions ( TimeSpan . FromSeconds ( 5 ) , 3 , retryOptions =>
149
+ {
150
+ retryOptions . BackoffCoefficient = 2.0 ;
151
+ retryOptions . MaxRetryInterval = TimeSpan . FromMinutes ( 1 ) ;
152
+ } )
153
+ . Build ( ) ;
154
+
155
+ // Assert
156
+ Assert . IsNotNull ( options . RetryOptions ) ;
157
+ Assert . AreEqual ( TimeSpan . FromSeconds ( 5 ) , options . RetryOptions . FirstRetryInterval ) ;
158
+ Assert . AreEqual ( 3 , options . RetryOptions . MaxNumberOfAttempts ) ;
159
+ Assert . AreEqual ( 2.0 , options . RetryOptions . BackoffCoefficient ) ;
160
+ Assert . AreEqual ( TimeSpan . FromMinutes ( 1 ) , options . RetryOptions . MaxRetryInterval ) ;
161
+ }
162
+
163
+ [ TestMethod ]
164
+ public void WithRetryOptions_PassNullConfigureAction_ShouldStillCreateRetryOptions ( )
165
+ {
166
+ // Act
167
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
168
+ . WithRetryOptions ( TimeSpan . FromSeconds ( 5 ) , 3 , null )
169
+ . Build ( ) ;
170
+
171
+ // Assert
172
+ Assert . IsNotNull ( options . RetryOptions ) ;
173
+ Assert . AreEqual ( TimeSpan . FromSeconds ( 5 ) , options . RetryOptions . FirstRetryInterval ) ;
174
+ Assert . AreEqual ( 3 , options . RetryOptions . MaxNumberOfAttempts ) ;
175
+ }
176
+
177
+ [ TestMethod ]
178
+ public void FluentInterface_CombiningAllMethods_ShouldBuildCorrectInstance ( )
179
+ {
180
+ // Arrange
181
+ RetryOptions retryOptions = new RetryOptions ( TimeSpan . FromSeconds ( 1 ) , 2 ) ;
182
+
183
+ // Act
184
+ ScheduleTaskOptions options = ScheduleTaskOptions . CreateBuilder ( )
185
+ . AddTag ( "env" , "test" )
186
+ . WithRetryOptions ( retryOptions )
187
+ . AddTag ( "priority" , "high" )
188
+ . Build ( ) ;
189
+
190
+ // Assert
191
+ Assert . IsNotNull ( options ) ;
192
+ Assert . IsNotNull ( options . Tags ) ;
193
+ Assert . AreEqual ( 2 , options . Tags . Count ) ;
194
+ Assert . AreEqual ( "test" , options . Tags [ "env" ] ) ;
195
+ Assert . AreEqual ( "high" , options . Tags [ "priority" ] ) ;
196
+ Assert . IsNotNull ( options . RetryOptions ) ;
197
+ Assert . AreEqual ( retryOptions . FirstRetryInterval , options . RetryOptions . FirstRetryInterval ) ;
198
+ Assert . AreEqual ( retryOptions . MaxNumberOfAttempts , options . RetryOptions . MaxNumberOfAttempts ) ;
199
+ }
200
+ }
201
+ }
0 commit comments