");
}
bool foundPlaceholderFeatures = false;
diff --git a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitecoreRedirectsAppConfigurationExtensions.cs b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitecoreRedirectsAppConfigurationExtensions.cs
index 7498a28..02dcb33 100644
--- a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitecoreRedirectsAppConfigurationExtensions.cs
+++ b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitecoreRedirectsAppConfigurationExtensions.cs
@@ -40,7 +40,7 @@ public static IServiceCollection AddSitecoreRedirects(this IServiceCollection se
{
ArgumentNullException.ThrowIfNull(services);
- services.TryAddSingleton
();
+ services.TryAddSingleton();
return services;
}
diff --git a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitemapAppConfigurationExtensions.cs b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitemapAppConfigurationExtensions.cs
index bb3f221..98c33ca 100644
--- a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitemapAppConfigurationExtensions.cs
+++ b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Extensions/SitemapAppConfigurationExtensions.cs
@@ -77,7 +77,7 @@ public static IServiceCollection AddEdgeSitemap(this IServiceCollection services
services.AddProxy();
- services.TryAddSingleton();
+ services.TryAddSingleton();
return services;
}
diff --git a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Services/GraphQlSiteInfoService.cs b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Services/GraphQlSiteInfoService.cs
index e8ab873..50400bd 100644
--- a/src/Sitecore.AspNetCore.SDK.SearchOptimization/Services/GraphQlSiteInfoService.cs
+++ b/src/Sitecore.AspNetCore.SDK.SearchOptimization/Services/GraphQlSiteInfoService.cs
@@ -9,15 +9,15 @@
namespace Sitecore.AspNetCore.SDK.SearchOptimization.Services;
///
-/// Implements the Sitemap and Redirects services by GraphQl data retrieval from Edge or Preview Delivery API.
+/// Implements the Sitemap and Redirects services by GraphQL data retrieval from Edge or Preview Delivery API.
///
-/// Options to configure the GraphQl Client.
-/// GraphQl Client.
+/// Options to configure the GraphQL Client.
+/// GraphQL Client.
/// Logger service.
-internal class GraphQlSiteInfoService(
- IOptions options,
+internal class GraphQLSiteInfoService(
+ IOptions options,
IGraphQLClient graphQlClient,
- ILogger logger)
+ ILogger logger)
: ISitemapService, IRedirectsService
{
private const string SiteInfoQuerySitemap = """
@@ -46,7 +46,7 @@ query SiteInfoQuery($site: String!) {
}
""";
- private readonly SitecoreGraphQlClientOptions _options = options.Value;
+ private readonly SitecoreGraphQLClientOptions _options = options.Value;
///
public async Task GetSitemapUrl(string requestedUrl, string? siteName)
@@ -128,7 +128,7 @@ private static void EnsureSiteName(string? siteName)
{
if (string.IsNullOrWhiteSpace(siteName))
{
- throw new InvalidGraphQlConfigurationException("Empty DefaultSiteName, provided in GraphQLClientOptions.");
+ throw new InvalidGraphQLConfigurationException("Empty DefaultSiteName, provided in GraphQLClientOptions.");
}
}
}
\ No newline at end of file
diff --git a/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs b/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs
index ad30c04..384b284 100644
--- a/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs
@@ -13,70 +13,70 @@
namespace Sitecore.AspNetCore.SDK.GraphQL.Tests.Extensions;
-public class GraphQlConfigurationExtensionsFixture
+public class GraphQLConfigurationExtensionsFixture
{
[Theory]
[AutoNSubstituteData]
- public void AddGraphQlClient_NullProperties_ThrowsExceptions(IServiceCollection serviceCollection)
+ public void AddGraphQLClient_NullProperties_ThrowsExceptions(IServiceCollection serviceCollection)
{
Func servicesNull =
- () => GraphQlConfigurationExtensions.AddGraphQlClient(null!, null!);
+ () => GraphQLConfigurationExtensions.AddGraphQLClient(null!, null!);
Func configNull =
- () => serviceCollection.AddGraphQlClient(null!);
+ () => serviceCollection.AddGraphQLClient(null!);
servicesNull.Should().Throw().WithParameterName("services");
configNull.Should().Throw().WithParameterName("configuration");
}
[Fact]
- public void AddGraphQlClient_EmptyApiKey_InConfiguration_ThrowsExceptions()
+ public void AddGraphQLClient_EmptyApiKey_InConfiguration_ThrowsExceptions()
{
Func act =
- () => Substitute.For().AddGraphQlClient(_ => { });
- act.Should().Throw()
+ () => Substitute.For().AddGraphQLClient(_ => { });
+ act.Should().Throw()
.WithMessage(Resources.Exception_MissingApiKeyAndContextId);
}
[Theory]
[AutoData]
- public void AddGraphQlClient_EmptyEndpoint_WithApiKey_ThrowsExceptions(string apiKey)
+ public void AddGraphQLClient_EmptyEndpoint_WithApiKey_ThrowsExceptions(string apiKey)
{
Func act =
- () => Substitute.For().AddGraphQlClient(options =>
+ () => Substitute.For().AddGraphQLClient(options =>
{
options.ApiKey = apiKey;
});
- act.Should().Throw()
+ act.Should().Throw()
.WithMessage(Resources.Exception_MissingEndpoint);
}
[Theory]
[AutoData]
- public void AddGraphQlClient_EmptyEndpointUri_WithContextId_UsesDefault(string contextId)
+ public void AddGraphQLClient_EmptyEndpointUri_WithContextId_UsesDefault(string contextId)
{
// Arrange
ServiceCollection serviceCollection = [];
// Act
- serviceCollection.AddGraphQlClient(configuration =>
+ serviceCollection.AddGraphQLClient(configuration =>
{
configuration.ContextId = contextId;
});
GraphQLHttpClient? graphQlClient = serviceCollection.BuildServiceProvider().GetService() as GraphQLHttpClient;
// Assert
- graphQlClient!.Options.EndPoint!.OriginalString.Should().Contain(SitecoreGraphQlClientOptions.DefaultEdgeEndpoint.OriginalString);
+ graphQlClient!.Options.EndPoint!.OriginalString.Should().Contain(SitecoreGraphQLClientOptions.DefaultEdgeEndpoint.OriginalString);
}
[Theory]
[AutoData]
- public void AddGraphQlClient_AddConfiguredGraphQlClient_To_ServiceCollection(string apiKey, Uri endpointUri, string defaultSiteName)
+ public void AddGraphQLClient_AddConfiguredGraphQLClient_To_ServiceCollection(string apiKey, Uri endpointUri, string defaultSiteName)
{
// Arrange
ServiceCollection serviceCollection = [];
// Act
- serviceCollection.AddGraphQlClient(
+ serviceCollection.AddGraphQLClient(
configuration =>
{
configuration.ApiKey = apiKey;
@@ -94,13 +94,13 @@ public void AddGraphQlClient_AddConfiguredGraphQlClient_To_ServiceCollection(str
[Theory]
[AutoData]
- public void AddGraphQlClient_WithContext_To_ServiceCollection(string contextId, Uri endpointUri, string defaultSiteName)
+ public void AddGraphQLClient_WithContext_To_ServiceCollection(string contextId, Uri endpointUri, string defaultSiteName)
{
// Arrange
ServiceCollection serviceCollection = [];
// Act
- serviceCollection.AddGraphQlClient(
+ serviceCollection.AddGraphQLClient(
configuration =>
{
configuration.ContextId = contextId;
diff --git a/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Request/GraphQLHttpRequestWithHeadersFixture.cs b/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Request/GraphQLHttpRequestWithHeadersFixture.cs
new file mode 100644
index 0000000..054eeeb
--- /dev/null
+++ b/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Request/GraphQLHttpRequestWithHeadersFixture.cs
@@ -0,0 +1,44 @@
+using System.Diagnostics.CodeAnalysis;
+using AutoFixture;
+using FluentAssertions;
+using GraphQL.Client.Abstractions;
+using GraphQL.Client.Http;
+using NSubstitute;
+using Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
+using Sitecore.AspNetCore.SDK.GraphQL.Request;
+using Xunit;
+
+namespace Sitecore.AspNetCore.SDK.GraphQL.Tests.Request;
+
+public class GraphQLHttpRequestWithHeadersFixture
+{
+ [ExcludeFromCodeCoverage]
+ public static Action AutoSetup => f =>
+ {
+ GraphQLHttpClientOptions options = Substitute.For();
+ f.Inject(options);
+
+ IGraphQLJsonSerializer serializer = Substitute.For();
+ f.Inject(serializer);
+ };
+
+ [Theory]
+ [AutoNSubstituteData]
+ public void ToHttpRequestMessage_HeadersAreAddedToReturnedMessage(GraphQLHttpRequestWithHeaders sut, GraphQLHttpClientOptions options, IGraphQLJsonSerializer serializer)
+ {
+ // Arrange
+ sut.Headers = new Dictionary
+ {
+ { "key1", "value1" },
+ { "key2", "value2" }
+ };
+
+ // Act
+ HttpRequestMessage result = sut.ToHttpRequestMessage(options, serializer);
+
+ // Assert
+ result.Should().NotBeNull();
+ result.Headers.GetValues("key1").Should().Contain("value1");
+ result.Headers.GetValues("key2").Should().Contain("value2");
+ }
+}
diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs
index 906506e..690693c 100644
--- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs
@@ -29,7 +29,7 @@ public async Task ContextRequest_Ok(string handlerName, string contextId)
// Set up the client
ISitecoreLayoutClientBuilder builder = services.AddSitecoreLayoutService();
- builder.AddGraphQlWithContextHandler(handlerName, contextId).AsDefaultHandler();
+ builder.AddGraphQLWithContextHandler(handlerName, contextId).AsDefaultHandler();
// Create an intercept for the actual HTTP call
MockHttpMessageHandler result = new();
@@ -72,8 +72,8 @@ public async Task ApiRequest_Ok(string handler1Name, string handler2Name, string
// Set up the client
ISitecoreLayoutClientBuilder builder = services.AddSitecoreLayoutService();
- builder.AddGraphQlHandler(handler1Name, site1Name, apiKey, endpoint).AsDefaultHandler();
- builder.AddGraphQlHandler(handler2Name, site2Name);
+ builder.AddGraphQLHandler(handler1Name, site1Name, apiKey, endpoint).AsDefaultHandler();
+ builder.AddGraphQLHandler(handler2Name, site2Name);
// Create an intercept for the actual HTTP call
MockHttpMessageHandler result = new();
diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs
index 92aef0e..1ed8378 100644
--- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs
@@ -6,17 +6,17 @@
namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.Exceptions;
-public class LayoutServiceGraphQlExceptionFixture
+public class LayoutServiceGraphQLExceptionFixture
{
[Theory]
[AutoNSubstituteData]
- public void LayoutServiceGraphQlException_GraphQlError_Get(GraphQLError error)
+ public void LayoutServiceGraphQLException_GraphQLError_Get(GraphQLError error)
{
// Arrange
- LayoutServiceGraphQlException sut = new(error);
+ LayoutServiceGraphQLException sut = new(error);
// Act
- GraphQLError result = sut.GraphQlError;
+ GraphQLError result = sut.GraphQLError;
// Assert
result.Should().Be(error);
diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs
index 1a23a57..d53bad1 100644
--- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs
@@ -168,10 +168,10 @@ public void WithDefaultRequestOptions_RequestDefaultsHasApiKeySpecified_ServiceP
[Theory]
[AutoNSubstituteData]
- public void AddGraphQlHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string name, string siteName, string apiKey, Uri uri)
+ public void AddGraphQLHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string name, string siteName, string apiKey, Uri uri)
{
// Act
- ILayoutRequestHandlerBuilder result = builder.AddGraphQlHandler(name, siteName, apiKey, uri);
+ ILayoutRequestHandlerBuilder result = builder.AddGraphQLHandler(name, siteName, apiKey, uri);
// Assert
ServiceProvider provider = result.Services.BuildServiceProvider();
@@ -183,10 +183,10 @@ public void AddGraphQlHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builde
[Theory]
[AutoNSubstituteData]
- public void AddGraphQlWithContextHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string contextId)
+ public void AddGraphQLWithContextHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string contextId)
{
// Act
- ILayoutRequestHandlerBuilder result = builder.AddGraphQlWithContextHandler("Test", contextId);
+ ILayoutRequestHandlerBuilder result = builder.AddGraphQLWithContextHandler("Test", contextId);
// Assert
ServiceProvider provider = result.Services.BuildServiceProvider();
diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/GraphQlLayoutServiceHandlerFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/GraphQlLayoutServiceHandlerFixture.cs
index c5529c5..c8086b6 100644
--- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/GraphQlLayoutServiceHandlerFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/GraphQlLayoutServiceHandlerFixture.cs
@@ -14,18 +14,18 @@
namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.Request.Handlers;
-public class GraphQlLayoutServiceHandlerFixture
+public class GraphQLLayoutServiceHandlerFixture
{
private readonly IGraphQLClient _client;
private readonly ISitecoreLayoutSerializer _serializer;
- private readonly GraphQlLayoutServiceHandler _graphQlLayoutServiceHandler;
+ private readonly GraphQLLayoutServiceHandler _graphQlLayoutServiceHandler;
- public GraphQlLayoutServiceHandlerFixture()
+ public GraphQLLayoutServiceHandlerFixture()
{
_client = Substitute.For();
_serializer = Substitute.For();
- ILogger? logger = Substitute.For>();
- _graphQlLayoutServiceHandler = new GraphQlLayoutServiceHandler(_client, _serializer, logger);
+ ILogger? logger = Substitute.For>();
+ _graphQlLayoutServiceHandler = new GraphQLLayoutServiceHandler(_client, _serializer, logger);
}
[Theory]
diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/HttpLayoutRequestHandlerFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/HttpLayoutRequestHandlerFixture.cs
index 84c0131..b8af9b1 100644
--- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/HttpLayoutRequestHandlerFixture.cs
+++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Request/Handlers/HttpLayoutRequestHandlerFixture.cs
@@ -426,7 +426,7 @@ public async Task Request_WithInvalidHttpHeaders_DoNotPopulatesErrors(
SitecoreLayoutRequest request)
{
// Arrange
- var httpResponse = new HttpResponseMessageWrapper(System.Net.HttpStatusCode.OK)
+ HttpResponseMessageWrapper? httpResponse = new(System.Net.HttpStatusCode.OK)
{
Headers = null
};
diff --git a/tests/Sitecore.AspNetCore.SDK.Pages.Tests/Controllers/PagesSetupControllerFixture.cs b/tests/Sitecore.AspNetCore.SDK.Pages.Tests/Controllers/PagesSetupControllerFixture.cs
new file mode 100644
index 0000000..d1db512
--- /dev/null
+++ b/tests/Sitecore.AspNetCore.SDK.Pages.Tests/Controllers/PagesSetupControllerFixture.cs
@@ -0,0 +1,228 @@
+using System.Diagnostics.CodeAnalysis;
+using AutoFixture;
+using AutoFixture.Idioms;
+using FluentAssertions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Primitives;
+using NSubstitute;
+using Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
+using Sitecore.AspNetCore.SDK.AutoFixture.Extensions;
+using Sitecore.AspNetCore.SDK.Pages.Configuration;
+using Sitecore.AspNetCore.SDK.Pages.Controllers;
+using Sitecore.AspNetCore.SDK.Pages.Models;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Configuration;
+using Sitecore.AspNetCore.SDK.RenderingEngine.Rendering;
+using Xunit;
+
+namespace Sitecore.AspNetCore.SDK.Pages.Tests.Controllers
+{
+ public class PagesSetupControllerFixture
+ {
+ private const string ValidConfigEndpoint = "/api/editing/config";
+ private const string ValidRenderEndpoint = "/api/editing/render";
+ private const string ValidEditingOrigin = "http://some.editing.domain";
+ private const string ValidOrigins = "http://some.origin.domain";
+ private const string ValidEditingSecret = "editing_secret_1234";
+
+ [ExcludeFromCodeCoverage]
+ public static Action AutoSetup => f =>
+ {
+ RequestDelegate requestDelegate = Substitute.For();
+ f.Inject(requestDelegate);
+
+ IOptions pagesOptions = Substitute.For>();
+ PagesOptions pagesOptionsValues = new()
+ {
+ ConfigEndpoint = ValidConfigEndpoint,
+ RenderEndpoint = ValidRenderEndpoint,
+ ValidEditingOrigin = ValidEditingOrigin,
+ ValidOrigins = ValidOrigins,
+ EditingSecret = ValidEditingSecret
+ };
+ pagesOptions.Value.Returns(pagesOptionsValues);
+ f.Inject(pagesOptions);
+
+ ILogger logger = Substitute.For>();
+ f.Inject(logger);
+
+ IOptions renderingEngineOptions = Substitute.For>();
+ string componentName = "TestComponent";
+ ComponentRendererDescriptor componentRendererDescriptor = new(name => name == componentName, _ => null!, componentName);
+ RenderingEngineOptions renderingEngineOptionsValues = new()
+ {
+ RendererRegistry = new SortedList
+ {
+ { 1, componentRendererDescriptor }
+ }
+ };
+ renderingEngineOptions.Value.Returns(renderingEngineOptionsValues);
+ f.Inject(renderingEngineOptions);
+ };
+
+ [Theory]
+ [AutoNSubstituteData]
+ public void Ctor_InvalidArgs_Throws(GuardClauseAssertion guard)
+ {
+ guard.VerifyConstructors();
+ }
+
+ [Theory]
+ [AutoNSubstituteData]
+ public void ConfigRoute_InvalidEditingSecret_ReturnsBadRequestResponse(IOptions pageOptions, ILogger logger, IOptions renderingEngineOptions)
+ {
+ // Arrange
+ HttpContext httpContext = Substitute.For();
+ httpContext.Request.Method.Returns("GET");
+ httpContext.Request.Path.Returns(new PathString(ValidConfigEndpoint));
+ httpContext.Request.Query.Returns(new QueryCollection(new Dictionary { { "secret", new StringValues("incorrect_secret_value") } }));
+ PagesSetupController sut = new(pageOptions, logger, renderingEngineOptions);
+ sut.ControllerContext = new ControllerContext()
+ {
+ HttpContext = httpContext
+ };
+
+ // Act
+ ActionResult response = sut.Config();
+
+ // Assert
+ logger.Received().Log(LogLevel.Error, Arg.Any(), Arg.Is