Skip to content

Commit

Permalink
Allow to add sections to layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 16, 2024
1 parent ce709b2 commit b509a54
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Modules/Layouting/Provider/LayoutBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ public LayoutBuilder Add(IHandlerBuilder handler)
return this;
}

/// <summary>
/// Creates a new layout and registers it at the given path.
/// </summary>
/// <param name="section">The path of the section to be added</param>
/// <returns>The newly created section</returns>
public LayoutBuilder AddSection(string section)
{
var child = Layout.Create();

Add(section, child);

return child;
}

public LayoutBuilder Add(IConcernBuilder concern)
{
_Concerns.Add(concern);
Expand Down
31 changes: 31 additions & 0 deletions Testing/Acceptance/Modules/Layouting/SectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Net;
using GenHTTP.Modules.IO;
using GenHTTP.Modules.Layouting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.Layouting;

[TestClass]
public class SectionTests
{

[TestMethod]
[MultiEngineTest]
public async Task TestSection(TestEngine engine)
{
var app = Layout.Create();

var section = app.AddSection("section");

section.Index(Content.From(Resource.FromString("Hello World")));

await using var host = await TestHost.RunAsync(app, engine: engine);

using var response = await host.GetResponseAsync("/section/");

await response.AssertStatusAsync(HttpStatusCode.OK);

Assert.AreEqual("Hello World", await response.GetContentAsync());
}

}

0 comments on commit b509a54

Please sign in to comment.