diff --git a/src/BootstrapBlazor/Utils/QueryHelper.cs b/src/BootstrapBlazor/Utils/QueryHelper.cs
index b5ee94cca70ce3e6e49fa1a027ac0af9e7d44ca5..f38e18d5d88218d22c2fd59af890f91623bbbcf2 100644
--- a/src/BootstrapBlazor/Utils/QueryHelper.cs
+++ b/src/BootstrapBlazor/Utils/QueryHelper.cs
@@ -11,6 +11,7 @@ namespace BootstrapBlazor.Components;
///
/// Provides methods for parsing and manipulating query strings.
///
+[ExcludeFromCodeCoverage]
public static class QueryHelper
{
///
diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs
index 3ae7dca433f7fab0e660f938476cbbcc3a858a41..56dd04b2ff595ac48a07a70e190a7f98c8acc178 100644
--- a/src/BootstrapBlazor/Utils/Utility.cs
+++ b/src/BootstrapBlazor/Utils/Utility.cs
@@ -283,6 +283,10 @@ public static class Utility
builder.AddAttribute(2, nameof(Textarea.Value), fieldValue);
builder.AddAttribute(3, nameof(Textarea.ShowLabelTooltip), item.ShowLabelTooltip);
builder.AddAttribute(4, "readonly", true);
+ if (item.Rows > 0)
+ {
+ builder.AddAttribute(5, "rows", item.Rows);
+ }
builder.CloseComponent();
}
else
diff --git a/test/UnitTest/Components/EditorFormTest.cs b/test/UnitTest/Components/EditorFormTest.cs
index 6149569c8399c175b371b851882213c212159854..7895f466a25b19cb50aaea412bb1b7a563fab373 100644
--- a/test/UnitTest/Components/EditorFormTest.cs
+++ b/test/UnitTest/Components/EditorFormTest.cs
@@ -104,6 +104,36 @@ public class EditorFormTest : BootstrapBlazorTestBase
});
}
+ [Fact]
+ public void Textarea_Ok()
+ {
+ var foo = new Foo();
+ var cut = Context.RenderComponent>(pb =>
+ {
+ pb.Add(a => a.IsDisplay, true);
+ pb.Add(a => a.Model, foo);
+ pb.Add(a => a.AutoGenerateAllItem, false);
+ pb.Add(a => a.FieldItems, CreateTextAreaItem());
+ });
+
+ RenderFragment CreateTextAreaItem() => f => builder =>
+ {
+ builder.OpenComponent>(0);
+ builder.AddAttribute(1, nameof(EditorItem.Field), f.Name);
+ builder.AddAttribute(2, nameof(EditorItem.FieldExpression), Utility.GenerateValueExpression(foo, nameof(Foo.Name), typeof(string)));
+ builder.AddAttribute(3, nameof(EditorItem.ComponentType), typeof(Textarea));
+ builder.AddAttribute(4, nameof(EditorItem.Rows), 0);
+ builder.CloseComponent();
+
+ builder.OpenComponent>(0);
+ builder.AddAttribute(1, nameof(EditorItem.Field), f.Address);
+ builder.AddAttribute(2, nameof(EditorItem.FieldExpression), Utility.GenerateValueExpression(foo, nameof(Foo.Address), typeof(string)));
+ builder.AddAttribute(3, nameof(EditorItem.ComponentType), typeof(Textarea));
+ builder.AddAttribute(4, nameof(EditorItem.Rows), 3);
+ builder.CloseComponent();
+ };
+ }
+
[Fact]
public void IsSearch_Ok()
{
diff --git a/test/UnitTest/Core/BootstrapBlazorTestBase.cs b/test/UnitTest/Core/BootstrapBlazorTestBase.cs
index 85c7ffb74a38252ab9c1d6a02b03492a06920bfd..1e567b0d972d1bb73b6a162324117a27743eec04 100644
--- a/test/UnitTest/Core/BootstrapBlazorTestBase.cs
+++ b/test/UnitTest/Core/BootstrapBlazorTestBase.cs
@@ -12,9 +12,12 @@ public class BootstrapBlazorTestBase
{
protected TestContext Context { get; }
+ protected ICacheManager Cache { get; }
+
public BootstrapBlazorTestBase()
{
Context = BootstrapBlazorTestHost.Instance;
+ Cache = BootstrapBlazorTestHost.Cache;
}
}
@@ -29,6 +32,9 @@ public class BootstrapBlazorTestHost : IDisposable
[NotNull]
internal static TestContext? Instance { get; private set; }
+ [NotNull]
+ internal static ICacheManager? Cache { get; private set; }
+
public BootstrapBlazorTestHost()
{
Instance = new TestContext();
@@ -41,7 +47,7 @@ public class BootstrapBlazorTestHost : IDisposable
ConfigureConfigration(Instance.Services);
// 渲染 BootstrapBlazorRoot 组件 激活 ICacheManager 接口
- Instance.Services.GetRequiredService();
+ Cache = Instance.Services.GetRequiredService();
}
protected virtual void ConfigureServices(IServiceCollection services)
diff --git a/test/UnitTest/Services/CacheManagerTest.cs b/test/UnitTest/Services/CacheManagerTest.cs
new file mode 100644
index 0000000000000000000000000000000000000000..769336b0e8051eadcd352405b5fd512c89908ebc
--- /dev/null
+++ b/test/UnitTest/Services/CacheManagerTest.cs
@@ -0,0 +1,52 @@
+// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+// Website: https://www.blazor.zone or https://argozhang.github.io/
+
+namespace UnitTest.Services;
+
+public class CacheManagerTest : BootstrapBlazorTestBase
+{
+ [Fact]
+ public void GetStartTime_Ok()
+ {
+ Cache.SetStartTime();
+
+ Assert.True(DateTime.Now > Cache.GetStartTime());
+ }
+
+ [Fact]
+ public async Task GetOrCreateAsync_Ok()
+ {
+ var key = new object();
+ var val = 0;
+ var actual = await GetOrCreateAsync(key);
+ Assert.Equal(1, actual);
+
+ actual = await GetOrCreateAsync(key);
+ Assert.Equal(1, actual);
+
+ Task GetOrCreateAsync(object key) => Cache.GetOrCreateAsync(key, entry =>
+ {
+ val++;
+ return Task.FromResult(val);
+ });
+ }
+
+ [Fact]
+ public void GetOrCreate_Ok()
+ {
+ var key = new object();
+ var val = 0;
+ var actual = GetOrCreate(key);
+ Assert.Equal(1, actual);
+
+ actual = GetOrCreate(key);
+ Assert.Equal(1, actual);
+
+ int GetOrCreate(object key) => Cache.GetOrCreate(key, entry =>
+ {
+ val++;
+ return val;
+ });
+ }
+}
diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs
index a871e785352d882db760af61629e96d48f31aafc..eba49f1eab2a3a80617e3189a5abf0af4650b45d 100644
--- a/test/UnitTest/Utils/UtilityTest.cs
+++ b/test/UnitTest/Utils/UtilityTest.cs
@@ -138,10 +138,28 @@ public class UtilityTest : BootstrapBlazorTestBase
Assert.Equal("False", items.ElementAt(2).Text);
}
+ [Fact]
+ public void GenerateColumns_Ok()
+ {
+ var cols = Utility.GenerateColumns(col => col.GetFieldName() == "Name");
+ Assert.Single(cols);
+ }
+
+ [Fact]
+ public void CreateDisplayByFieldType_Ok()
+ {
+ var editor = new MockNullDisplayNameColumn("Name", typeof(string));
+ var fragment = new RenderFragment(builder => builder.CreateDisplayByFieldType(editor, new Foo() { Name = "Test-Display" }));
+ var cut = Context.Render(builder => builder.AddContent(0, fragment));
+ }
+
private class Dummy
{
public string? Name { get; set; }
+
public bool? Complete { get; set; }
+
+ public string Field = "";
}
private class MockClone : ICloneable
@@ -206,4 +224,14 @@ public class UtilityTest : BootstrapBlazorTestBase
Assert.NotNull(GetMenuItems);
Assert.Equal(2, GetMenuItems.First().Items.Count());
}
+
+ private class MockNullDisplayNameColumn : MockTableColumn, IEditorItem
+ {
+ public MockNullDisplayNameColumn(string fieldName, Type propertyType) : base(fieldName, propertyType)
+ {
+
+ }
+
+ string IEditorItem.GetDisplayName() => null!;
+ }
}