diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ef5fa01..1deaea7 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,5 @@ - + ## Description / Motivation @@ -10,7 +10,7 @@ ## Testing - [ ] The Unit & Intergration tests are passing. -- [ ] I have added the necesary tests to cover my changes. +- [ ] I have added the necessary tests to cover my changes. ## Terms diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs index da87e38..23dc37c 100644 --- a/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Client/Models/SitecoreGraphQLClientOptions.cs @@ -9,11 +9,31 @@ namespace Sitecore.AspNetCore.SDK.GraphQL.Client.Models; /// public class SitecoreGraphQlClientOptions : GraphQLHttpClientOptions { + /// + /// ContextId query string key. + /// + public const string ContextIdQueryStringKey = "sitecoreContextId"; + + /// + /// Header name for the ApiKey. + /// + public const string ApiKeyHeaderName = "sc_apikey"; + + /// + /// Default Edge Endpoint Uri. + /// + public static readonly Uri DefaultEdgeEndpoint = new("https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1"); + /// /// Gets or sets ApiKey. /// public string? ApiKey { get; set; } + /// + /// Gets or sets ContextId. + /// + public string? ContextId { get; set; } + /// /// Gets or sets Default site name, used by middlewares which use GraphQl client. /// diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs index 31923da..6adb9b4 100644 --- a/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/GraphQlConfigurationExtensions.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Sitecore.AspNetCore.SDK.GraphQL.Client.Models; using Sitecore.AspNetCore.SDK.GraphQL.Exceptions; +using Sitecore.AspNetCore.SDK.GraphQL.Properties; namespace Sitecore.AspNetCore.SDK.GraphQL.Extensions; @@ -24,13 +25,24 @@ public static IServiceCollection AddGraphQlClient(this IServiceCollection servic services.Configure(configuration); - SitecoreGraphQlClientOptions graphQlClientOptions = TryGetConfiguration(configuration); + SitecoreGraphQlClientOptions options = TryGetConfiguration(configuration); services.AddSingleton(_ => { - GraphQLHttpClient graphQlHttpClient = new(graphQlClientOptions.EndPoint!, graphQlClientOptions.GraphQlJsonSerializer); + if (!string.IsNullOrWhiteSpace(options.ContextId)) + { + options.EndPoint = options.EndPoint.AddQueryString( + SitecoreGraphQlClientOptions.ContextIdQueryStringKey, + options.ContextId); + } + + GraphQLHttpClient graphQlHttpClient = new(options.EndPoint!, options.GraphQlJsonSerializer); + + if (!string.IsNullOrWhiteSpace(options.ApiKey)) + { + graphQlHttpClient.HttpClient.DefaultRequestHeaders.Add(SitecoreGraphQlClientOptions.ApiKeyHeaderName, options.ApiKey); + } - graphQlHttpClient.HttpClient.DefaultRequestHeaders.Add("sc_apikey", graphQlClientOptions.ApiKey); return graphQlHttpClient; }); @@ -39,19 +51,23 @@ public static IServiceCollection AddGraphQlClient(this IServiceCollection servic private static SitecoreGraphQlClientOptions TryGetConfiguration(Action configuration) { - SitecoreGraphQlClientOptions graphQlClientOptions = new(); - configuration.Invoke(graphQlClientOptions); + SitecoreGraphQlClientOptions options = new(); + configuration.Invoke(options); - if (string.IsNullOrWhiteSpace(graphQlClientOptions.ApiKey)) + if (string.IsNullOrWhiteSpace(options.ApiKey) && string.IsNullOrWhiteSpace(options.ContextId)) { - throw new InvalidGraphQlConfigurationException("Empty ApiKey, provided in GraphQLClientOptions."); + throw new InvalidGraphQlConfigurationException(Resources.Exception_MissingApiKeyAndContextId); } - if (graphQlClientOptions.EndPoint == null) + if (options.EndPoint == null && !string.IsNullOrWhiteSpace(options.ContextId)) + { + options.EndPoint = SitecoreGraphQlClientOptions.DefaultEdgeEndpoint; + } + else if (options.EndPoint == null) { - throw new InvalidGraphQlConfigurationException("Empty EndPoint, provided in GraphQLClientOptions."); + throw new InvalidGraphQlConfigurationException(Resources.Exception_MissingEndpoint); } - return graphQlClientOptions; + return options; } } \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/UriExtensions.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/UriExtensions.cs new file mode 100644 index 0000000..0ae47c3 --- /dev/null +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Extensions/UriExtensions.cs @@ -0,0 +1,30 @@ +using System.Web; + +namespace Sitecore.AspNetCore.SDK.GraphQL.Extensions; + +/// +/// Extension methods for . +/// +public static class UriExtensions +{ + /// + /// Adds a query string to the . + /// + /// The original . + /// The key to use. + /// The value to use. This will be UrlEncoded. + /// New with the query or the original if is null or is null, empty or whitespace. + public static Uri? AddQueryString(this Uri? uri, string key, string value) + { + Uri? result = uri; + if (uri != null && !string.IsNullOrWhiteSpace(key)) + { + int queryIndex = uri.OriginalString.IndexOf('?'); + result = queryIndex > 0 + ? new Uri(uri.OriginalString.Insert(queryIndex + 1, $"{key}={HttpUtility.UrlEncode(value)}&"), UriKind.RelativeOrAbsolute) + : new Uri($"{uri.OriginalString}?{key}={HttpUtility.UrlEncode(value)}", UriKind.RelativeOrAbsolute); + } + + return result; + } +} \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.Designer.cs b/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0fadff7 --- /dev/null +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.Designer.cs @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Sitecore.AspNetCore.SDK.GraphQL.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sitecore.AspNetCore.SDK.GraphQL.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Both the API Key and Context Id are empty, one or the other must be filled to allow successfull connection.. + /// + internal static string Exception_MissingApiKeyAndContextId { + get { + return ResourceManager.GetString("Exception_MissingApiKeyAndContextId", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The endpoint was not configured.. + /// + internal static string Exception_MissingEndpoint { + get { + return ResourceManager.GetString("Exception_MissingEndpoint", resourceCulture); + } + } + } +} diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.resx b/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.resx new file mode 100644 index 0000000..15cf5dd --- /dev/null +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Properties/Resources.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Both the API Key and Context Id are empty, one or the other must be filled to allow successfull connection. + + + The endpoint was not configured. + + \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj b/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj index 1270519..6fc8e95 100644 --- a/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj +++ b/src/Sitecore.AspNetCore.SDK.GraphQL/Sitecore.AspNetCore.SDK.GraphQL.csproj @@ -11,4 +11,25 @@ + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + <_Parameter1>Sitecore.AspNetCore.SDK.GraphQL.Tests + + + diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs index d2696a0..4c5b2d1 100644 --- a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs +++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutClientBuilderExtensions.cs @@ -1,5 +1,4 @@ -using System.Text.Json.Serialization; -using GraphQL.Client.Abstractions; +using GraphQL.Client.Abstractions; using GraphQL.Client.Http; using GraphQL.Client.Serializer.SystemTextJson; using Microsoft.Extensions.DependencyInjection; @@ -12,7 +11,6 @@ using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers.GraphQL; using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization; -using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization.Converter; namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; @@ -89,6 +87,9 @@ public static ILayoutRequestHandlerBuilder AddGraph GraphQLHttpClient client = new(uri, new SystemTextJsonSerializer()); client.HttpClient.DefaultRequestHeaders.Add("sc_apikey", apiKey); + builder.Services.TryAddKeyedSingleton(name, client); + builder.Services.TryAddSingleton(client); + builder.WithDefaultRequestOptions(request => { request @@ -101,7 +102,10 @@ public static ILayoutRequestHandlerBuilder AddGraph }); return builder.AddHandler(name, sp => ActivatorUtilities.CreateInstance( - sp, client, sp.GetRequiredService(), sp.GetRequiredService>())); + sp, + sp.GetRequiredKeyedService(name), + sp.GetRequiredService(), + sp.GetRequiredService>())); } /// @@ -123,8 +127,11 @@ public static ILayoutRequestHandlerBuilder AddGraph builder.WithDefaultRequestOptions(request => { - request - .SiteName(siteName); + if (!request.ContainsKey(RequestKeys.SiteName)) + { + request.SiteName(siteName); + } + if (!request.ContainsKey(RequestKeys.Language)) { request.Language(defaultLanguage); @@ -132,7 +139,10 @@ public static ILayoutRequestHandlerBuilder AddGraph }); return builder.AddHandler(name, sp => ActivatorUtilities.CreateInstance( - sp, sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService>())); + sp, + sp.GetRequiredService(), + sp.GetRequiredService(), + sp.GetRequiredService>())); } /// @@ -152,7 +162,7 @@ public static ISitecoreLayoutClientBuilder WithDefaultRequestOptions(this ISitec } /// - /// Registers a HTTP request handler for the Sitecore layout service client. + /// Registers an HTTP request handler for the Sitecore layout service client. /// /// The to configure. /// The name of the request handler being registered. @@ -293,4 +303,50 @@ public static ILayoutRequestHandlerBuilder AddHttpHand return AddHttpHandler(builder, handlerName, new Uri(uri)); } + + /// + /// Registers a graphQl handler to handle requests. + /// + /// The being configured. + /// The name used to identify the handler. + /// The context identifier to access graphQl endpoint. + /// GraphQl endpoint uri. + /// The siteName used to identify the handler. + /// Default language for GraphQl requests. + /// The so that additional calls can be chained. + public static ILayoutRequestHandlerBuilder AddGraphQlWithContextHandler( + this ISitecoreLayoutClientBuilder builder, + string name, + string contextId, + Uri? uri = null, + string? siteName = null, + string defaultLanguage = "en") + { + ArgumentNullException.ThrowIfNull(name); + ArgumentNullException.ThrowIfNull(contextId); + ArgumentNullException.ThrowIfNull(defaultLanguage); + + uri ??= new Uri("https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1"); + uri = uri.AddQueryString("sitecoreContextId", contextId)!; + + GraphQLHttpClient client = new(uri, new SystemTextJsonSerializer()); + builder.Services.TryAddKeyedSingleton(name, client); + + builder.WithDefaultRequestOptions(request => + { + request + .SiteName(siteName) + .ContextId(contextId); + if (!request.ContainsKey(RequestKeys.Language)) + { + request.Language(defaultLanguage); + } + }); + return builder.AddHandler(name, sp + => ActivatorUtilities.CreateInstance( + sp, + sp.GetRequiredKeyedService(name), + sp.GetRequiredService(), + sp.GetRequiredService>())); + } } \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs index 144a94d..a7a9b0f 100644 --- a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs +++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/SitecoreLayoutRequestExtensions.cs @@ -15,7 +15,8 @@ internal static class SitecoreLayoutRequestExtensions RequestKeys.Language, RequestKeys.ApiKey, RequestKeys.Mode, - RequestKeys.PreviewDate + RequestKeys.PreviewDate, + RequestKeys.ContextId ]; /// diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/UriExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/UriExtensions.cs new file mode 100644 index 0000000..ec54b3b --- /dev/null +++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Extensions/UriExtensions.cs @@ -0,0 +1,30 @@ +using System.Web; + +namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; + +/// +/// Extension methods for . +/// +public static class UriExtensions +{ + /// + /// Adds a query string to the . + /// + /// The original . + /// The key to use. + /// The value to use. This will be UrlEncoded. + /// New with the query or the original if is null or is null, empty or whitespace. + public static Uri? AddQueryString(this Uri? uri, string key, string value) + { + Uri? result = uri; + if (uri != null && !string.IsNullOrWhiteSpace(key)) + { + int queryIndex = uri.OriginalString.IndexOf('?'); + result = queryIndex > 0 + ? new Uri(uri.OriginalString.Insert(queryIndex + 1, $"{key}={HttpUtility.UrlEncode(value)}&"), UriKind.RelativeOrAbsolute) + : new Uri($"{uri.OriginalString}?{key}={HttpUtility.UrlEncode(value)}", UriKind.RelativeOrAbsolute); + } + + return result; + } +} \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/RequestKeys.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/RequestKeys.cs index 21920e2..7ef8827 100644 --- a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/RequestKeys.cs +++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/RequestKeys.cs @@ -49,4 +49,9 @@ public static class RequestKeys /// The key name for request preview date. /// public const string PreviewDate = "sc_date"; + + /// + /// The key name for request context identifier. + /// + public const string ContextId = "sitecoreContextId"; } \ No newline at end of file diff --git a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/SitecoreLayoutRequestExtensions.cs b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/SitecoreLayoutRequestExtensions.cs index 1973a64..38b2472 100644 --- a/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/SitecoreLayoutRequestExtensions.cs +++ b/src/Sitecore.AspNetCore.SDK.LayoutService.Client/Request/SitecoreLayoutRequestExtensions.cs @@ -28,6 +28,24 @@ public static class SitecoreLayoutRequestExtensions public static SitecoreLayoutRequest ApiKey(this SitecoreLayoutRequest request, string? value) => WriteValue(request, RequestKeys.ApiKey, value); + /// + /// Gets the context id key of the request. + /// + /// The . + /// The API key string value, otherwise null. + public static string? ContextId(this SitecoreLayoutRequest request) + => ReadValue(request, RequestKeys.ContextId); + + /// + /// Sets the context id key of the request. + /// If a null value is provided, the API key is removed from the request. + /// + /// The . + /// The value to set. + /// The . + public static SitecoreLayoutRequest ContextId(this SitecoreLayoutRequest request, string? value) + => WriteValue(request, RequestKeys.ContextId, value); + /// /// Gets the site name of the request. /// diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/HttpRequestMessageExtensions.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/HttpRequestMessageExtensions.cs new file mode 100644 index 0000000..c53a111 --- /dev/null +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/HttpRequestMessageExtensions.cs @@ -0,0 +1,30 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Sitecore.AspNetCore.SDK.AutoFixture.Extensions; + +[ExcludeFromCodeCoverage] +public static class HttpRequestMessageExtensions +{ + public static async Task Clone(this HttpRequestMessage request) + { + HttpRequestMessage clone = new(request.Method, request.RequestUri) + { + Version = request.Version + }; + + if (request.Content != null) + { + MemoryStream ms = new(); + await request.Content.CopyToAsync(ms); + ms.Position = 0; + clone.Content = new StreamContent(ms); + + request.Content.Headers.ToList().ForEach(header => clone.Content.Headers.TryAddWithoutValidation(header.Key, header.Value)); + } + + request.Options.ToList().ForEach(option => clone.Options.TryAdd(option.Key, option.Value)); + request.Headers.ToList().ForEach(header => clone.Headers.TryAddWithoutValidation(header.Key, header.Value)); + + return clone; + } +} \ No newline at end of file diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Mocks/MockHttpMessageHandler.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Mocks/MockHttpMessageHandler.cs new file mode 100644 index 0000000..9db3126 --- /dev/null +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Mocks/MockHttpMessageHandler.cs @@ -0,0 +1,32 @@ +using System.Diagnostics.CodeAnalysis; +using Sitecore.AspNetCore.SDK.AutoFixture.Extensions; + +namespace Sitecore.AspNetCore.SDK.AutoFixture.Mocks; + +[ExcludeFromCodeCoverage] +public class MockHttpMessageHandler : HttpMessageHandler +{ + public Stack Responses { get; } = new(); + + public List Requests { get; } = []; + + public bool WasInvoked { get; private set; } + + protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken) + { + Task clone = request.Clone(); + clone.Wait(cancellationToken); + Requests.Add(clone.Result); + WasInvoked = true; + HttpResponseMessage response = Responses.Pop(); + return response; + } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + Requests.Add(await request.Clone().WaitAsync(cancellationToken)); + WasInvoked = true; + HttpResponseMessage response = Responses.Pop(); + return response; + } +} \ 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 b5bc1fb..ad30c04 100644 --- a/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.GraphQL.Tests/Extensions/GraphQlConfigurationExtensionsFixture.cs @@ -5,8 +5,10 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; +using Sitecore.AspNetCore.SDK.GraphQL.Client.Models; using Sitecore.AspNetCore.SDK.GraphQL.Exceptions; using Sitecore.AspNetCore.SDK.GraphQL.Extensions; +using Sitecore.AspNetCore.SDK.GraphQL.Properties; using Xunit; namespace Sitecore.AspNetCore.SDK.GraphQL.Tests.Extensions; @@ -30,22 +32,40 @@ public void AddGraphQlClient_NullProperties_ThrowsExceptions(IServiceCollection public void AddGraphQlClient_EmptyApiKey_InConfiguration_ThrowsExceptions() { Func act = - () => Substitute.For().AddGraphQlClient(delegate { }); + () => Substitute.For().AddGraphQlClient(_ => { }); act.Should().Throw() - .WithMessage("Empty ApiKey, provided in GraphQLClientOptions."); + .WithMessage(Resources.Exception_MissingApiKeyAndContextId); } [Theory] [AutoData] - public void AddGraphQlClient_EmptyEndpointUri_InConfiguration_ThrowsExceptions(string apiKey) + public void AddGraphQlClient_EmptyEndpoint_WithApiKey_ThrowsExceptions(string apiKey) { Func act = - () => Substitute.For().AddGraphQlClient(configuration => + () => Substitute.For().AddGraphQlClient(options => { - configuration.ApiKey = apiKey; + options.ApiKey = apiKey; }); act.Should().Throw() - .WithMessage("Empty EndPoint, provided in GraphQLClientOptions."); + .WithMessage(Resources.Exception_MissingEndpoint); + } + + [Theory] + [AutoData] + public void AddGraphQlClient_EmptyEndpointUri_WithContextId_UsesDefault(string contextId) + { + // Arrange + ServiceCollection serviceCollection = []; + + // Act + serviceCollection.AddGraphQlClient(configuration => + { + configuration.ContextId = contextId; + }); + GraphQLHttpClient? graphQlClient = serviceCollection.BuildServiceProvider().GetService() as GraphQLHttpClient; + + // Assert + graphQlClient!.Options.EndPoint!.OriginalString.Should().Contain(SitecoreGraphQlClientOptions.DefaultEdgeEndpoint.OriginalString); } [Theory] @@ -71,4 +91,27 @@ public void AddGraphQlClient_AddConfiguredGraphQlClient_To_ServiceCollection(str graphQlClient.HttpClient.DefaultRequestHeaders.Contains("sc_apikey").Should().BeTrue(); apiKey.Should().Be(graphQlClient.HttpClient.DefaultRequestHeaders.GetValues("sc_apikey").FirstOrDefault()); } + + [Theory] + [AutoData] + public void AddGraphQlClient_WithContext_To_ServiceCollection(string contextId, Uri endpointUri, string defaultSiteName) + { + // Arrange + ServiceCollection serviceCollection = []; + + // Act + serviceCollection.AddGraphQlClient( + configuration => + { + configuration.ContextId = contextId; + configuration.EndPoint = endpointUri; + configuration.DefaultSiteName = defaultSiteName; + }); + GraphQLHttpClient? graphQlClient = serviceCollection.BuildServiceProvider().GetService() as GraphQLHttpClient; + + // Assert + graphQlClient.Should().NotBeNull(); + graphQlClient!.Options.EndPoint!.Host.Should().Be(endpointUri.Host); + graphQlClient.Options.EndPoint.Query.Should().Contain($"sitecoreContextId={contextId}"); + } } \ No newline at end of file diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs new file mode 100644 index 0000000..906506e --- /dev/null +++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests/RequestsFixture.cs @@ -0,0 +1,128 @@ +using System.Net; +using System.Net.Http.Headers; +using FluentAssertions; +using GraphQL.Client.Abstractions; +using GraphQL.Client.Http; +using GraphQL.Client.Serializer.SystemTextJson; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; +using Xunit; + +namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Integration.Tests; + +public class RequestsFixture +{ + [Theory] + [AutoNSubstituteData] + public async Task ContextRequest_Ok(string handlerName, string contextId) + { + // Arrange + IServiceCollection services = new ServiceCollection(); + + // Logging is required for the client + services.AddLogging(); + + // Set up the client + ISitecoreLayoutClientBuilder builder = services.AddSitecoreLayoutService(); + builder.AddGraphQlWithContextHandler(handlerName, contextId).AsDefaultHandler(); + + // Create an intercept for the actual HTTP call + MockHttpMessageHandler result = new(); + string json = await File.ReadAllTextAsync("./Json/headlessSxa.json"); + HttpResponseMessage message = new(HttpStatusCode.OK) + { + Content = new StringContent($"{{ \"data\": {json} }}") + }; + message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/graphql+json"); + result.Responses.Push(message); + ServiceDescriptor gqlClient = services.Single(s => s.ServiceKey?.ToString() == handlerName); + GraphQLHttpClientOptions options = ((GraphQLHttpClient)gqlClient.KeyedImplementationInstance!).Options; + options.HttpMessageHandler = result; + services.RemoveAllKeyed(handlerName); + services.AddKeyedSingleton(handlerName, new GraphQLHttpClient( + options, + new SystemTextJsonSerializer())); + + // Build and grab the sut + IServiceProvider provider = services.BuildServiceProvider(); + ISitecoreLayoutClient sut = provider.GetRequiredService(); + + // Act + _ = await sut.Request([]); + + // Assert + result.Requests.Should().ContainSingle(); + result.Requests.Single().RequestUri!.Query.Should().Contain(contextId); + } + + [Theory] + [AutoNSubstituteData] + public async Task ApiRequest_Ok(string handler1Name, string handler2Name, string site1Name, string site2Name, string apiKey, Uri endpoint) + { + // Arrange + IServiceCollection services = new ServiceCollection(); + + // Logging is required for the client + services.AddLogging(); + + // Set up the client + ISitecoreLayoutClientBuilder builder = services.AddSitecoreLayoutService(); + builder.AddGraphQlHandler(handler1Name, site1Name, apiKey, endpoint).AsDefaultHandler(); + builder.AddGraphQlHandler(handler2Name, site2Name); + + // Create an intercept for the actual HTTP call + MockHttpMessageHandler result = new(); + string json = await File.ReadAllTextAsync("./Json/headlessSxa.json"); + result.Responses.Push(GenerateGqlResponse(json)); + result.Responses.Push(GenerateGqlResponse(json)); + result.Responses.Push(GenerateGqlResponse(json)); + ServiceDescriptor gqlClient = services.Single(s => s.ServiceKey?.ToString() == handler1Name); + GraphQLHttpClient originalClient = (GraphQLHttpClient)gqlClient.KeyedImplementationInstance!; + GraphQLHttpClientOptions options = originalClient.Options; + options.HttpMessageHandler = result; + services.RemoveAllKeyed(handler1Name); + services.RemoveAll(); + GraphQLHttpClient interceptClient = new( + options, + new SystemTextJsonSerializer()); + services.AddKeyedSingleton(handler1Name, interceptClient); + services.AddSingleton(interceptClient); + + // Build and grab the sut + IServiceProvider provider = services.BuildServiceProvider(); + ISitecoreLayoutClient sut = provider.GetRequiredService(); + + // Act + _ = await sut.Request([]); + _ = await sut.Request([], handler2Name); + _ = await sut.Request(new SitecoreLayoutRequest { { RequestKeys.SiteName, site2Name } }, handler2Name); + + // Assert + result.Requests.Should().HaveCount(3); + string req1 = await result.Requests[0].Content!.ReadAsStringAsync(); + req1.Should().Contain(site1Name); + string req2 = await result.Requests[1].Content!.ReadAsStringAsync(); + req2.Should().Contain(site1Name); + string req3 = await result.Requests[2].Content!.ReadAsStringAsync(); + req3.Should().Contain(site2Name); + + // Since we replace the client we validate the original + originalClient.HttpClient.DefaultRequestHeaders.Single(h => h.Key == "sc_apikey").Value.Single().Should().Be(apiKey); + } + + private static HttpResponseMessage GenerateGqlResponse(string json) + { + HttpResponseMessage result = new(HttpStatusCode.OK) + { + Content = new StringContent($"{{ \"data\": {json} }}") + }; + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/graphql+json"); + + return result; + } +} \ No newline at end of file diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs new file mode 100644 index 0000000..92aef0e --- /dev/null +++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Exceptions/LayoutServiceGraphQlExceptionFixture.cs @@ -0,0 +1,24 @@ +using FluentAssertions; +using GraphQL; +using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers.GraphQL; +using Xunit; + +namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.Exceptions; + +public class LayoutServiceGraphQlExceptionFixture +{ + [Theory] + [AutoNSubstituteData] + public void LayoutServiceGraphQlException_GraphQlError_Get(GraphQLError error) + { + // Arrange + LayoutServiceGraphQlException sut = new(error); + + // Act + GraphQLError result = sut.GraphQlError; + + // Assert + result.Should().Be(error); + } +} \ No newline at end of file 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 aaced68..1a23a57 100644 --- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/Extensions/SitecoreLayoutClientBuilderExtensionsFixture.cs @@ -8,6 +8,7 @@ using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Request.Handlers.GraphQL; using Xunit; namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.Extensions; @@ -165,6 +166,36 @@ public void WithDefaultRequestOptions_RequestDefaultsHasApiKeySpecified_ServiceP options.RequestDefaults.ApiKey().Should().Be("test_api_key"); } + [Theory] + [AutoNSubstituteData] + public void AddGraphQlHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string name, string siteName, string apiKey, Uri uri) + { + // Act + ILayoutRequestHandlerBuilder result = builder.AddGraphQlHandler(name, siteName, apiKey, uri); + + // Assert + ServiceProvider provider = result.Services.BuildServiceProvider(); + SitecoreLayoutRequestOptions options = provider.GetRequiredService>().Value; + options.RequestDefaults.ApiKey().Should().Be(apiKey); + options.RequestDefaults.SiteName().Should().Be(siteName); + options.RequestDefaults.Language().Should().Be("en"); + } + + [Theory] + [AutoNSubstituteData] + public void AddGraphQlWithContextHandler_Minimal_IsValid(SitecoreLayoutClientBuilder builder, string contextId) + { + // Act + ILayoutRequestHandlerBuilder result = builder.AddGraphQlWithContextHandler("Test", contextId); + + // Assert + ServiceProvider provider = result.Services.BuildServiceProvider(); + SitecoreLayoutRequestOptions options = provider.GetRequiredService>().Value; + options.RequestDefaults.ContextId().Should().Be(contextId); + options.RequestDefaults.SiteName().Should().BeNull(); + options.RequestDefaults.Language().Should().Be("en"); + } + private static IEnumerable EmptyStrings() { yield return [null!]; diff --git a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/MockModels/HttpMessageHandlerWrapper.cs b/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/MockModels/HttpMessageHandlerWrapper.cs deleted file mode 100644 index 8db5fbe..0000000 --- a/tests/Sitecore.AspNetCore.SDK.LayoutService.Client.Tests/MockModels/HttpMessageHandlerWrapper.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Tests.MockModels; - -public class HttpMessageHandlerWrapper : HttpMessageHandler -{ - public List Messages { get; } = []; - - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - Messages.Add(request); - return Task.FromResult(new HttpResponseMessage()); - } -} \ No newline at end of file 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 acf6c5a..84c0131 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 @@ -8,6 +8,7 @@ using NSubstitute.ExceptionExtensions; using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; using Sitecore.AspNetCore.SDK.AutoFixture.Extensions; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration; using Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; @@ -49,7 +50,7 @@ public class HttpLayoutRequestHandlerFixture public static Action HttpClientWithMockedHttpMessageHandler => f => { - HttpMessageHandlerWrapper mockHttpHandler = new(); + MockHttpMessageHandler mockHttpHandler = new(); HttpClient client = new(mockHttpHandler) { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/ExperienceEditorMiddlewareBenchmarks.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/ExperienceEditorMiddlewareBenchmarks.cs index 3a66de3..d5b44f2 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/ExperienceEditorMiddlewareBenchmarks.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/ExperienceEditorMiddlewareBenchmarks.cs @@ -1,4 +1,5 @@ -using BenchmarkDotNet.Attributes; +using System.Diagnostics.CodeAnalysis; +using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; @@ -13,6 +14,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks; [SimpleJob] [MemoryDiagnoser] +[ExcludeFromCodeCoverage] public class ExperienceEditorMiddlewareBenchmarks : IDisposable { private readonly TestServer _server; diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/Program.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/Program.cs index ca103b5..e243da6 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/Program.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/Program.cs @@ -1,8 +1,10 @@ -using BenchmarkDotNet.Configs; +using System.Diagnostics.CodeAnalysis; +using BenchmarkDotNet.Configs; using BenchmarkDotNet.Running; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks; +[ExcludeFromCodeCoverage] internal class Program { private static void Main() diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/RenderingEngineBenchmarks.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/RenderingEngineBenchmarks.cs index ab61c9c..2bd3f89 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/RenderingEngineBenchmarks.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/RenderingEngineBenchmarks.cs @@ -1,7 +1,9 @@ -using System.Net; +using System.Diagnostics.CodeAnalysis; +using System.Net; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests; @@ -11,17 +13,18 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks; [SimpleJob] [MemoryDiagnoser] +[ExcludeFromCodeCoverage] public class RenderingEngineBenchmarks : IDisposable { private TestServer? _server; private HttpClient? _client; - private HttpLayoutClientMessageHandler? _mockClientHandler; + private MockHttpMessageHandler? _mockClientHandler; [GlobalSetup] public void Setup() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/TrackingBenchmarks.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/TrackingBenchmarks.cs index 9a035a2..0b9137a 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/TrackingBenchmarks.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/TrackingBenchmarks.cs @@ -1,9 +1,11 @@ -using System.Net; +using System.Diagnostics.CodeAnalysis; +using System.Net; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests; @@ -16,18 +18,19 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks; [SimpleJob] [MemoryDiagnoser] +[ExcludeFromCodeCoverage] public class TrackingBenchmarks : IDisposable { private TestServer? _server; private HttpClient? _client; - private HttpLayoutClientMessageHandler? _mockClientHandler; + private MockHttpMessageHandler? _mockClientHandler; private RenderingEngineBenchmarks? _baseLineTestInstance; [GlobalSetup(Target = nameof(RegularHomePageRequestWithTracking))] public void TrackingBenchmarksSetup() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ComplexModelBindingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ComplexModelBindingFixture.cs index 4e84b35..f60c81a 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ComplexModelBindingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ComplexModelBindingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class ComplexModelBindingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ComplexModelBindingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomModelContextBindingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomModelContextBindingFixture.cs index 693bc30..a4bab21 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomModelContextBindingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomModelContextBindingFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class CustomModelContextBindingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public CustomModelContextBindingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomResolverBindingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomResolverBindingFixture.cs index ffc4c13..0167c43 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomResolverBindingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomResolverBindingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.ComponentModels; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class CustomResolverBindingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public CustomResolverBindingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingErrorHandlingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingErrorHandlingFixture.cs index c90ed18..f02dda9 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingErrorHandlingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingErrorHandlingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class ModelBindingErrorHandlingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ModelBindingErrorHandlingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingFixture.cs index e22357a..8c7e5f7 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ModelBindingFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Response; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class ModelBindingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ModelBindingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ViewFieldsBindingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ViewFieldsBindingFixture.cs index ded299b..8f8f7ef 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ViewFieldsBindingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/ViewFieldsBindingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Bin public class ViewFieldsBindingFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ViewFieldsBindingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ControllerMiddlewareFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ControllerMiddlewareFixture.cs index c372a8d..1ebb157 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ControllerMiddlewareFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ControllerMiddlewareFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Xunit; @@ -14,14 +15,14 @@ public class ControllerMiddlewareFixture : IDisposable private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ControllerMiddlewareFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/LoggingComponentRendererFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/LoggingComponentRendererFixture.cs index 4661cb2..3b04725 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/LoggingComponentRendererFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/LoggingComponentRendererFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Logging; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Cus public class LoggingComponentRendererFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public LoggingComponentRendererFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/MultipleComponentsAddedFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/MultipleComponentsAddedFixture.cs index d635c05..9ff33f2 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/MultipleComponentsAddedFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/MultipleComponentsAddedFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Cus public class MultipleComponentsAddedFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public MultipleComponentsAddedFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/PartialViewRendererFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/PartialViewRendererFixture.cs index bd2d55e..d66e022 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/PartialViewRendererFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/CustomRenderTypes/PartialViewRendererFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Cus public class PartialViewRendererFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public PartialViewRendererFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ErrorHandlingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ErrorHandlingFixture.cs index a5c9a76..c9141d5 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ErrorHandlingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ErrorHandlingFixture.cs @@ -4,6 +4,7 @@ using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Exceptions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; @@ -22,7 +23,7 @@ public class ErrorHandlingFixture public static Action ValidHttpClient => f => { TestServerBuilder testHostBuilder = new(); - HttpLayoutClientMessageHandler mockClientHandler = new(); + MockHttpMessageHandler mockClientHandler = new(); testHostBuilder .ConfigureServices(builder => { @@ -45,7 +46,7 @@ public class ErrorHandlingFixture public static Action InvalidHttpClient => f => { TestServerBuilder testHostBuilder = new(); - HttpLayoutClientMessageHandler mockClientHandler = new(); + MockHttpMessageHandler mockClientHandler = new(); testHostBuilder .ConfigureServices(builder => { @@ -68,7 +69,7 @@ public class ErrorHandlingFixture public static Action InvalidHttpMessageConfiguration => f => { TestServerBuilder testHostBuilder = new(); - HttpLayoutClientMessageHandler mockClientHandler = new(); + MockHttpMessageHandler mockClientHandler = new(); testHostBuilder .ConfigureServices(builder => { @@ -91,7 +92,7 @@ public class ErrorHandlingFixture [Theory] [AutoNSubstituteData(nameof(InvalidHttpMessageConfiguration))] - public async Task HttpMessageConfigurationError_Returns_SitecoreLayoutServiceMessageConfigurationException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpMessageConfigurationError_Returns_SitecoreLayoutServiceMessageConfigurationException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange clientHandler.Responses.Push(new HttpResponseMessage @@ -134,7 +135,7 @@ public async Task HttpRequestTimeoutError_Returns_CouldNotContactSitecoreLayoutS [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponse50xErrors_Return_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponse50xErrors_Return_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange HttpStatusCode[] responseStatuses = @@ -184,7 +185,7 @@ public async Task HttpResponse50xErrors_Return_InvalidResponseSitecoreLayoutServ [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponse40xErrors_Return_InvalidRequestSitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponse40xErrors_Return_InvalidRequestSitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange HttpStatusCode[] responseStatuses = @@ -246,7 +247,7 @@ public async Task HttpResponse40xErrors_Return_InvalidRequestSitecoreLayoutServi [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponse404Error_Returns_ContentAndItemNotFoundSitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponse404Error_Returns_ContentAndItemNotFoundSitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange const HttpStatusCode responseStatus = HttpStatusCode.NotFound; @@ -280,7 +281,7 @@ public async Task HttpResponse404Error_Returns_ContentAndItemNotFoundSitecoreLay [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponseDeserializationError_Returns_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponseDeserializationError_Returns_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange HttpStatusCode responseStatus = HttpStatusCode.NotFound; @@ -307,7 +308,7 @@ public async Task HttpResponseDeserializationError_Returns_InvalidResponseSiteco [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponse10xErrors_Return_SitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponse10xErrors_Return_SitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange HttpStatusCode[] responseStatuses = @@ -347,7 +348,7 @@ public async Task HttpResponse10xErrors_Return_SitecoreLayoutServiceClientExcept [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task HttpResponse30xErrors_Return_SitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task HttpResponse30xErrors_Return_SitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { // Arrange HttpStatusCode[] responseStatuses = @@ -397,7 +398,7 @@ public async Task HttpResponse30xErrors_Return_SitecoreLayoutServiceClientExcept [Theory] [AutoNSubstituteData(nameof(ValidHttpClient))] - public async Task ErrorView_Returns_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, HttpLayoutClientMessageHandler clientHandler) + public async Task ErrorView_Returns_InvalidResponseSitecoreLayoutServiceClientException(TestServer server, MockHttpMessageHandler clientHandler) { clientHandler.Responses.Push(new HttpResponseMessage { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ForwardHeaders/ForwardHeadersToLayoutServiceFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ForwardHeaders/ForwardHeadersToLayoutServiceFixture.cs index 4f627aa..fb86afb 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ForwardHeaders/ForwardHeadersToLayoutServiceFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/ForwardHeaders/ForwardHeadersToLayoutServiceFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ public class ForwardHeadersToLayoutServiceFixture : IDisposable { private const string TestHeaderRhResponse = "testHeaderResponseFromRenderingHost"; private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ForwardHeadersToLayoutServiceFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); _ = testHostBuilder .ConfigureServices(builder => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/GlobalMiddlewareFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/GlobalMiddlewareFixture.cs index 7dc8e81..244188d 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/GlobalMiddlewareFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/GlobalMiddlewareFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -16,14 +17,14 @@ public class GlobalMiddlewareFixture : IDisposable private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public GlobalMiddlewareFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/AdvanceLocalizationFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/AdvanceLocalizationFixture.cs index 16ef24b..966ee98 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/AdvanceLocalizationFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/AdvanceLocalizationFixture.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -15,13 +16,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Loc public class AdvanceLocalizationFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public AdvanceLocalizationFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/DefaultLocalizationFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/DefaultLocalizationFixture.cs index 88b5a65..3446375 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/DefaultLocalizationFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/DefaultLocalizationFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Loc public class DefaultLocalizationFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public DefaultLocalizationFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationFixture.cs index ce13332..9a859bf 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Loc public class LocalizationFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public LocalizationFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationUsingAttributeMiddlewareFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationUsingAttributeMiddlewareFixture.cs index a511a7d..3556668 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationUsingAttributeMiddlewareFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Localization/LocalizationUsingAttributeMiddlewareFixture.cs @@ -4,6 +4,7 @@ using FluentAssertions; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Loc public class LocalizationUsingAttributeMiddlewareFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public LocalizationUsingAttributeMiddlewareFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Multisite/MultisiteFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Multisite/MultisiteFixture.cs index 4770ac3..2bd160e 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Multisite/MultisiteFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Multisite/MultisiteFixture.cs @@ -5,6 +5,7 @@ using GraphQL.Client.Abstractions; using Microsoft.AspNetCore.TestHost; using NSubstitute; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; @@ -18,13 +19,13 @@ public class MultisiteFixture : IDisposable { private const string DefaultSiteName = "defaultSiteName"; private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public MultisiteFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestDefaultsConfigurationFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestDefaultsConfigurationFixture.cs index 57b3ac2..f23b75e 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestDefaultsConfigurationFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestDefaultsConfigurationFixture.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures; public class RequestDefaultsConfigurationFixture : IDisposable { - private readonly HttpLayoutClientMessageHandler _clientHandler; + private readonly MockHttpMessageHandler _clientHandler; private readonly TestServer _server; public RequestDefaultsConfigurationFixture() { TestServerBuilder testHostBuilder = new(); - _clientHandler = new HttpLayoutClientMessageHandler(); + _clientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestExtensionsFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestExtensionsFixture.cs index fd473ce..d17afc7 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestExtensionsFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestExtensionsFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures; public class RequestExtensionsFixture : IDisposable { - private readonly HttpLayoutClientMessageHandler _clientHandler; + private readonly MockHttpMessageHandler _clientHandler; private readonly TestServer _server; public RequestExtensionsFixture() { TestServerBuilder testHostBuilder = new(); - _clientHandler = new HttpLayoutClientMessageHandler(); + _clientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestHeadersValidationFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestHeadersValidationFixture.cs index 5278d56..9c2acb0 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestHeadersValidationFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestHeadersValidationFixture.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; @@ -11,7 +12,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures; public class RequestHeadersValidationFixture : IDisposable { - private HttpLayoutClientMessageHandler _clientHandler = new(); + private MockHttpMessageHandler _clientHandler = new(); private TestServer _server = null!; [Fact] @@ -64,7 +65,7 @@ public void Dispose() private void ConfigureServices(string[] nonValidatedHeaders) { TestServerBuilder testHostBuilder = new(); - _clientHandler = new HttpLayoutClientMessageHandler(); + _clientHandler = new MockHttpMessageHandler(); Dictionary headers = new() { { "User-Agent", ["site;core"] } diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestMappingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestMappingFixture.cs index 3f08421..3238d3c 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestMappingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/RequestMappingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Primitives; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Request; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; @@ -22,14 +23,14 @@ public class RequestMappingFixture : IDisposable private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public RequestMappingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/EdgeSitemapProxyFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/EdgeSitemapProxyFixture.cs index bdca6d7..1d9885c 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/EdgeSitemapProxyFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/EdgeSitemapProxyFixture.cs @@ -4,6 +4,7 @@ using GraphQL.Client.Abstractions; using Microsoft.AspNetCore.TestHost; using NSubstitute; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Mocks; using Sitecore.AspNetCore.SDK.SearchOptimization.Extensions; using Sitecore.AspNetCore.SDK.SearchOptimization.Models; @@ -15,7 +16,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Sea public class EdgeSitemapProxyFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler = new(); + private readonly MockHttpMessageHandler _mockClientHandler = new(); private readonly ISitemapService _mockSitemapService = Substitute.For(); private readonly Uri _edgeSitemapUrl = new("https://xmcloud-test.com/sitemap.xml"); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/SitemapProxyFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/SitemapProxyFixture.cs index 44709e6..2d031a0 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/SitemapProxyFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SearchOptimization/SitemapProxyFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Mocks; using Sitecore.AspNetCore.SDK.SearchOptimization.Extensions; using Xunit; @@ -10,7 +11,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Sea public class SitemapProxyFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler = new(); + private readonly MockHttpMessageHandler _mockClientHandler = new(); private readonly Uri _cdInstanceUri = new("http://cd"); public SitemapProxyFixture() diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SitecoreLayoutClientBuilderExtensionsFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SitecoreLayoutClientBuilderExtensionsFixture.cs index 93401ed..77d2c8c 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SitecoreLayoutClientBuilderExtensionsFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/SitecoreLayoutClientBuilderExtensionsFixture.cs @@ -1,6 +1,7 @@ using FluentAssertions; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Options; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Configuration; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.LayoutService.Client.Interfaces; @@ -11,13 +12,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures; public class SitecoreLayoutClientBuilderExtensionsFixture : IDisposable { - private readonly HttpLayoutClientMessageHandler _messageHandler; + private readonly MockHttpMessageHandler _messageHandler; private readonly TestServer _server; public SitecoreLayoutClientBuilderExtensionsFixture() { TestServerBuilder testHostBuilder = new(); - _messageHandler = new HttpLayoutClientMessageHandler(); + _messageHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/AllFieldTagHelpersFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/AllFieldTagHelpersFixture.cs index 31d823c..bf853cb 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/AllFieldTagHelpersFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/AllFieldTagHelpersFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class AllFieldTagHelpersFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public AllFieldTagHelpersFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/DateFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/DateFieldTagHelperFixture.cs index 707c6c8..60f4aa3 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/DateFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/DateFieldTagHelperFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class DateFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public DateFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/FileFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/FileFieldTagHelperFixture.cs index f34b635..9c29d78 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/FileFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/FileFieldTagHelperFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class FileFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public FileFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/ImageFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/ImageFieldTagHelperFixture.cs index bde8dc1..95f9877 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/ImageFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/ImageFieldTagHelperFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -13,13 +14,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class ImageFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public ImageFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/LinkFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/LinkFieldTagHelperFixture.cs index 83cb17e..6929244 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/LinkFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/LinkFieldTagHelperFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class LinkFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public LinkFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/NumberFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/NumberFieldTagHelperFixture.cs index 2c2849b..113a51b 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/NumberFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/NumberFieldTagHelperFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ public class NumberFieldTagHelperFixture : IDisposable { private const decimal TestValue = 1.21M; private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public NumberFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/PlaceholderTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/PlaceholderTagHelperFixture.cs index 4600a0f..3784db1 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/PlaceholderTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/PlaceholderTagHelperFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -12,13 +13,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class PlaceholderTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public PlaceholderTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/RichTextFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/RichTextFieldTagHelperFixture.cs index 1e248ae..23e1ef2 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/RichTextFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/RichTextFieldTagHelperFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class RichTextFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public RichTextFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/TextFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/TextFieldTagHelperFixture.cs index bf0946e..31417b2 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/TextFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/TagHelpers/TextFieldTagHelperFixture.cs @@ -3,6 +3,7 @@ using FluentAssertions; using HtmlAgilityPack; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -14,13 +15,13 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tag public class TextFieldTagHelperFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); public TextFieldTagHelperFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); testHostBuilder .ConfigureServices(builder => { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/AttributeBasedTrackingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/AttributeBasedTrackingFixture.cs index 2606723..05a0e59 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/AttributeBasedTrackingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/AttributeBasedTrackingFixture.cs @@ -1,6 +1,7 @@ using System.Net; using FluentAssertions; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -25,7 +26,7 @@ public class AttributeBasedTrackingFixture : IDisposable private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); @@ -34,7 +35,7 @@ public class AttributeBasedTrackingFixture : IDisposable public AttributeBasedTrackingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); _ = testHostBuilder .ConfigureServices(builder => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingFixture.cs index 7dd33fb..1724ae3 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.TestData; @@ -26,7 +27,7 @@ public class TrackingFixture : IDisposable private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler; + private readonly MockHttpMessageHandler _mockClientHandler; private readonly Uri _layoutServiceUri = new("http://layout.service"); @@ -35,7 +36,7 @@ public class TrackingFixture : IDisposable public TrackingFixture() { TestServerBuilder testHostBuilder = new(); - _mockClientHandler = new HttpLayoutClientMessageHandler(); + _mockClientHandler = new MockHttpMessageHandler(); _ = testHostBuilder .ConfigureServices(builder => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingProxyFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingProxyFixture.cs index 74bee0a..1de71f1 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingProxyFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/Fixtures/Tracking/TrackingProxyFixture.cs @@ -2,6 +2,7 @@ using FluentAssertions; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.TestHost; +using Sitecore.AspNetCore.SDK.AutoFixture.Mocks; using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Mocks; @@ -15,7 +16,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Tra public class TrackingProxyFixture : IDisposable { private readonly TestServer _server; - private readonly HttpLayoutClientMessageHandler _mockClientHandler = new(); + private readonly MockHttpMessageHandler _mockClientHandler = new(); private readonly Uri _layoutServiceUri = new("http://layout.service"); private readonly Uri _cmInstanceUri = new("http://layout.service"); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/HttpLayoutClientMessageHandler.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/HttpLayoutClientMessageHandler.cs deleted file mode 100644 index 7a6b72a..0000000 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/HttpLayoutClientMessageHandler.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests; - -public class HttpLayoutClientMessageHandler : HttpMessageHandler -{ - public Stack Responses { get; } = new(); - - public List Requests { get; } = []; - - public bool WasInvoked { get; private set; } - - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - Requests.Add(request); - WasInvoked = true; - HttpResponseMessage response = Responses.Pop(); - return Task.FromResult(response); - } -} \ No newline at end of file diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/ContentBlock.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/ContentBlock.cs index 48ecd53..410ee63 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/ContentBlock.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/ContentBlock.cs @@ -1,7 +1,9 @@ -using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model.Fields; +using System.Diagnostics.CodeAnalysis; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model.Fields; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class ContentBlock { public TextField? Heading { get; set; } diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/HeaderBlock.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/HeaderBlock.cs index 1f04235..d6aff72 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/HeaderBlock.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/HeaderBlock.cs @@ -1,7 +1,9 @@ -using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model.Fields; +using System.Diagnostics.CodeAnalysis; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model.Fields; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class HeaderBlock { public TextField? Heading1 { get; set; } diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelBinderProviderContext.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelBinderProviderContext.cs index d4aaacc..4419616 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelBinderProviderContext.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelBinderProviderContext.cs @@ -1,7 +1,9 @@ -using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class TestModelBinderProviderContext(ModelMetadata modelMetadata) : ModelBinderProviderContext { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelMetadata.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelMetadata.cs index 99d1db4..903f796 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelMetadata.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestModelMetadata.cs @@ -1,8 +1,10 @@ -using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class TestModelMetadata(ModelMetadataIdentity identity, Type type) : ModelMetadata(identity) { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestPlaceholderFeature.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestPlaceholderFeature.cs index cd4beaf..39c3779 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestPlaceholderFeature.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestPlaceholderFeature.cs @@ -1,7 +1,9 @@ -using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; +using System.Diagnostics.CodeAnalysis; +using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class TestPlaceholderFeature : IPlaceholderFeature { public string? Content { get; set; } diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestSitecoreLayoutBindingSource.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestSitecoreLayoutBindingSource.cs index adb130d..57ad6d9 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestSitecoreLayoutBindingSource.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Mocks/TestSitecoreLayoutBindingSource.cs @@ -1,9 +1,11 @@ -using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Mvc.ModelBinding; using Sitecore.AspNetCore.SDK.RenderingEngine.Binding.Sources; using Sitecore.AspNetCore.SDK.RenderingEngine.Interfaces; namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Mocks; +[ExcludeFromCodeCoverage] public class TestSitecoreLayoutBindingSource() : SitecoreLayoutBindingSource("test", "test", false, false) { diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ComponentRendererDescriptorFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ComponentRendererDescriptorFixture.cs index 7040565..4f9a297 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ComponentRendererDescriptorFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ComponentRendererDescriptorFixture.cs @@ -1,4 +1,5 @@ -using AutoFixture; +using System.Diagnostics.CodeAnalysis; +using AutoFixture; using FluentAssertions; using NSubstitute; using Sitecore.AspNetCore.SDK.AutoFixture.Attributes; @@ -10,6 +11,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Rendering; public class ComponentRendererDescriptorFixture { // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup() { return f => diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/LoggingComponentRendererFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/LoggingComponentRendererFixture.cs index 4c9a385..0ade8ba 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/LoggingComponentRendererFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/LoggingComponentRendererFixture.cs @@ -1,4 +1,5 @@ using System.ComponentModel.Design; +using System.Diagnostics.CodeAnalysis; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -16,6 +17,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Rendering; public class LoggingComponentRendererFixture { // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { ILogger? logger = Substitute.For>(); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/PartialViewComponentRendererFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/PartialViewComponentRendererFixture.cs index dbaee82..fc45e5b 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/PartialViewComponentRendererFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/PartialViewComponentRendererFixture.cs @@ -1,4 +1,5 @@ using System.ComponentModel.Design; +using System.Diagnostics.CodeAnalysis; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -19,6 +20,7 @@ public class PartialViewComponentRendererFixture private const string Locator = "testLocator"; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { f.Inject(new ViewContext()); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/SitecoreRenderingContextFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/SitecoreRenderingContextFixture.cs index 60593d2..96406c2 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/SitecoreRenderingContextFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/SitecoreRenderingContextFixture.cs @@ -1,4 +1,5 @@ -using AutoFixture; +using System.Diagnostics.CodeAnalysis; +using AutoFixture; using FluentAssertions; using Microsoft.AspNetCore.Mvc.ModelBinding; using Sitecore.AspNetCore.SDK.RenderingEngine.Rendering; @@ -9,6 +10,7 @@ namespace Sitecore.AspNetCore.SDK.RenderingEngine.Tests.Rendering; public class SitecoreRenderingContextFixture { // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { f.Inject(new BindingInfo()); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ViewComponentComponentRendererFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ViewComponentComponentRendererFixture.cs index fc7c687..083f0b5 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ViewComponentComponentRendererFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/Rendering/ViewComponentComponentRendererFixture.cs @@ -1,4 +1,5 @@ using System.ComponentModel.Design; +using System.Diagnostics.CodeAnalysis; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -20,6 +21,7 @@ public class ViewComponentComponentRendererFixture private const string Locator = "testLocator"; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { IHtmlHelper? htmlHelper = Substitute.For(); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/DateTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/DateTagHelperFixture.cs index e0ea415..33c2a2c 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/DateTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/DateTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -23,6 +24,7 @@ public class DateTagHelperFixture private readonly DateTime _date = DateTime.Parse("2012-05-04T00:00:00Z", CultureInfo.InvariantCulture); // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { TagHelperContext tagHelperContext = new([], new Dictionary(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/ImageTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/ImageTagHelperFixture.cs index f4c681e..ab8d12e 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/ImageTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/ImageTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -26,6 +27,7 @@ public class ImageTagHelperFixture private readonly Image _image = new() { Src = "http://styleguide/-/media/styleguide/data/media/img/sc_logo.png?iar=0&hash=F313AD90AE547CAB09277E42509E289B", Alt = "Sitecore Logo", Width = 100, Height = 100, VSpace = 10, HSpace = 10, Border = 1, Class = "test", Title = "title" }; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { TagHelperContext tagHelperContext = new([], new Dictionary(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/NumberTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/NumberTagHelperFixture.cs index 3d153d8..c577671 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/NumberTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/NumberTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -25,6 +26,7 @@ public class NumberTagHelperFixture private const string Editable = "{\"commands\":[{\"click\":\"chrome:field:editcontrol({command:\\\"webedit: editnumber\\\"})\",\"header\":\"Edit number\",\"icon\":\"/temp/iconcache/wordprocessing/16x16/word_count.png\",\"disabledIcon\":\"/temp/word_count_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Edit number\",\"type\":\"\"},{\"click\":\"chrome:common:edititem({command:\\\"webedit: open\\\"})\",\"header\":\"Edit the related item\",\"icon\":\"/temp/iconcache/office/16x16/cubes.png\",\"disabledIcon\":\"/temp/cubes_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Edit the related item in the Content Editor.\",\"type\":\"common\"},{\"click\":\"chrome:rendering:personalize({command:\\\"webedit: personalize\\\"})\",\"header\":\"Personalize\",\"icon\":\"/temp/iconcache/office/16x16/users_family.png\",\"disabledIcon\":\"/temp/users_family_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Create or edit personalization for this component.\",\"type\":\"sticky\"},{\"click\":\"chrome:rendering:editvariations({command:\\\"webedit: editvariations\\\"})\",\"header\":\"Edit variations\",\"icon\":\"/temp/iconcache/office/16x16/windows.png\",\"disabledIcon\":\"/temp/windows_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Edit the variations.\",\"type\":\"sticky\"}],\"contextItemUri\":\"sitecore://master/{30B7EF86-9214-58E8-9072-6B0CEFE157CD}?lang=en&ver=1\",\"custom\":{},\"displayName\":\"sample\",\"expandedDisplayName\":null}9.99"; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { TagHelperContext tagHelperContext = new([], new Dictionary(), Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)); diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/RichTextTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/RichTextTagHelperFixture.cs index 85fc8ca..2fbb4e4 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/RichTextTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/RichTextTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -23,6 +24,7 @@ public class RichTextTagHelperFixture private const string TestEditableMarkup = "{\"commands\":[{\"click\":\"chrome:field:editcontrol({command:\\\"webedit:edithtml\\\"})\",\"header\":\"Edit Text\",\"icon\":\"/temp/iconcache/office/16x16/pencil.png\",\"disabledIcon\":\"/temp/pencil_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Edit the text\",\"type\":null},{\"click\":\"chrome:field:execute({command:\\\"bold\\\", userInterface:true, value:true})\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/font_style_bold.png\",\"disabledIcon\":\"/temp/font_style_bold_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Bold\",\"type\":null},{\"click\":\"chrome:field:execute({command:\\\"Italic\\\", userInterface:true, value:true})\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/font_style_italics.png\",\"disabledIcon\":\"/temp/font_style_italics_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Italic\",\"type\":null},{\"click\":\"chrome:field:execute({command:\\\"Underline\\\", userInterface:true, value:true})\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/font_style_underline.png\",\"disabledIcon\":\"/temp/font_style_underline_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Underline\",\"type\":null},{\"click\":\"chrome:field:insertexternallink\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/earth_link.png\",\"disabledIcon\":\"/temp/earth_link_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Insert an external link into the text field.\",\"type\":null},{\"click\":\"chrome:field:insertlink\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/link.png\",\"disabledIcon\":\"/temp/link_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Insert a link into the text field.\",\"type\":null},{\"click\":\"chrome:field:removelink\",\"header\":\"\",\"icon\":\"/temp/iconcache/office/16x16/link_broken.png\",\"disabledIcon\":\"/temp/link_broken_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Remove link.\",\"type\":null},{\"click\":\"chrome:field:insertimage\",\"header\":\"Insert image\",\"icon\":\"/temp/iconcache/office/16x16/photo_landscape.png\",\"disabledIcon\":\"/temp/photo_landscape_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Insert an image into the text field.\",\"type\":null},{\"click\":\"chrome:common:edititem({command:\\\"webedit:open\\\"})\",\"header\":\"Edit the related item\",\"icon\":\"/temp/iconcache/office/16x16/cubes.png\",\"disabledIcon\":\"/temp/cubes_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Edit the related item in the Content Editor.\",\"type\":\"common\"},{\"click\":\"chrome:rendering:personalize({command:\\\"webedit:personalize\\\"})\",\"header\":\"Personalize\",\"icon\":\"/temp/iconcache/office/16x16/users_family.png\",\"disabledIcon\":\"/temp/users_family_disabled16x16.png\",\"isDivider\":false,\"tooltip\":\"Create or edit personalization for this component.\",\"type\":\"sticky\"}],\"contextItemUri\":\"sitecore://master/{585596CA-7903-500B-8DF2-0357DD6E3FAC}?lang=en&ver=1\",\"custom\":{},\"displayName\":\"content\",\"expandedDisplayName\":null}This is a live set of examples of how to use JSS. For more information on using JSS, please see the documentation.\nThe content and layout of this page is defined in /data/routes/styleguide/en.yml\n"; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { TagHelperContext tagHelperContext = new( diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/TextFieldTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/TextFieldTagHelperFixture.cs index ab939d0..1e7a04e 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/TextFieldTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/Fields/TextFieldTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Text.Encodings.Web; using AutoFixture; using AutoFixture.Idioms; @@ -25,6 +26,7 @@ public class TextFieldTagHelperFixture private static readonly string TestMultilineText = $"This is the test text {Environment.NewLine} with line endings."; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { TagHelperContext tagHelperContext = new( diff --git a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs index 6794636..b87fe29 100644 --- a/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.RenderingEngine.Tests/TagHelpers/PlaceholderTagHelperFixture.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -35,6 +36,7 @@ public class PlaceholderTagHelperFixture private static IComponentRendererFactory _componentRendererFactory = null!; // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { // prevent nested recursion issues diff --git a/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/Extensions/TrackingApplicationConfigurationExtensionsFixture.cs b/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/Extensions/TrackingApplicationConfigurationExtensionsFixture.cs index 0caa8d5..985c1c3 100644 --- a/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/Extensions/TrackingApplicationConfigurationExtensionsFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/Extensions/TrackingApplicationConfigurationExtensionsFixture.cs @@ -1,4 +1,5 @@ -using AutoFixture; +using System.Diagnostics.CodeAnalysis; +using AutoFixture; using FluentAssertions; using NSubstitute; using Xunit; @@ -8,6 +9,7 @@ namespace Sitecore.AspNetCore.SDK.Tracking.Tests.Extensions; public class TrackingApplicationConfigurationExtensionsFixture { // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { IServiceProvider? services = Substitute.For(); diff --git a/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/TagHelpers/SitecoreVisitorIdentificationTagHelperFixture.cs b/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/TagHelpers/SitecoreVisitorIdentificationTagHelperFixture.cs index c33f8dd..6e4a283 100644 --- a/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/TagHelpers/SitecoreVisitorIdentificationTagHelperFixture.cs +++ b/tests/Sitecore.AspNetCore.SDK.Tracking.Tests/TagHelpers/SitecoreVisitorIdentificationTagHelperFixture.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Diagnostics.CodeAnalysis; using AutoFixture; using AutoFixture.Idioms; using FluentAssertions; @@ -22,6 +23,7 @@ namespace Sitecore.AspNetCore.SDK.Tracking.Tests.TagHelpers; public class SitecoreVisitorIdentificationTagHelperFixture { // ReSharper disable once UnusedMember.Global - Used by testing framework + [ExcludeFromCodeCoverage] public static Action AutoSetup => f => { ViewContext viewContext = new() @@ -266,6 +268,7 @@ public async Task ProcessAsync_ViRequestGACookieTrueNoResponseGACookie_OutputDos tagHelperOutput.Content.GetContent().Should().NotBe($"\"/>"); } + [ExcludeFromCodeCoverage] private class RequestCookies(Dictionary cookies) : Dictionary(cookies), IRequestCookieCollection {
This is a live set of examples of how to use JSS. For more information on using JSS, please see the documentation.
The content and layout of this page is defined in /data/routes/styleguide/en.yml
/data/routes/styleguide/en.yml
This is the test text {Environment.NewLine} with line endings.