-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Content Resolver Support (#14)
<!-- Provide a general summary of your changes in the Title above --> <!-- Apply the label "bug" or "enhacement" as applicable. --> ## Description / Motivation <!-- Describe your changes in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it fixes an open issue, please link to the issue here. --> This modifies the FieldParser to support Custom Content Resolvers returning modified JSON. This fixes #8 Added missing CONTRIBUTING file. Removed `AddSystemTextJson` which should not be used or needed as it pollutes the DI. ## Testing Added integration tests both for layout client and rendering engine binding leveraging the "Navigation" component from Headless SXA. - [X] The Unit & Intergration tests are passing. - [X] I have added the necesary tests to cover my changes. ## Terms <!-- Place an X in the [] to check. --> <!-- The Code of Conduct helps create a safe space for everyone. We require that everyone agrees to it. --> - [X] I agree to follow this project's [Code of Conduct](CODE_OF_CONDUCT.md). --------- Co-authored-by: Ivan Lieckens <[email protected]>
- Loading branch information
1 parent
a79266c
commit e0a4b12
Showing
18 changed files
with
648 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Contribution to the Sitecore ASP.NET Core SDK | ||
|
||
Thank you for your interest in contributing to our project. You can contribute with issues and PRs. Simply filing issues for problems you encounter is a great way to contribute. Contributing implementations is greatly appreciated. | ||
|
||
## Code of Conduct | ||
Please read the [Code of Conduct](./CODE_OF_CONDUCT.md) before participating, all contributors are expected to uphold this code. Please report unacceptable behavior to [[email protected]](mailto:[email protected]). | ||
|
||
## Reporting Issues | ||
|
||
We always welcome bug reports, feature requests and overall feedback. Here are a few tips on how you can make reporting your issue as effective as possible. | ||
|
||
### Finding Existing Issues | ||
|
||
Before filing a new issue, please search our [open issues](https://github.com/Sitecore/ASP.NET-Core-SDK/issues) to check if it already exists. | ||
|
||
If you do find an existing issue, please include your own feedback in the discussion. Do consider upvoting (reaction) the original post, as this helps us prioritize popular issues. | ||
|
||
### Use the right template | ||
|
||
When creating a new issue, please use the appropriate template. We have the following templates available: | ||
|
||
| Template | Description | | ||
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| Bug Report | Use this template to report a bug. | | ||
| Feature Request | Use this template to request a new feature. | | ||
| Question | Use this template to ask a question. For implementation specific questions please use [StackExchange](https://sitecore.stackexchange.com/). | | ||
| Report a security vulnerability | Use this template to report a security vulnerability. | | ||
|
||
### Writing a Good Bug Report | ||
|
||
Good bug reports make it easier for maintainers to verify and root cause the underlying problem. The better a bug report, the faster the problem will be resolved. Ideally, a bug report should contain the following information: | ||
|
||
* A high-level description of the problem. | ||
* A _minimal reproduction_, i.e. the smallest size of code/configuration required to reproduce the wrong behavior. | ||
* A description of the _expected behavior_, contrasted with the _actual behavior_ observed. | ||
* Information on the environment: Sitecore XM version, SDK version, etc. | ||
* Additional information, e.g. is it a regression from previous versions? are there any known workarounds? | ||
|
||
#### Why are Minimal Reproductions Important? | ||
|
||
A reproduction lets maintainers verify the presence of a bug, and diagnose the issue using a debugger. A _minimal_ reproduction is the smallest possible application demonstrating that bug. Minimal reproductions are generally preferable since they: | ||
|
||
1. Focus debugging efforts on a simple code snippet, | ||
2. Ensure that the problem is not caused by unrelated dependencies/configuration, | ||
3. Avoid the need to share production codebases. | ||
|
||
#### Are Minimal Reproductions Required? | ||
|
||
In certain cases, creating a minimal reproduction might not be practical (e.g. due to nondeterministic factors, external dependencies). In such cases you would be asked to provide as much information as possible, for example by sharing a memory dump of the failing application. If maintainers are unable to root cause the problem, they might still close the issue as not actionable. While not required, minimal reproductions are strongly encouraged and will significantly improve the chances of your issue being prioritized and fixed by the maintainers. | ||
|
||
#### How to Create a Minimal Reproduction | ||
|
||
The best way to create a minimal reproduction is gradually removing code and dependencies from a reproducing app, until the problem no longer occurs. A good minimal reproduction: | ||
|
||
* Excludes all unnecessary types, methods, code blocks, source files, nuget dependencies and project configurations. | ||
* Contains documentation or code comments illustrating expected vs actual behavior. | ||
* If possible, avoids performing any unneeded IO or system calls. | ||
|
||
## Contributiting Code | ||
All code contributions must be submitted by the standard GitHub pull request flow, or by logging an issue. | ||
|
||
### Accepting Contributions | ||
Sitecore has a _"No commitment"_ approach to this repository. The required functionality of the SDK and related XM Cloud features will be the driver for acceptance decisions. We are open to contributions from the community, but make no commitment to accept or incorporate changes. | ||
|
||
### Guidelines | ||
* Create a [fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) | ||
* Create a branch for your changes. Use /feat/ for new features, /fix/ for bug fixes and /new/ for breaking changes. | ||
* We observe strict code style rules, please ensure your changes follow the guidance provided by the analyzers. | ||
* [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) | ||
* [File Scoped Namespaces](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces) | ||
* Do not use `var` | ||
* We require all changes to be covered by tests. | ||
* When you are ready to submit your changes, [create a pull request from your fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) into this repository. | ||
* This repository is configured to use `Squash Merges` for all accepted contributions. This decision has been made to keep the commit history clean and concise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...tecore.AspNetCore.SDK.RenderingEngine.Integration.Tests/ComponentModels/CustomResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization.Converter; | ||
using Sitecore.AspNetCore.SDK.RenderingEngine.Binding.Attributes; | ||
|
||
namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.ComponentModels; | ||
|
||
public class CustomResolver | ||
{ | ||
[SitecoreComponentField(Name = FieldParser.CustomContentFieldKey)] | ||
public CustomResolverModel[]? CustomContent { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
...e.AspNetCore.SDK.RenderingEngine.Integration.Tests/ComponentModels/CustomResolverModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model.Fields; | ||
|
||
namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.ComponentModels | ||
{ | ||
public class CustomResolverModel | ||
{ | ||
public List<string>? Styles { get; set; } = []; | ||
|
||
public List<CustomResolverModel>? Children { get; set; } = []; | ||
|
||
public string? Href { get; set; } | ||
|
||
public string? Querystring { get; set; } | ||
|
||
public TextField? NavigationTitle { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
....SDK.RenderingEngine.Integration.Tests/ComponentModels/PartialDesignDynamicPlaceholder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Sitecore.AspNetCore.SDK.RenderingEngine.Binding.Attributes; | ||
|
||
namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.ComponentModels; | ||
|
||
public class PartialDesignDynamicPlaceholder | ||
{ | ||
[SitecoreComponentParameter(Name ="sig")] | ||
public string? Sig { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...re.SDK.RenderingEngine.Integration.Tests/Fixtures/Binding/CustomResolverBindingFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System.Net; | ||
using FluentAssertions; | ||
using HtmlAgilityPack; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Sitecore.AspNetCore.SDK.LayoutService.Client.Extensions; | ||
using Sitecore.AspNetCore.SDK.RenderingEngine.Extensions; | ||
using Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.ComponentModels; | ||
using Xunit; | ||
|
||
// ReSharper disable StringLiteralTypo | ||
namespace Sitecore.AspNetCore.SDK.RenderingEngine.Integration.Tests.Fixtures.Binding; | ||
|
||
public class CustomResolverBindingFixture : IDisposable | ||
{ | ||
private readonly TestServer _server; | ||
private readonly HttpLayoutClientMessageHandler _mockClientHandler; | ||
private readonly Uri _layoutServiceUri = new("http://layout.service"); | ||
|
||
public CustomResolverBindingFixture() | ||
{ | ||
TestServerBuilder testHostBuilder = new(); | ||
_mockClientHandler = new HttpLayoutClientMessageHandler(); | ||
testHostBuilder | ||
.ConfigureServices(builder => | ||
{ | ||
builder | ||
.AddSitecoreLayoutService() | ||
.AddHttpHandler("mock", _ => new HttpClient(_mockClientHandler) { BaseAddress = _layoutServiceUri }) | ||
.AsDefaultHandler(); | ||
builder.AddSitecoreRenderingEngine(options => | ||
{ | ||
options | ||
.AddModelBoundView<PartialDesignDynamicPlaceholder>("PartialDesignDynamicPlaceholder") | ||
.AddModelBoundView<CustomResolver>(name => name.Equals("Navigation", StringComparison.OrdinalIgnoreCase), "CustomResolver") | ||
.AddDefaultComponentRenderer(); | ||
}); | ||
}) | ||
.Configure(app => | ||
{ | ||
app.UseRouting(); | ||
app.UseSitecoreRenderingEngine(); | ||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapDefaultControllerRoute(); | ||
}); | ||
}); | ||
|
||
_server = testHostBuilder.BuildServer(new Uri("http://localhost")); | ||
} | ||
|
||
[Fact] | ||
public async Task SitecoreLayoutModelBinders_BindDataCorrectly() | ||
{ | ||
// Arrange | ||
string json = await File.ReadAllTextAsync("./Json/headlessSxa.json"); | ||
_mockClientHandler.Responses.Push(new HttpResponseMessage | ||
{ | ||
StatusCode = HttpStatusCode.OK, | ||
Content = new StringContent(json) | ||
}); | ||
|
||
HttpClient client = _server.CreateClient(); | ||
|
||
// Act | ||
string response = await client.GetStringAsync(new Uri("/", UriKind.Relative)); | ||
|
||
HtmlDocument doc = new(); | ||
doc.LoadHtml(response); | ||
HtmlNode? sectionNode = doc.DocumentNode.ChildNodes["head"].ChildNodes.First(n => n.HasClass("custom-resolver")); | ||
|
||
// Assert | ||
sectionNode.ChildNodes["ul"].ChildNodes.Count(c => c.Name.Equals("li")).Should().Be(1); | ||
sectionNode.ChildNodes["ul"].ChildNodes["li"].ChildNodes.Count(c => c.Name.Equals("span")).Should().Be(1); | ||
sectionNode.ChildNodes["ul"].ChildNodes["li"].ChildNodes["span"].InnerText.Should().Be("Home"); | ||
|
||
sectionNode.ChildNodes["ul"].ChildNodes["li"].ChildNodes["ul"].ChildNodes.Count(c => c.Name.Equals("li")).Should().Be(1); | ||
sectionNode.ChildNodes["ul"].ChildNodes["li"].ChildNodes["ul"].ChildNodes["li"].ChildNodes["span"].InnerText.Should().Be("About"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_server.Dispose(); | ||
_mockClientHandler.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.