diff --git a/src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs b/src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs index bb22efd..48264e4 100644 --- a/src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs +++ b/src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs @@ -25,13 +25,12 @@ public class EditingScriptsTagHelper : TagHelper /// public override void Process(TagHelperContext context, TagHelperOutput output) { - ISitecoreRenderingContext renderingContext = ViewContext?.HttpContext.GetSitecoreRenderingContext() ?? - throw new NullReferenceException(Resources.Exception_EditingScriptsTagHelperSitecoreRenderingContextNull); + ISitecoreRenderingContext? renderingContext = ViewContext?.HttpContext.GetSitecoreRenderingContext(); output.TagName = string.Empty; string html = string.Empty; - if (renderingContext.Response?.Content?.Sitecore?.Context?.IsEditing ?? false) + if (renderingContext?.Response?.Content?.Sitecore?.Context?.IsEditing ?? false) { EditingContext? editingContext = JsonSerializer.Deserialize(renderingContext.Response?.Content.ContextRawData ?? string.Empty); if (editingContext == null) diff --git a/tests/Sitecore.AspNetCore.SDK.Pages.Tests/TagHelpers/EditingScriptsTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.Pages.Tests/TagHelpers/EditingScriptsTagHelperFixture.cs index e4084e7..5a2be3a 100644 --- a/tests/Sitecore.AspNetCore.SDK.Pages.Tests/TagHelpers/EditingScriptsTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.Pages.Tests/TagHelpers/EditingScriptsTagHelperFixture.cs @@ -54,7 +54,7 @@ public void Ctor_InvalidArgs_Throws(GuardClauseAssertion guard) [Theory] [AutoNSubstituteData] - public async Task ProcessAsync_NoSitecoreContenxt_ExceptionIsThrown(EditingScriptsTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput) + public async Task ProcessAsync_NoSitecoreContext_EmptyResult(EditingScriptsTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput) { // Arrange ViewContext viewContext = new() @@ -66,10 +66,10 @@ public async Task ProcessAsync_NoSitecoreContenxt_ExceptionIsThrown(EditingScrip sut.ViewContext = viewContext; // Act - Func act = async () => await sut.ProcessAsync(tagHelperContext, tagHelperOutput); + await sut.ProcessAsync(tagHelperContext, tagHelperOutput); // Assert - await act.Should().ThrowAsync(); + tagHelperOutput.Content.GetContent().Should().BeEmpty(); } [Theory]