-
Notifications
You must be signed in to change notification settings - Fork 845
Expand file tree
/
Copy pathConformanceTests.cs
More file actions
688 lines (547 loc) · 24.4 KB
/
ConformanceTests.cs
File metadata and controls
688 lines (547 loc) · 24.4 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Text.Json.Nodes;
using Aspire.TestUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Json.Schema;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Xunit;
using Microsoft.DotNet.RemoteExecutor;
namespace Aspire.Components.ConformanceTests;
public abstract class ConformanceTests<TService, TOptions>
where TService : class
where TOptions : class, new()
{
protected static readonly EvaluationOptions DefaultEvaluationOptions = new() { RequireFormatValidation = true, OutputFormat = OutputFormat.List };
/// <summary>
/// Optional ITestOutputHelper for capturing diagnostic logs during test execution.
/// When provided, all logs will be output to xUnit test results for easier debugging.
/// </summary>
protected ITestOutputHelper? Output { get; }
/// <summary>
/// Initializes a new instance of the ConformanceTests base class.
/// </summary>
/// <param name="output">
/// Optional ITestOutputHelper for capturing diagnostic logs. When provided,
/// all logs from components under test will be written to xUnit output,
/// making test failures easier to diagnose.
/// </param>
protected ConformanceTests(ITestOutputHelper? output = null)
{
Output = output;
}
protected abstract ServiceLifetime ServiceLifetime { get; }
protected abstract string ActivitySourceName { get; }
protected string JsonSchemaPath => Path.Combine(AppContext.BaseDirectory, "ConfigurationSchema.json");
protected virtual string ValidJsonConfig { get; } = string.Empty;
protected virtual (string json, string error)[] InvalidJsonToErrorMessage => Array.Empty<(string json, string error)>();
protected abstract string[] RequiredLogCategories { get; }
protected virtual string[] NotAcceptableLogCategories => Array.Empty<string>();
protected virtual bool CanCreateClientWithoutConnectingToServer => true;
protected virtual bool CanConnectToServer => false;
protected virtual bool SupportsNamedConfig => true;
protected virtual string? ConfigurationSectionName => null;
protected virtual bool SupportsKeyedRegistrations => false;
protected virtual bool IsComponentBuiltBeforeHost => false;
protected bool MetricsAreSupported => CheckIfImplemented(SetMetrics);
// every Component has to support health checks, this property is a temporary workaround
protected bool HealthChecksAreSupported => CheckIfImplemented(SetHealthCheck);
protected virtual void DisableRetries(TOptions options) { }
protected bool TracingIsSupported => CheckIfImplemented(SetTracing);
protected virtual bool CheckOptionClassSealed => true;
/// <summary>
/// Calls the actual Component
/// </summary>
protected abstract void RegisterComponent(HostApplicationBuilder builder, Action<TOptions>? configure = null, string? key = null);
/// <summary>
/// Populates the Configuration with everything that is required by the Component
/// </summary>
/// <param name="configuration"></param>
protected abstract void PopulateConfiguration(ConfigurationManager configuration, string? key = null);
/// <summary>
/// Do anything that is going to trigger the <see cref="Activity"/> and <see cref="ILogger"/> creation. Example: try to create a DB.
/// </summary>
protected abstract void TriggerActivity(TService service);
/// <summary>
/// Sets the health checks to given value
/// </summary>
protected abstract void SetHealthCheck(TOptions options, bool enabled);
/// <summary>
/// Sets the tracing to given value
/// </summary>
protected abstract void SetTracing(TOptions options, bool enabled);
/// <summary>
/// Sets the metrics to given value
/// </summary>
protected abstract void SetMetrics(TOptions options, bool enabled);
[Fact]
public void OptionsTypeIsSealed()
{
if (typeof(TOptions) == typeof(object))
{
Assert.Skip("Not implemented yet");
}
if (!CheckOptionClassSealed)
{
Assert.Skip("Opt-out of test");
}
Assert.True(typeof(TOptions).IsSealed);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void HealthChecksRegistersHealthCheckService(bool enabled)
{
SkipIfHealthChecksAreNotSupported();
using IHost host = CreateHostWithComponent(options => SetHealthCheck(options, enabled));
HealthCheckService? healthCheckService = host.Services.GetService<HealthCheckService>();
Assert.Equal(enabled, healthCheckService is not null);
}
[Fact]
public async Task EachKeyedComponentRegistersItsOwnHealthCheck()
{
SkipIfHealthChecksAreNotSupported();
SkipIfKeyedRegistrationIsNotSupported();
const string key1 = "key1", key2 = "key2";
using IHost host = CreateHostWithMultipleKeyedComponents(key1, key2);
HealthCheckService healthCheckService = host.Services.GetRequiredService<HealthCheckService>();
List<string> registeredNames = new();
await healthCheckService.CheckHealthAsync(healthCheckRegistration =>
#pragma warning disable xUnit1030 // Do not call ConfigureAwait(false) in test method
{
registeredNames.Add(healthCheckRegistration.Name);
return false;
}).ConfigureAwait(false);
#pragma warning restore xUnit1030 // Do not call ConfigureAwait(false) in test method
Assert.Equal(2, registeredNames.Count);
Assert.All(registeredNames, name => Assert.True(name.Contains(key1) || name.Contains(key2), $"{name} did not contain the key."));
}
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void TracingRegistersTraceProvider(bool enabled)
{
SkipIfTracingIsNotSupported();
SkipIfRequiredServerConnectionCanNotBeEstablished();
using IHost host = CreateHostWithComponent(options => SetTracing(options, enabled));
TracerProvider? tracer = host.Services.GetService<TracerProvider>();
Assert.Equal(enabled, tracer is not null);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void MetricsRegistersMeterProvider(bool enabled)
{
SkipIfMetricsAreNotSupported();
using IHost host = CreateHostWithComponent(options => SetMetrics(options, enabled));
MeterProvider? meter = host.Services.GetService<MeterProvider>();
Assert.Equal(enabled, meter is not null);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void ServiceLifetimeIsAsExpected(bool useKey)
{
SkipIfRequiredServerConnectionCanNotBeEstablished();
SkipIfKeyedRegistrationIsNotSupported(useKey);
TService? serviceFromFirstScope, serviceFromSecondScope, secondServiceFromSecondScope;
string? key = useKey ? "key" : null;
using IHost host = CreateHostWithComponent(key: key);
using (IServiceScope scope1 = host.Services.CreateScope())
{
serviceFromFirstScope = Resolve(scope1.ServiceProvider, key);
}
using (IServiceScope scope2 = host.Services.CreateScope())
{
serviceFromSecondScope = Resolve(scope2.ServiceProvider, key);
secondServiceFromSecondScope = Resolve(scope2.ServiceProvider, key);
}
Assert.NotNull(serviceFromFirstScope);
Assert.NotNull(serviceFromSecondScope);
Assert.NotNull(secondServiceFromSecondScope);
switch (ServiceLifetime)
{
case ServiceLifetime.Singleton:
Assert.Same(serviceFromFirstScope, serviceFromSecondScope);
Assert.Same(serviceFromSecondScope, secondServiceFromSecondScope);
break;
case ServiceLifetime.Scoped:
Assert.NotSame(serviceFromFirstScope, serviceFromSecondScope);
Assert.Same(serviceFromSecondScope, secondServiceFromSecondScope);
break;
case ServiceLifetime.Transient:
Assert.NotSame(serviceFromFirstScope, serviceFromSecondScope);
Assert.NotSame(serviceFromSecondScope, secondServiceFromSecondScope);
break;
}
static TService? Resolve(IServiceProvider serviceProvider, string? key)
=> string.IsNullOrEmpty(key)
? serviceProvider.GetService<TService>()
: serviceProvider.GetKeyedService<TService>(key);
}
[Fact]
public void CanRegisterMultipleInstancesUsingDifferentKeys()
{
SkipIfKeyedRegistrationIsNotSupported();
SkipIfRequiredServerConnectionCanNotBeEstablished();
const string key1 = "key1", key2 = "key2";
using IHost host = CreateHostWithMultipleKeyedComponents(key1, key2);
TService serviceForKey1 = host.Services.GetRequiredKeyedService<TService>(key1);
TService serviceForKey2 = host.Services.GetRequiredKeyedService<TService>(key2);
Assert.NotSame(serviceForKey1, serviceForKey2);
}
[Fact]
public void WhenKeyedRegistrationIsUsedThenItsImpossibleToResolveWithoutKey()
{
SkipIfKeyedRegistrationIsNotSupported();
SkipIfRequiredServerConnectionCanNotBeEstablished();
const string key = "key";
HostApplicationBuilder builder = Host.CreateEmptyApplicationBuilder(settings: null);
PopulateConfiguration(builder.Configuration, key);
RegisterComponent(builder, key: key);
using IHost host = builder.Build();
Assert.NotNull(host.Services.GetKeyedService<TService>(key));
Assert.Null(host.Services.GetService<TService>());
Assert.Throws<InvalidOperationException>(host.Services.GetRequiredService<TService>);
}
[Theory]
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, true)]
[InlineData(false, false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void LoggerFactoryIsUsedByRegisteredClient(bool registerAfterLoggerFactory, bool useKey)
{
SkipIfRequiredServerConnectionCanNotBeEstablished();
SkipIfKeyedRegistrationIsNotSupported(useKey);
string? key = useKey ? "key" : null;
HostApplicationBuilder builder = CreateHostBuilder(key: key);
if (registerAfterLoggerFactory)
{
builder.Services.AddSingleton<ILoggerFactory, TestLoggerFactory>();
RegisterComponent(builder, key: key);
}
else
{
// the Component should be lazily created when it's requested for the first time!
RegisterComponent(builder, key: key);
builder.Services.AddSingleton<ILoggerFactory, TestLoggerFactory>();
}
using IHost host = builder.Build();
TService service = key is null
? host.Services.GetRequiredService<TService>()
: host.Services.GetRequiredKeyedService<TService>(key);
TestLoggerFactory loggerFactory = (TestLoggerFactory)host.Services.GetRequiredService<ILoggerFactory>();
try
{
TriggerActivity(service);
}
catch (Exception) { }
// Output diagnostic information about which categories were actually logged
// to help debug failures when expected categories are not found.
if (Output is not null)
{
Output.WriteLine("=== Logged Categories ===");
foreach (var category in loggerFactory.Categories.OrderBy(c => c))
{
Output.WriteLine($" - {category}");
}
Output.WriteLine("");
Output.WriteLine("=== Required Categories ===");
foreach (var category in RequiredLogCategories.OrderBy(c => c))
{
var found = loggerFactory.Categories.Contains(category);
Output.WriteLine($" {(found ? "✓" : "✗")} {category}");
}
if (NotAcceptableLogCategories.Length > 0)
{
Output.WriteLine("");
Output.WriteLine("=== Not Acceptable Categories (should not be present) ===");
foreach (var category in NotAcceptableLogCategories.OrderBy(c => c))
{
var found = loggerFactory.Categories.Contains(category);
Output.WriteLine($" {(found ? "✗ FOUND" : "✓ Not found")} {category}");
}
}
Output.WriteLine("");
}
foreach (string logCategory in RequiredLogCategories)
{
Assert.Contains(logCategory, loggerFactory.Categories);
}
foreach (string logCategory in NotAcceptableLogCategories)
{
Assert.DoesNotContain(logCategory, loggerFactory.Categories);
}
}
[Theory]
[InlineData(null)]
[InlineData("key")]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public virtual async Task HealthCheckReportsExpectedStatus(string? key)
{
SkipIfHealthChecksAreNotSupported();
// DisableRetries so the test doesn't take so long retrying when the server isn't available.
using IHost host = CreateHostWithComponent(configureComponent: DisableRetries, key: key);
var healthCheckService = host.Services.GetRequiredService<HealthCheckService>();
var healthReport = await healthCheckService.CheckHealthAsync();
var expected = CanConnectToServer ? HealthStatus.Healthy : HealthStatus.Unhealthy;
Assert.Equal(expected, healthReport.Status);
Assert.NotEmpty(healthReport.Entries);
Assert.Contains(healthReport.Entries, entry => entry.Value.Status == expected);
}
[Fact]
public void ConfigurationSchemaValidJsonConfigTest()
{
var schema = JsonSchema.FromFile(JsonSchemaPath);
var config = JsonNode.Parse(ValidJsonConfig);
var results = schema.Evaluate(config);
Assert.True(results.IsValid);
}
[Fact]
public void ConfigurationSchemaInvalidJsonConfigTest()
{
var schema = JsonSchema.FromFile(JsonSchemaPath);
foreach ((string json, string error) in InvalidJsonToErrorMessage)
{
var config = JsonNode.Parse(json);
var results = schema.Evaluate(config, DefaultEvaluationOptions);
var detail = results.Details.FirstOrDefault(x => x.HasErrors);
Assert.NotNull(detail);
Assert.Equal(error, detail.Errors!.First().Value);
}
}
/// <summary>
/// Ensures that when the connection information is missing, an exception isn't thrown before the host
/// is built, so any exception can be logged with ILogger.
/// </summary>
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/microsoft/aspire/issues/11820", typeof(PlatformDetection), nameof(PlatformDetection.IsRunningFromAzdo))]
public void ConnectionInformationIsDelayValidated(bool useKey)
{
SkipIfComponentIsBuiltBeforeHost();
SetupConnectionInformationIsDelayValidated();
var builder = Host.CreateEmptyApplicationBuilder(null);
string? key = useKey ? "key" : null;
RegisterComponent(builder, key: key);
using var host = builder.Build();
Assert.Throws<InvalidOperationException>(() =>
key is null
? host.Services.GetRequiredService<TService>()
: host.Services.GetRequiredKeyedService<TService>(key));
}
[Fact]
public void FavorsNamedConfigurationOverTopLevelConfigurationWhenBothProvided_DisableTracing()
{
SkipIfNamedConfigNotSupported();
SkipIfTracingIsNotSupported();
var key = "target-service";
var builder = Host.CreateEmptyApplicationBuilder(null);
builder.Configuration.AddInMemoryCollection([
new KeyValuePair<string, string?>($"{ConfigurationSectionName}:DisableTracing", "false"),
new KeyValuePair<string, string?>($"{ConfigurationSectionName}:{key}:DisableTracing", "true"),
]);
RegisterComponent(builder, key: key);
using var host = builder.Build();
// Trace provider is not configured because DisableTracing is set to true in the named configuration
Assert.Null(host.Services.GetService<TracerProvider>());
}
[Fact]
public void FavorsNamedConfigurationOverTopLevelConfigurationWhenBothProvided_DisableHealthChecks()
{
SkipIfNamedConfigNotSupported();
SkipIfHealthChecksAreNotSupported();
var key = "target-service";
var builder = Host.CreateEmptyApplicationBuilder(null);
builder.Configuration.AddInMemoryCollection([
new KeyValuePair<string, string?>($"{ConfigurationSectionName}:DisableHealthChecks", "false"),
new KeyValuePair<string, string?>($"{ConfigurationSectionName}:{key}:DisableHealthChecks", "true"),
]);
RegisterComponent(builder, key: key);
using var host = builder.Build();
// HealthChecksService is not configured because DisableHealthChecks is set to true in the named configuration
Assert.Null(host.Services.GetService<HealthCheckService>());
}
protected virtual void SetupConnectionInformationIsDelayValidated() { }
// This method can have side effects (setting AppContext switch, enabling activity source by name).
// That is why it needs to be executed in a standalone process.
// We use RemoteExecutor for that, but it does not support abstract classes
// (it can not determine the type to instantiate), so that is why this "test"
// is here and derived types call it
protected void ActivitySourceTest(string? key)
{
HostApplicationBuilder builder = CreateHostBuilder(key: key);
builder.Logging.AddConsole();
RegisterComponent(builder, options => SetTracing(options, true), key);
List<Activity> exportedActivities = new();
builder.Services.AddOpenTelemetry().WithTracing(builder => builder.AddInMemoryExporter(exportedActivities));
using (IHost host = builder.Build())
{
// We start the host to make it build TracerProvider.
// If we don't, nothing gets reported!
host.Start();
TService service = key is null
? host.Services.GetRequiredService<TService>()
: host.Services.GetRequiredKeyedService<TService>(key);
Assert.Empty(exportedActivities);
try
{
TriggerActivity(service);
}
catch (Exception) when (!CanConnectToServer)
{
}
Assert.NotEmpty(exportedActivities);
Assert.Contains(exportedActivities, activity => activity.Source.Name == ActivitySourceName);
}
}
protected IHost CreateHostWithComponent(Action<TOptions>? configureComponent = null, HostApplicationBuilderSettings? hostSettings = null, string? key = null)
{
HostApplicationBuilder builder = CreateHostBuilder(hostSettings, key);
RegisterComponent(builder, configureComponent, key);
return builder.Build();
}
protected IHost CreateHostWithMultipleKeyedComponents(params string[] keys)
{
HostApplicationBuilder builder = Host.CreateEmptyApplicationBuilder(settings: null);
foreach (var key in keys)
{
PopulateConfiguration(builder.Configuration, key);
RegisterComponent(builder, key: key);
}
return builder.Build();
}
protected void SkipIfHealthChecksAreNotSupported()
{
if (!HealthChecksAreSupported)
{
Assert.Skip("Health checks aren't supported.");
}
}
protected void SkipIfKeyedRegistrationIsNotSupported(bool useKey = true)
{
if (useKey && !SupportsKeyedRegistrations)
{
Assert.Skip("Does not support Keyed Services");
}
}
protected void SkipIfTracingIsNotSupported()
{
if (!TracingIsSupported)
{
Assert.Skip("Tracing is not supported.");
}
}
protected void SkipIfMetricsAreNotSupported()
{
if (!MetricsAreSupported)
{
Assert.Skip("Metrics are not supported.");
}
}
protected void SkipIfRequiredServerConnectionCanNotBeEstablished()
{
if (!CanCreateClientWithoutConnectingToServer && !CanConnectToServer)
{
Assert.Skip("Unable to connect to the server.");
}
}
protected void SkipIfCanNotConnectToServer()
{
if (!CanConnectToServer)
{
Assert.Skip("Unable to connect to the server.");
}
}
protected void SkipIfNamedConfigNotSupported()
{
if (!SupportsNamedConfig || ConfigurationSectionName is null)
{
Assert.Skip("Named configuration is not supported.");
}
}
protected static void RemoteInvokeWithLogging(Action action, ITestOutputHelper? testOutput, RemoteInvokeOptions? options = null)
{
using var handle = RemoteExecutor.Invoke(action, GetRemoteInvokeOptionsForLogging(options));
ConfigureLoggingAndStart(handle, testOutput);
}
protected static void RemoteInvokeWithLogging(Action<string> action, string arg, ITestOutputHelper? testOutput, RemoteInvokeOptions? options = null)
{
using var handle = RemoteExecutor.Invoke(action, arg, GetRemoteInvokeOptionsForLogging(options));
ConfigureLoggingAndStart(handle, testOutput);
}
private static RemoteInvokeOptions GetRemoteInvokeOptionsForLogging(RemoteInvokeOptions? options = null)
{
options ??= new RemoteInvokeOptions();
options.StartInfo.RedirectStandardError = true;
options.StartInfo.RedirectStandardOutput = true;
options.Start = false;
return options;
}
private static void ConfigureLoggingAndStart(RemoteInvokeHandle handle, ITestOutputHelper? testOutput)
{
if (testOutput is not null)
{
handle.Process.OutputDataReceived += (sender, e) =>
{
if (e.Data is not null)
{
testOutput.WriteLine($"[RemoteExecutor] {e.Data}");
}
};
handle.Process.ErrorDataReceived += (sender, e) =>
{
if (e.Data is not null)
{
testOutput.WriteLine($"[RemoteExecutor] ERROR: {e.Data}");
}
};
}
handle.Process.Start();
// RemoteInvokeHandle Dispose will handle the wait for exit
if (testOutput is not null)
{
handle.Process.BeginErrorReadLine();
handle.Process.BeginOutputReadLine();
}
}
public static string CreateConfigKey(string prefix, string? key, string suffix)
=> string.IsNullOrEmpty(key) ? $"{prefix}:{suffix}" : $"{prefix}:{key}:{suffix}";
protected void SkipIfComponentIsBuiltBeforeHost()
{
if (IsComponentBuiltBeforeHost)
{
Assert.Skip("Component is built before host.");
}
}
protected HostApplicationBuilder CreateHostBuilder(HostApplicationBuilderSettings? hostSettings = null, string? key = null)
{
HostApplicationBuilder builder = Host.CreateEmptyApplicationBuilder(hostSettings);
PopulateConfiguration(builder.Configuration, key);
return builder;
}
private static bool CheckIfImplemented(Action<TOptions, bool> action)
{
try
{
action(new TOptions(), true);
return true;
}
catch (NotImplementedException)
{
return false;
}
}
}