Added web module tests

This commit is contained in:
2025-01-19 16:00:33 +01:00
parent 8d63910aae
commit 80aa650a2c
26 changed files with 587 additions and 71 deletions

View File

@@ -10,20 +10,32 @@
</component>
<component name="ChangeListManager">
<list default="true" id="0648788e-7696-4e60-bf12-5d5601f33d8c" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/DisplayPropertyTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Dialogs/HopFrameEditorTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Layout/HopFrameLayoutTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Layout/HopFrameNavigationTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Layout/HopFrameSideMenuTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Pages/HopFrameHomeTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Components/Pages/HopFrameTablePageTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Helpers/EnumerableExtensions.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/HopFrame.Tests.Web.csproj" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Models/MyDbContext.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Web/Models/MyTable.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HopFrame/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/PropertyConfig.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Config/TableConfig.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/Services/Implementations/TableManager.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/HopFrame.Web.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/HopFrame.Web.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Web/ServiceCollectionExtensions.cs" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Web/ServiceCollectionExtensions.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/testing/HopFrame.Testing/Program.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/HopFrameConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/HopFrameConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/PropertyConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/PropertyConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/TableConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/TableConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel2.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel2.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/ContextExplorerTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/ContextExplorerTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/HopFrame.sln" beforeDir="false" afterPath="$PROJECT_DIR$/HopFrame.sln" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/HopFrame.Core/HopFrame.Core.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/src/HopFrame.Core/HopFrame.Core.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/DbContextConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Config/DbContextConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/HopFrameConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Config/HopFrameConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/PropertyConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Config/PropertyConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Config/TableConfiguratorTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Config/TableConfiguratorTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/HopFrame.Core.Tests.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/HopFrame.Tests.Core.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockDbContext.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Models/MockDbContext.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Models/MockModel.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/MockModel2.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Models/MockModel2.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Models/QueryProvider.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Models/QueryProvider.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/ContextExplorerTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/ContextExplorerTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/DefaultAuthHandlerTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/DefaultAuthHandlerTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/DisplayPropertyTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/DisplayPropertyTests.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/HopFrame.Core.Tests/Services/TableManagerTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/tests/HopFrame.Tests.Core/Services/TableManagerTests.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -168,7 +180,8 @@
<workItem from="1737120164342" duration="9351000" />
<workItem from="1737199714142" duration="8344000" />
<workItem from="1737208313207" duration="4612000" />
<workItem from="1737281957060" duration="2760000" />
<workItem from="1737281957060" duration="3232000" />
<workItem from="1737293153907" duration="5484000" />
</task>
<task id="LOCAL-00001" summary="Added basic configuration">
<option name="closed" value="true" />
@@ -306,7 +319,15 @@
<option name="project" value="LOCAL" />
<updated>1737212497960</updated>
</task>
<option name="localTasksCounter" value="18" />
<task id="LOCAL-00018" summary="Added more tests">
<option name="closed" value="true" />
<created>1737285123218</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1737285123218</updated>
</task>
<option name="localTasksCounter" value="19" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -321,52 +342,33 @@
<expand>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Total 61% 571/1454" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Total 61% 571/1454" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 46% 401/743" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Total 61% 571/1454" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 46% 401/743" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 93% 25/367" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Total 61% 571/1454" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 46% 401/743" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 93% 25/367" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 93% 25/367" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Services.Implementations 93% 9/134" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Services.Implementations 93% 9/134" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="TableManager&lt;TModel&gt; 87% 8/63" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
<path>
<item name="rootNode" type="c53c71d1:RiderDotCoverCoverageTreeModel$RootNode" />
<item name="Total 59% 577/1420" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 45% 407/741" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 92% 31/365" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Services.Implementations 93% 9/134" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="TableManager&lt;TModel&gt; 87% 8/63" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="DisplayProperty(object,PropertyConfig,object) 73% 7/26" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Total 61% 571/1454" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Core 46% 401/743" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 93% 25/367" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="HopFrame.Core 93% 25/367" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
<item name="Services.Implementations 96% 5/136" type="8b8fad3a:RiderDotCoverCoverageTreeNode" />
</path>
</expand>
<select />
@@ -393,6 +395,7 @@
<MESSAGE value="Addressed all build warnings" />
<MESSAGE value="Added documentation for the configurators and service extensions methods" />
<MESSAGE value="Created tests for the core module" />
<option name="LAST_COMMIT_MESSAGE" value="Created tests for the core module" />
<MESSAGE value="Added more tests" />
<option name="LAST_COMMIT_MESSAGE" value="Added more tests" />
</component>
</project>

