|
10 | 10 | using Microsoft.Extensions.Logging; |
11 | 11 | using Microsoft.Extensions.Logging.Abstractions; |
12 | 12 | using Microsoft.Extensions.Options; |
13 | | -using Microsoft.Extensions.Primitives; |
14 | 13 | using Steeltoe.Common.TestResources; |
15 | 14 | using Steeltoe.Common.TestResources.IO; |
16 | 15 |
|
@@ -187,33 +186,13 @@ public async Task CertificateOptions_update_on_changed_contents(string certifica |
187 | 186 |
|
188 | 187 | var optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<CertificateOptions>>(); |
189 | 188 | optionsMonitor.Get(certificateName).Certificate.Should().BeEquivalentTo(firstX509); |
190 | | - IOptionsChangeTokenSource<CertificateOptions>[] tokenSources = [.. serviceProvider.GetServices<IOptionsChangeTokenSource<CertificateOptions>>()]; |
191 | | - |
192 | | - List<FilePathInOptionsChangeTokenSource<CertificateOptions>> matchingTokenSources = |
193 | | - [ |
194 | | - .. tokenSources.OfType<FilePathInOptionsChangeTokenSource<CertificateOptions>>() |
195 | | - ]; |
196 | | - |
197 | | - matchingTokenSources.Should().HaveCount(2); |
198 | | - |
199 | | - List<IChangeToken> changeTokens = [.. matchingTokenSources.Select(s => s.GetChangeToken())]; |
200 | | - |
201 | | - bool certificateContentsChangeCalled = false; |
202 | | - bool keyContentsChangeCalled = false; |
203 | | - using IDisposable certificateContentChangeToken = changeTokens[0].RegisterChangeCallback(_ => certificateContentsChangeCalled = true, null); |
204 | | - using IDisposable keyContentChangeToken = changeTokens[1].RegisterChangeCallback(_ => keyContentsChangeCalled = true, null); |
205 | | - |
206 | | - certificateContentsChangeCalled.Should().BeFalse("certificate file content has not changed yet"); |
207 | | - keyContentsChangeCalled.Should().BeFalse("key file content has not changed yet"); |
208 | 189 |
|
209 | 190 | await File.WriteAllTextAsync(certificateFilePath, secondCertificateContent, TestContext.Current.CancellationToken); |
210 | 191 | await File.WriteAllTextAsync(privateKeyFilePath, secondPrivateKeyContent, TestContext.Current.CancellationToken); |
211 | 192 |
|
212 | 193 | using Task pollTask = WaitUntilCertificateChangedToAsync(secondX509, optionsMonitor, certificateName, TestContext.Current.CancellationToken); |
213 | 194 | await pollTask.WaitAsync(TimeSpan.FromSeconds(4), TestContext.Current.CancellationToken); |
214 | 195 |
|
215 | | - certificateContentsChangeCalled.Should().BeTrue("certificate file contents changed"); |
216 | | - keyContentsChangeCalled.Should().BeTrue("key file contents changed"); |
217 | 196 | optionsMonitor.Get(certificateName).Certificate.Should().Be(secondX509); |
218 | 197 | } |
219 | 198 |
|
@@ -244,26 +223,14 @@ public async Task CertificateOptions_update_on_changed_path(string certificateNa |
244 | 223 |
|
245 | 224 | var optionsMonitor = serviceProvider.GetRequiredService<IOptionsMonitor<CertificateOptions>>(); |
246 | 225 | optionsMonitor.Get(certificateName).Certificate.Should().BeEquivalentTo(firstX509); |
247 | | - IOptionsChangeTokenSource<CertificateOptions>[] tokenSources = [.. serviceProvider.GetServices<IOptionsChangeTokenSource<CertificateOptions>>()]; |
248 | | - |
249 | | - IChangeToken configurationChangeToken = |
250 | | - tokenSources.OfType<ConfigurationChangeTokenSource<CertificateOptions>>().Should().ContainSingle().Which.GetChangeToken(); |
251 | 226 |
|
252 | | - bool configurationChangeCalled = false; |
| 227 | + appSettings = BuildAppSettingsJson(certificateName, "secondInstance.crt", "secondInstance.key"); |
| 228 | + await File.WriteAllTextAsync(appSettingsPath, appSettings, TestContext.Current.CancellationToken); |
253 | 229 |
|
254 | | - using (configurationChangeToken.RegisterChangeCallback(_ => configurationChangeCalled = true, null)) |
255 | | - { |
256 | | - configurationChangeCalled.Should().BeFalse("file path information has not changed yet"); |
257 | | - |
258 | | - appSettings = BuildAppSettingsJson(certificateName, "secondInstance.crt", "secondInstance.key"); |
259 | | - await File.WriteAllTextAsync(appSettingsPath, appSettings, TestContext.Current.CancellationToken); |
260 | | - |
261 | | - using Task pollTask = WaitUntilCertificateChangedToAsync(secondX509, optionsMonitor, certificateName, TestContext.Current.CancellationToken); |
262 | | - await pollTask.WaitAsync(TimeSpan.FromSeconds(4), TestContext.Current.CancellationToken); |
| 230 | + using Task pollTask = WaitUntilCertificateChangedToAsync(secondX509, optionsMonitor, certificateName, TestContext.Current.CancellationToken); |
| 231 | + await pollTask.WaitAsync(TimeSpan.FromSeconds(4), TestContext.Current.CancellationToken); |
263 | 232 |
|
264 | | - configurationChangeCalled.Should().BeTrue("file path information changed"); |
265 | | - optionsMonitor.Get(certificateName).Certificate.Should().Be(secondX509); |
266 | | - } |
| 233 | + optionsMonitor.Get(certificateName).Certificate.Should().Be(secondX509); |
267 | 234 | } |
268 | 235 |
|
269 | 236 | private static string BuildAppSettingsJson(string certificateName, string certificatePath, string keyPath) |
|
0 commit comments