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