View File

@@ -12,7 +12,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Testing", "testing
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{141928CB-5977-4285-A986-5BD785F2883C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Core.Tests", "tests\HopFrame.Core.Tests\HopFrame.Core.Tests.csproj", "{2E2D29E0-53FA-462D-B4D2-4678CD106E29}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Tests.Core", "tests\HopFrame.Tests.Core\HopFrame.Tests.Core.csproj", "{2E2D29E0-53FA-462D-B4D2-4678CD106E29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HopFrame.Tests.Web", "tests\HopFrame.Tests.Web\HopFrame.Tests.Web.csproj", "{7AB4F4FF-E938-4A40-A7EB-7B2063262896}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -24,6 +26,7 @@ Global
{8E59F398-184A-47C9-AAA2-3E0FFD775ABF} = {7E4AAFB3-9762-4F42-86DF-5A3194FDC243}
{58490069-51DF-454C-8B54-7FB7D4BDFF81} = {9EB7FDBD-49C2-4872-9666-6F7AEBA541B2}
{2E2D29E0-53FA-462D-B4D2-4678CD106E29} = {141928CB-5977-4285-A986-5BD785F2883C}
{7AB4F4FF-E938-4A40-A7EB-7B2063262896} = {141928CB-5977-4285-A986-5BD785F2883C}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BFE21C2-EAAC-4662-8B97-500836651B2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -42,5 +45,9 @@ Global
{2E2D29E0-53FA-462D-B4D2-4678CD106E29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E2D29E0-53FA-462D-B4D2-4678CD106E29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E2D29E0-53FA-462D-B4D2-4678CD106E29}.Release|Any CPU.Build.0 = Release|Any CPU
{7AB4F4FF-E938-4A40-A7EB-7B2063262896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AB4F4FF-E938-4A40-A7EB-7B2063262896}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AB4F4FF-E938-4A40-A7EB-7B2063262896}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AB4F4FF-E938-4A40-A7EB-7B2063262896}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -12,7 +12,7 @@
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>HopFrame.Core.Tests</_Parameter1>
<_Parameter1>HopFrame.Tests.Core</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

View File

