Skip to content

Commit e695ac3

Browse files
committed
Prepare InertiaCore for tests
1 parent 8bff816 commit e695ac3

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

InertiaCore/InertiaSharedData.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using InertiaCore.Extensions;
2+
13
namespace InertiaCore;
24

35
internal class InertiaSharedData
@@ -10,7 +12,7 @@ internal class InertiaSharedData
1012

1113
if (Data != null)
1214
foreach (var (key, value) in Data)
13-
result[key] = value;
15+
result[key.ToCamelCase()] = value;
1416

1517
foreach (var (key, value) in with) result[key] = value;
1618

@@ -22,6 +24,6 @@ internal class InertiaSharedData
2224
public void Set(string key, object? value)
2325
{
2426
Data ??= new Dictionary<string, object?>();
25-
Data[key] = value;
27+
Data[key.ToCamelCase()] = value;
2628
}
2729
}

InertiaCore/Response.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ public Response(string component, object props, string rootView, string? version
2424
public async Task ExecuteResultAsync(ActionContext context)
2525
{
2626
SetContext(context);
27+
ProcessResponse();
2728

29+
await GetResult().ExecuteResultAsync(_context!);
30+
}
31+
32+
protected internal void ProcessResponse()
33+
{
2834
var page = new Page
2935
{
3036
Component = _component,
3137
Version = _version,
3238
Url = _context!.RequestedUri()
3339
};
3440

35-
var partial = context.GetPartialData();
36-
if (partial.Any() && context.IsInertiaPartialComponent(_component))
41+
var partial = _context!.GetPartialData();
42+
if (partial.Any() && _context!.IsInertiaPartialComponent(_component))
3743
{
3844
var only = _props.Only(partial);
3945
var partialProps = only.ToDictionary(o => o.ToCamelCase(), o =>
@@ -48,18 +54,16 @@ public async Task ExecuteResultAsync(ActionContext context)
4854
page.Props = props;
4955
}
5056

51-
var shared = context.HttpContext.Features.Get<InertiaSharedData>();
57+
var shared = _context!.HttpContext.Features.Get<InertiaSharedData>();
5258
if (shared != null)
5359
page.Props = shared.GetMerged(page.Props);
5460

5561
page.Props["errors"] = GetErrors();
5662

5763
SetPage(page);
58-
59-
await GetResult().ExecuteResultAsync(_context!);
6064
}
6165

62-
private JsonResult GetJson()
66+
protected internal JsonResult GetJson()
6367
{
6468
_context!.HttpContext.Response.Headers.Add("X-Inertia", "true");
6569
_context!.HttpContext.Response.Headers.Add("Vary", "Accept");
@@ -87,7 +91,7 @@ private ViewResult GetView()
8791
return new ViewResult { ViewName = _rootView, ViewData = viewData };
8892
}
8993

90-
private IActionResult GetResult() => _context!.IsInertiaRequest() ? GetJson() : GetView();
94+
protected internal IActionResult GetResult() => _context!.IsInertiaRequest() ? GetJson() : GetView();
9195

9296
private IDictionary<string, string> GetErrors()
9397
{
@@ -98,7 +102,7 @@ private IDictionary<string, string> GetErrors()
98102
return new Dictionary<string, string>(0);
99103
}
100104

101-
private void SetContext(ActionContext context) => _context = context;
105+
protected internal void SetContext(ActionContext context) => _context = context;
102106

103107
private void SetPage(Page page) => _page = page;
104108

0 commit comments

Comments
 (0)