Handle null for retrieval of content section in unit tests (#19260)

This commit is contained in:
Andy Butland
2025-05-07 09:18:18 +02:00
committed by GitHub
parent 22e0720395
commit 744ff61fb0

View File

@@ -95,7 +95,12 @@ public static partial class UmbracoBuilderExtensions
builder.ContentIndexHandlers().Add(() => builder.TypeLoader.GetTypes<IContentIndexHandler>());
WebhookPayloadType webhookPayloadType = Constants.Webhooks.DefaultPayloadType;
if (builder.Config.GetSection(Constants.Configuration.ConfigWebhookPayloadType).Value is not null)
// IntelliSense indicates that GetSection cannot return null. However, in certain unit test setups,
// the configuration may not be fully initialized, leading to GetSection returning null. This null
// check ensures that the code behaves correctly in such scenarios and prevents potential null
// reference exceptions during testing.
if (builder.Config.GetSection(Constants.Configuration.ConfigWebhookPayloadType)?.Value is not null)
{
webhookPayloadType = builder.Config.GetValue<WebhookPayloadType>(Constants.Configuration.ConfigWebhookPayloadType);
}