@@ -1,8 +1,8 @@
using HopFrame.Core.Config;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
using Moq;
namespace HopFrame.Core.Tests.Config;
namespace HopFrame.Tests.Core.Config;
public class DbContextConfiguratorTests {
[Fact]

View File

@@ -1,7 +1,7 @@
using HopFrame.Core.Config;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
namespace HopFrame.Core.Tests.Config;
namespace HopFrame.Tests.Core.Config;
public class HopFrameConfiguratorTests {
[Fact]

View File

@@ -1,8 +1,8 @@
using System.Linq.Expressions;
using HopFrame.Core.Config;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
namespace HopFrame.Core.Tests.Config;
namespace HopFrame.Tests.Core.Config;
public class PropertyConfiguratorTests {
[Fact]

View File

@@ -1,8 +1,8 @@
using System.Linq.Expressions;
using HopFrame.Core.Config;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
namespace HopFrame.Core.Tests.Config;
namespace HopFrame.Tests.Core.Config;
public class TableConfiguratorTests {
[Fact]

View File

@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
namespace HopFrame.Core.Tests.Models;
namespace HopFrame.Tests.Core.Models;
// A mock DbContext for testing purposes
public class MockDbContext : DbContext {

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace HopFrame.Core.Tests.Models;
namespace HopFrame.Tests.Core.Models;
// A mock model for testing purposes
public class MockModel {

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace HopFrame.Core.Tests.Models;
namespace HopFrame.Tests.Core.Models;
public class MockModel2 {
[Key]

View File

@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query;
namespace HopFrame.Core.Tests.Models;
namespace HopFrame.Tests.Core.Models;
// A mock implementation for async query provider
internal class TestAsyncQueryProvider<TEntity> : IAsyncQueryProvider {

View File

@@ -1,10 +1,10 @@
using HopFrame.Core.Config;
using HopFrame.Core.Services.Implementations;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
using Microsoft.Extensions.Logging;
using Moq;
namespace HopFrame.Core.Tests.Services;
namespace HopFrame.Tests.Core.Services;
public class ContextExplorerTests {
[Fact]

View File

@@ -1,6 +1,6 @@
using HopFrame.Core.Services.Implementations;
namespace HopFrame.Core.Tests.Services;
namespace HopFrame.Tests.Core.Services;
public class DefaultAuthHandlerTests {
[Fact]

View File

@@ -1,11 +1,11 @@
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Core.Services.Implementations;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
using Microsoft.EntityFrameworkCore;
using Moq;
namespace HopFrame.Core.Tests.Services;
namespace HopFrame.Tests.Core.Services;
public class DisplayPropertyTests {
private readonly Mock<IServiceProvider> _providerMock;

View File

@@ -3,11 +3,11 @@
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Core.Services.Implementations;
using HopFrame.Core.Tests.Models;
using HopFrame.Tests.Core.Models;
using Microsoft.EntityFrameworkCore;
using Moq;
namespace HopFrame.Core.Tests.Services;
namespace HopFrame.Tests.Core.Services;
public class TableManagerTests {
private Mock<DbContext> CreateMockDbContext<TModel>(List<TModel> data) where TModel : class {

View File

@@ -0,0 +1,63 @@
using Bunit;
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Tests.Web.Models;
using HopFrame.Web;
using HopFrame.Web.Components.Dialogs;
using HopFrame.Web.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Moq;
namespace HopFrame.Tests.Web.Components.Dialogs;
public class HopFrameEditorTests : TestContext {
[Fact]
public void Renders_Properties_Correctly() {
// Arrange
var contextExplorerMock = new Mock<IContextExplorer>();
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var dialogServiceMock = new Mock<IDialogService>();
var toastServiceMock = new Mock<IToastService>();
var serviceProviderMock = new Mock<IServiceProvider>();
var contextConfig = new DbContextConfig(typeof(MyDbContext));
var tableConfig = new TableConfig(contextConfig, typeof(MyTable), "Table1", 0) {
DisplayName = "Table1",
ViewPolicy = "Policy1"
};
contextConfig.Tables.Add(tableConfig);
var config = new HopFrameConfig() {
Contexts = { contextConfig }
};
contextExplorerMock.Setup(e => e.GetTable("Table1")).Returns(tableConfig);
contextExplorerMock.Setup(e => e.GetTableManager("Table1")).Returns(Mock.Of<ITableManager>());
authHandlerMock.Setup(h => h.IsAuthenticatedAsync(It.IsAny<string>())).ReturnsAsync(true);
Services.AddHopFrame(config);
Services.AddSingleton(contextExplorerMock.Object);
Services.AddSingleton(authHandlerMock.Object);
Services.AddSingleton(dialogServiceMock.Object);
Services.AddSingleton(toastServiceMock.Object);
Services.AddSingleton(serviceProviderMock.Object);
JSInterop.Mode = JSRuntimeMode.Loose;
var dialogData = new EditorDialogData(tableConfig, new MyTable());
var dialog = new FluentDialog() {
Instance = new DialogInstance(typeof(HopFrameEditor), new DialogParameters(), dialogData)
};
// Act
var cut = RenderComponent<HopFrameEditor>(parameters => parameters
.Add(p => p.Content, dialogData)
.Add(p => p.Dialog, dialog));
// Assert
var dialogBody = cut.FindComponent<FluentDialogBody>();
Assert.NotNull(dialogBody);
var textFields = cut.FindComponents<FluentNumberField<double>>();
Assert.Single(textFields);
}
}

View File

@@ -0,0 +1,74 @@
using Bunit;
using Bunit.TestDoubles;
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Web;
using HopFrame.Web.Components.Layout;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Moq;
namespace HopFrame.Tests.Web.Components.Layout;
public class HopFrameLayoutTests : TestContext {
[Fact]
public void Renders_HopFrameLayout_Components() {
// Arrange
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var config = new HopFrameConfig {
DisplayUserInfo = true,
BasePolicy = "SomePolicy",
LoginPageRewrite = "/login"
};
authHandlerMock.Setup(h => h.IsAuthenticatedAsync("SomePolicy"))
.ReturnsAsync(true);
Services.AddSingleton(authHandlerMock.Object);
Services.AddHopFrame(config);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameLayout>();
// Assert
var header = cut.FindComponent<FluentHeader>();
Assert.NotNull(header);
var navigation = cut.FindComponent<HopFrameNavigation>();
Assert.NotNull(navigation);
var sideMenu = cut.FindComponent<HopFrameSideMenu>();
Assert.NotNull(sideMenu);
var footer = cut.FindComponent<FluentFooter>();
Assert.NotNull(footer);
}
[Fact]
public void Redirects_To_Login_When_Not_Authorized() {
// Arrange
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var navMock = new FakeNavigationManager(this);
var config = new HopFrameConfig {
DisplayUserInfo = true,
BasePolicy = "SomePolicy",
LoginPageRewrite = "/login"
};
authHandlerMock.Setup(h => h.IsAuthenticatedAsync("SomePolicy"))
.ReturnsAsync(false);
Services.AddSingleton(navMock);
Services.AddHopFrame(config);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameLayout>();
// Assert
// TODO: check if uri matches
}
}

View File

@@ -0,0 +1,68 @@
using Bunit;
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Web;
using HopFrame.Web.Components.Layout;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Moq;
namespace HopFrame.Tests.Web.Components.Layout;
public class HopFrameNavigationTests : TestContext {
[Fact]
public void Renders_HopFrameNavigation_Components() {
// Arrange
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var config = new HopFrameConfig {
DisplayUserInfo = true
};
authHandlerMock.Setup(h => h.GetCurrentUserDisplayNameAsync())
.ReturnsAsync("John Doe");
Services.AddSingleton(authHandlerMock.Object);
Services.AddHopFrame(config);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameNavigation>();
// Assert
var header = cut.FindComponent<FluentHeader>();
Assert.NotNull(header);
var persona = cut.FindComponent<FluentPersona>();
Assert.NotNull(persona);
Assert.Equal("John Doe", persona.Instance.Name);
Assert.Equal("JD", persona.Instance.Initials);
}
[Fact]
public void Renders_HopFrameNavigation_WithoutPersona() {
// Arrange
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var config = new HopFrameConfig {
DisplayUserInfo = false
};
authHandlerMock.Setup(h => h.GetCurrentUserDisplayNameAsync())
.ReturnsAsync("John Doe");
Services.AddSingleton(authHandlerMock.Object);
Services.AddHopFrame(config);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameNavigation>();
// Assert
var header = cut.FindComponent<FluentHeader>();
Assert.NotNull(header);
Assert.False(cut.HasComponent<FluentPersona>());
authHandlerMock.Verify(h => h.GetCurrentUserDisplayNameAsync(), Times.Never);
}
}

View File

@@ -0,0 +1,49 @@
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using Moq;
using Bunit;
using HopFrame.Tests.Web.Models;
using HopFrame.Web;
using HopFrame.Web.Components.Layout;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
namespace HopFrame.Tests.Web.Components.Layout;
public class HopFrameSideMenuTests : TestContext {
[Fact]
public void Renders_FluentAppBar_Components() {
// Arrange
var contextExplorerMock = new Mock<IContextExplorer>();
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var contextConfig = new DbContextConfig(typeof(MyDbContext));
var tableConfigs = new List<TableConfig> {
new (contextConfig, typeof(MyTable), "Table1", 0),
new (contextConfig, typeof(MyTable2), "Table2", 1)
};
var config = new HopFrameConfig {
Contexts = { contextConfig }
};
contextExplorerMock.Setup(e => e.GetTables()).Returns(tableConfigs);
authHandlerMock.Setup(h => h.IsAuthenticatedAsync(null))
.ReturnsAsync(true);
Services.AddSingleton(contextExplorerMock.Object);
Services.AddSingleton(authHandlerMock.Object);
Services.AddHopFrame(config);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameSideMenu>();
// Assert
var items = cut.FindComponents<FluentAppBarItem>();
Assert.Equal(tableConfigs.Count + 1, items.Count);
Assert.Contains(items, item => item.Instance.Text.Equals("Table1"));
Assert.Contains(items, item => item.Instance.Text.Equals("Table2"));
}
}

View File

@@ -0,0 +1,62 @@
using Bunit;
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Tests.Web.Models;
using HopFrame.Web;
using HopFrame.Web.Components.Pages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Moq;
namespace HopFrame.Tests.Web.Components.Pages;
public class HopFrameHomeTests : TestContext {
[Fact]
public void Renders_Table_Cards_Correctly() {
// Arrange
var contextExplorerMock = new Mock<IContextExplorer>();
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var contextConfig = new DbContextConfig(typeof(MyDbContext));
var tableConfigs = new List<TableConfig> {
new TableConfig(contextConfig, typeof(MyTable), "Table1", 0) {
DisplayName = "Table1",
ViewPolicy = "Policy1",
Description = "Description1"
},
new TableConfig(contextConfig, typeof(MyTable2), "Table2", 1) {
DisplayName = "Table2",
ViewPolicy = "Policy2",
Description = "Description2"
}
};
contextConfig.Tables.AddRange(tableConfigs);
var config = new HopFrameConfig() {
Contexts = { contextConfig }
};
contextExplorerMock.Setup(e => e.GetTables()).Returns(tableConfigs);
authHandlerMock.Setup(h => h.IsAuthenticatedAsync(It.IsAny<string>()))
.ReturnsAsync(true);
Services.AddHopFrame(config);
Services.AddSingleton(contextExplorerMock.Object);
Services.AddSingleton(authHandlerMock.Object);
// Act
var cut = RenderComponent<HopFrameHome>();
// Assert
var cards = cut.FindComponents<FluentCard>();
Assert.Equal(2, cards.Count);
Assert.Contains(cards, card => card.Markup.Contains("Table1"));
Assert.Contains(cards, card => card.Markup.Contains("Description1"));
Assert.Contains(cards, card => card.Markup.Contains("Policy1"));
Assert.Contains(cards, card => card.Markup.Contains("Open"));
Assert.Contains(cards, card => card.Markup.Contains("Table2"));
Assert.Contains(cards, card => card.Markup.Contains("Description2"));
Assert.Contains(cards, card => card.Markup.Contains("Policy2"));
Assert.Contains(cards, card => card.Markup.Contains("Open"));
}
}

View File

@@ -0,0 +1,96 @@
using Bunit;
using HopFrame.Core.Config;
using HopFrame.Core.Services;
using HopFrame.Tests.Web.Helpers;
using HopFrame.Tests.Web.Models;
using HopFrame.Web;
using HopFrame.Web.Components.Pages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components;
using Microsoft.JSInterop;
using Moq;
namespace HopFrame.Tests.Web.Components.Pages;
public class HopFrameTablePageTests : TestContext {
[Fact]
public void Renders_Table_Correctly() {
// Arrange
var contextExplorerMock = new Mock<IContextExplorer>();
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var dialogServiceMock = new Mock<IDialogService>();
var contextConfig = new DbContextConfig(typeof(MyDbContext));
var managerMock = new Mock<ITableManager>();
var tableConfig = new TableConfig(contextConfig, typeof(MyTable), "Table1", 0) {
DisplayName = "Table1",
ViewPolicy = "Policy1"
};
contextConfig.Tables.Add(tableConfig);
var config = new HopFrameConfig() {
Contexts = { contextConfig }
};
contextExplorerMock.Setup(e => e.GetTable("Table1")).Returns(tableConfig);
contextExplorerMock.Setup(e => e.GetTableManager("Table1")).Returns(managerMock.Object);
authHandlerMock.Setup(h => h.IsAuthenticatedAsync(It.IsAny<string>())).ReturnsAsync(true);
managerMock.Setup(m => m.LoadPage(It.IsAny<int>(), It.IsAny<int>())).Returns(Enumerable.Empty<object>().AsAsyncQueryable());
Services.AddHopFrame(config);
Services.AddSingleton(contextExplorerMock.Object);
Services.AddSingleton(authHandlerMock.Object);
Services.AddSingleton(dialogServiceMock.Object);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameTablePage>(parameters => parameters
.Add(p => p.TableDisplayName, "Table1"));
// Assert
var toolbar = cut.Find("fluent-toolbar");
Assert.NotNull(toolbar);
var searchBox = cut.Find("fluent-search");
Assert.NotNull(searchBox);
var dataGrid = cut.FindComponent<FluentDataGrid<object>>();
Assert.NotNull(dataGrid);
}
[Fact]
public void Displays_Properties_Correctly() {
// Arrange
var contextExplorerMock = new Mock<IContextExplorer>();
var authHandlerMock = new Mock<IHopFrameAuthHandler>();
var dialogServiceMock = new Mock<IDialogService>();
var contextConfig = new DbContextConfig(typeof(MyDbContext));
var tableConfig = new TableConfig(contextConfig, typeof(MyTable), "Table1", 0) {
DisplayName = "Table1",
ViewPolicy = "Policy1"
};
var tableManagerMock = new Mock<ITableManager>();
var items = new List<object> { new MyTable(), new MyTable() };
tableManagerMock.Setup(m => m.LoadPage(It.IsAny<int>(), It.IsAny<int>())).Returns(items.AsAsyncQueryable());
contextExplorerMock.Setup(e => e.GetTable("Table1")).Returns(tableConfig);
contextExplorerMock.Setup(e => e.GetTableManager("Table1")).Returns(tableManagerMock.Object);
authHandlerMock.Setup(h => h.IsAuthenticatedAsync(It.IsAny<string>())).ReturnsAsync(true);
Services.AddHopFrame(new HopFrameConfig());
Services.AddSingleton(contextExplorerMock.Object);
Services.AddSingleton(authHandlerMock.Object);
Services.AddSingleton(dialogServiceMock.Object);
JSInterop.Mode = JSRuntimeMode.Loose;
// Act
var cut = RenderComponent<HopFrameTablePage>(parameters => parameters
.Add(p => p.TableDisplayName, "Table1"));
// Assert
var dataGridItems = cut.FindComponents<PropertyColumn<object, string>>();
Assert.Single(dataGridItems);
Assert.Equal(nameof(MyTable.Id), dataGridItems[0].Instance.Title);
}
}

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query.Internal;
namespace HopFrame.Tests.Web.Helpers;
public static class EnumerableExtensions {
public static AsyncQueryable AsAsyncQueryable(this IEnumerable<object> enumerable) {
return new AsyncQueryable(enumerable);
}
public class AsyncQueryable(IEnumerable<object> enumerable) : IQueryable<object>, IAsyncEnumerable<object> {
public IEnumerator<object> GetEnumerator() {
return enumerable.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public Type ElementType { get; } = typeof(object);
public Expression Expression { get; }
public IQueryProvider Provider { get; }
public IAsyncEnumerator<object> GetAsyncEnumerator(CancellationToken cancellationToken = new CancellationToken()) {
return Enumerate().GetAsyncEnumerator(cancellationToken);
}
private async IAsyncEnumerable<object> Enumerate() {
foreach (var o in enumerable) {
yield return o;
}
}
}
}

View File

@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="bunit" Version="1.38.5" />
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
</ItemGroup>
<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\HopFrame.Core\HopFrame.Core.csproj" />
<ProjectReference Include="..\..\src\HopFrame.Web\HopFrame.Web.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,12 @@
using Microsoft.EntityFrameworkCore;
namespace HopFrame.Tests.Web.Models;
public class MyDbContext : DbContext {
public DbSet<MyTable> Table1 { get; set; }
public DbSet<MyTable2> Table2 { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseInMemoryDatabase(nameof(MyDbContext));
}
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace HopFrame.Tests.Web.Models;
public class MyTable {
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
public class MyTable2 {
[Key]
public string Id { get; set; }
}