Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Code311.Tabler.Components/Data/DataComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Code311.Tabler.Components.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Code311.Ui.Core.Loading;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Code311.Tabler.Components.Feedback;
Expand Down
2 changes: 1 addition & 1 deletion src/Code311.Tabler.Components/Forms/FormTagHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
}

[HtmlTargetElement("cd311-select")]
public sealed class Cd311SelectTagHelper(ITablerSemanticClassMapper mapper) : TagHelper
public sealed class Cd311SelectTagHelper : TagHelper
{
public string? Field { get; set; }
public IReadOnlyCollection<Cd311OptionItem>? Options { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Code311.Tabler.Components/Forms/FormViewComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;

namespace Code311.Tabler.Components.Forms;

Expand Down
1 change: 1 addition & 0 deletions src/Code311.Tabler.Components/Layout/LayoutComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Code311.Tabler.Components.Layout;
Expand Down
1 change: 1 addition & 0 deletions src/Code311.Tabler.Components/Media/MediaComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Code311.Tabler.Components.Media;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Code311.Tabler.Components.Navigation;
Expand Down
1 change: 1 addition & 0 deletions src/Code311.Tabler.Dashboard/Kpi/KpiViewComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Code311.Tabler.Dashboard.Models;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;

namespace Code311.Tabler.Dashboard.Kpi;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Code311.Ui.Abstractions.Semantics;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;

namespace Code311.Tabler.Dashboard.Layout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Code311.Tabler.Dashboard.Models;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;

namespace Code311.Tabler.Dashboard.Panels;

Expand Down
3 changes: 3 additions & 0 deletions src/Code311.Tabler.Dashboard/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Code311.Tests.Tabler.Dashboard")]
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public static IServiceCollection AddCode311TablerMvc(this IServiceCollection ser
}
}

internal sealed class ConfigureCode311MvcOptions(
IServiceProvider serviceProvider) : IConfigureOptions<MvcOptions>
internal sealed class ConfigureCode311MvcOptions : IConfigureOptions<MvcOptions>
{
public void Configure(MvcOptions options)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Code311.Tabler.Mvc/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Code311.Tests.Integration.Mvc")]
3 changes: 3 additions & 0 deletions src/Code311.Tabler.Razor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Code311.Tests.Integration.Razor")]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Code311.Ui.Core.Theming;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
Expand Down
4 changes: 2 additions & 2 deletions tests/Code311.Tests.Licensing/LicensingServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task FeatureGate_ShouldDeny_WhenFeatureMissing()
{
var services = new ServiceCollection()
.AddCode311Licensing(options => options.RequireValidLicenseAtStartup = false)
.AddCode311InMemoryLicenseSource(BuildLicense(features: ["dashboard.basic"]))
.AddCode311InMemoryLicenseSource(BuildLicense(features: new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "dashboard.basic" }))
.BuildServiceProvider();

var gate = services.GetRequiredService<ILicenseFeatureGate>();
Expand All @@ -85,7 +85,7 @@ public async Task FeatureGate_ShouldAllow_WhenFeaturePresent()
{
var services = new ServiceCollection()
.AddCode311Licensing(options => options.RequireValidLicenseAtStartup = false)
.AddCode311InMemoryLicenseSource(BuildLicense(features: ["dashboard.advanced"]))
.AddCode311InMemoryLicenseSource(BuildLicense(features: new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "dashboard.advanced" }))
.BuildServiceProvider();

var gate = services.GetRequiredService<ILicenseFeatureGate>();
Expand Down
21 changes: 12 additions & 9 deletions tests/Code311.Tests.Tabler.Components/ComponentRenderingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Text.Encodings.Web;
using Code311.Tabler.Components.Common;
using Code311.Tabler.Components.Data;
using Code311.Tabler.Components.Feedback;
Expand Down Expand Up @@ -26,7 +27,7 @@ public sealed class ComponentRenderingTests
[Fact]
public void Cd311Input_ShouldRenderSemanticClasses()
{
var helper = new Cd311InputTagHelper(new TablerSemanticClassMapper)
var helper = new Cd311InputTagHelper(new TablerSemanticClassMapper())
{
Field = "Email",
Label = "Email",
Expand All @@ -46,7 +47,7 @@ public void Cd311Input_ShouldRenderSemanticClasses()
[Fact]
public void Cd311Tabs_ShouldRenderItems()
{
var helper = new Cd311TabsTagHelper(new TablerSemanticClassMapper)
var helper = new Cd311TabsTagHelper(new TablerSemanticClassMapper())
{
Items =
[
Expand All @@ -66,7 +67,7 @@ public void Cd311Tabs_ShouldRenderItems()
[Fact]
public void Cd311Card_ShouldSetToneClass()
{
var helper = new Cd311CardTagHelper(new TablerSemanticClassMapper) { Tone = UiTone.Warning, Title = "Card" };
var helper = new Cd311CardTagHelper(new TablerSemanticClassMapper()) { Tone = UiTone.Warning, Title = "Card" };
var output = CreateOutput();

helper.Process(CreateContext(), output);
Expand All @@ -77,7 +78,7 @@ public void Cd311Card_ShouldSetToneClass()
[Fact]
public void Cd311Progress_ShouldClampAndRenderBar()
{
var helper = new Cd311ProgressTagHelper(new TablerSemanticClassMapper) { Value = 150, Tone = UiTone.Success };
var helper = new Cd311ProgressTagHelper(new TablerSemanticClassMapper()) { Value = 150, Tone = UiTone.Success };
var output = CreateOutput();

helper.Process(CreateContext(), output);
Expand All @@ -90,7 +91,7 @@ public void Cd311Progress_ShouldClampAndRenderBar()
[Fact]
public void Cd311Badge_ShouldRenderTone()
{
var helper = new Cd311BadgeTagHelper(new TablerSemanticClassMapper) { Tone = UiTone.Danger, Text = "Blocked" };
var helper = new Cd311BadgeTagHelper(new TablerSemanticClassMapper()) { Tone = UiTone.Danger, Text = "Blocked" };
var output = CreateOutput();

helper.Process(CreateContext(), output);
Expand All @@ -102,7 +103,7 @@ public void Cd311Badge_ShouldRenderTone()
[Fact]
public void Cd311Avatar_ShouldFallbackToInitials()
{
var helper = new Cd311AvatarTagHelper(new TablerSemanticClassMapper) { Name = "Code Three" };
var helper = new Cd311AvatarTagHelper(new TablerSemanticClassMapper()) { Name = "Code Three" };
var output = CreateOutput();

helper.Process(CreateContext(), output);
Expand All @@ -126,10 +127,12 @@ public void BusyAndAlertComponents_ShouldConsumeUiCoreServices()
var host = new Cd311PageAlertHostViewComponent(feedback);

Assert.Contains("active", overlayOutput.Attributes["class"].Value?.ToString());
var result = Assert.IsType<Microsoft.AspNetCore.Mvc.ViewComponents.HtmlContentViewComponentResult>(host.Invoke());
var result = host.Invoke();
var htmlResult = Assert.IsType<Microsoft.AspNetCore.Mvc.ViewComponents.HtmlContentViewComponentResult>(result);
using var writer = new StringWriter();
result.Content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
Assert.Contains("Saved", writer.ToString());
htmlResult.EncodedContent.WriteTo(writer, HtmlEncoder.Default);
var html = writer.ToString();
Assert.Contains("Saved", html);
}

private static TagHelperContext CreateContext() =>
Expand Down
21 changes: 13 additions & 8 deletions tests/Code311.Tests.Tabler.Dashboard/DashboardCompositionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Text.Encodings.Web;
using Code311.Tabler.Core.Mapping;
using Code311.Tabler.Dashboard.Composition;
using Code311.Tabler.Dashboard.Kpi;
Expand Down Expand Up @@ -41,10 +42,11 @@ [new DashboardPanelModel("p1", "Revenue", "<div>$100</div>", UiTone.Success)])
public void DashboardShell_ShouldRenderShellClasses()
{
var component = new Cd311DashboardShellViewComponent(new TablerSemanticClassMapper());
var result = Assert.IsType<HtmlContentViewComponentResult>(component.Invoke(new DashboardPageModel("Sales", []), UiLayout.Grid));
var result = component.Invoke(new DashboardPageModel("Sales", []), UiLayout.Grid);
var htmlResult = Assert.IsType<HtmlContentViewComponentResult>(result);

using var writer = new StringWriter();
result.Content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
htmlResult.EncodedContent.WriteTo(writer, HtmlEncoder.Default);
var html = writer.ToString();

Assert.Contains("cd311-dashboard-shell", html);
Expand All @@ -55,10 +57,11 @@ public void DashboardShell_ShouldRenderShellClasses()
public void KpiSummary_ShouldRenderToneMappedItems()
{
var component = new Cd311KpiSummaryViewComponent(new TablerSemanticClassMapper());
var result = Assert.IsType<HtmlContentViewComponentResult>(component.Invoke("KPIs", [new DashboardKpiItem("Users", "100", UiTone.Info, "+5%") ]));
var result = component.Invoke("KPIs", [new DashboardKpiItem("Users", "100", UiTone.Info, "+5%") ]);
var htmlResult = Assert.IsType<HtmlContentViewComponentResult>(result);

using var writer = new StringWriter();
result.Content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
htmlResult.EncodedContent.WriteTo(writer, HtmlEncoder.Default);
var html = writer.ToString();

Assert.Contains("text-info", html);
Expand All @@ -69,10 +72,11 @@ public void KpiSummary_ShouldRenderToneMappedItems()
public void QuickActionsPanel_ShouldRenderButtons()
{
var component = new Cd311QuickActionsPanelViewComponent(new TablerSemanticClassMapper());
var result = Assert.IsType<HtmlContentViewComponentResult>(component.Invoke("Actions", [new DashboardQuickAction(new("Create"), UiTone.Accent)]));
var result = component.Invoke("Actions", [new DashboardQuickAction(new("Create"), UiTone.Accent)]);
var htmlResult = Assert.IsType<HtmlContentViewComponentResult>(result);

using var writer = new StringWriter();
result.Content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
htmlResult.EncodedContent.WriteTo(writer, HtmlEncoder.Default);
var html = writer.ToString();

Assert.Contains("btn-primary", html);
Expand All @@ -83,10 +87,11 @@ public void QuickActionsPanel_ShouldRenderButtons()
public void ActivityPanel_ShouldRenderFeedItems()
{
var component = new Cd311ActivityPanelViewComponent(new TablerSemanticClassMapper());
var result = Assert.IsType<HtmlContentViewComponentResult>(component.Invoke("Activity", [new DashboardActivityItem("Imported orders", DateTimeOffset.UtcNow, UiTone.Warning)]));
var result = component.Invoke("Activity", [new DashboardActivityItem("Imported orders", DateTimeOffset.UtcNow, UiTone.Warning)]);
var htmlResult = Assert.IsType<HtmlContentViewComponentResult>(result);

using var writer = new StringWriter();
result.Content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
htmlResult.EncodedContent.WriteTo(writer, HtmlEncoder.Default);
var html = writer.ToString();

Assert.Contains("Imported orders", html);
Expand Down
Loading