From 34fd0c268a431824460b7f5fb1985d66ab4108f8 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 14:48:35 +0800 Subject: [PATCH 1/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87=E7=BB=9F=E8=AE=A1=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/QueryHelper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Utils/QueryHelper.cs b/src/BootstrapBlazor/Utils/QueryHelper.cs index b5ee94cca..f38e18d5d 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 { /// -- Gitee From 4705188ea22e7659c7c4b154836d6f4bd940c40e Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 14:48:50 +0800 Subject: [PATCH 2/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Cache=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Core/BootstrapBlazorTestBase.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Core/BootstrapBlazorTestBase.cs b/test/UnitTest/Core/BootstrapBlazorTestBase.cs index 85c7ffb74..1e567b0d9 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) -- Gitee From e41f10721b7e10971b6f68b3d6f15fee1612409e Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 14:49:07 +0800 Subject: [PATCH 3/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20CacheManager?= =?UTF-8?q?=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/CacheManagerTest.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/UnitTest/Services/CacheManagerTest.cs diff --git a/test/UnitTest/Services/CacheManagerTest.cs b/test/UnitTest/Services/CacheManagerTest.cs new file mode 100644 index 000000000..f2f18b194 --- /dev/null +++ b/test/UnitTest/Services/CacheManagerTest.cs @@ -0,0 +1,23 @@ +// 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(); + + var expected = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + Assert.Equal(expected, Cache.GetStartTime().ToString("yyyy-MM-dd HH:mm:ss")); + + var v = Cache.GetOrCreate("BootstrapBlazor_StartTime", entry => + { + return DateTimeOffset.Now.AddDays(-1); + }); + Assert.Equal(expected, v.ToString("yyyy-MM-dd HH:mm:ss")); + } +} -- Gitee From 4130022ad6311a03b33c281c5e8c10a6157eef73 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 14:49:23 +0800 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20GetOrCreate=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/CacheManagerTest.cs | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/UnitTest/Services/CacheManagerTest.cs b/test/UnitTest/Services/CacheManagerTest.cs index f2f18b194..226696a98 100644 --- a/test/UnitTest/Services/CacheManagerTest.cs +++ b/test/UnitTest/Services/CacheManagerTest.cs @@ -20,4 +20,40 @@ public class CacheManagerTest : BootstrapBlazorTestBase }); Assert.Equal(expected, v.ToString("yyyy-MM-dd HH:mm:ss")); } + + [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; + }); + } } -- Gitee From 4981e02d28943941ad04d2cefa69b80cf27363bd Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 15:45:37 +0800 Subject: [PATCH 5/9] =?UTF-8?q?refactor:=20Textarea=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E6=97=B6=E6=94=AF=E6=8C=81=20rows=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/Utility.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs index 3ae7dca43..56dd04b2f 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 -- Gitee From 30585667e0e1ed60144307d8ff7632b4fcd75f5e Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 15:45:48 +0800 Subject: [PATCH 6/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Textarea=20?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/EditorFormTest.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/UnitTest/Components/EditorFormTest.cs b/test/UnitTest/Components/EditorFormTest.cs index 6149569c8..32ec5f0b2 100644 --- a/test/UnitTest/Components/EditorFormTest.cs +++ b/test/UnitTest/Components/EditorFormTest.cs @@ -104,6 +104,29 @@ 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.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), 0); + builder.CloseComponent(); + }; + } + [Fact] public void IsSearch_Ok() { -- Gitee From e299271b38e449ab8b563ce3e341cd08c07be5cd Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 16:15:25 +0800 Subject: [PATCH 7/9] =?UTF-8?q?test:=20=E6=8F=90=E9=AB=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/EditorFormTest.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/UnitTest/Components/EditorFormTest.cs b/test/UnitTest/Components/EditorFormTest.cs index 32ec5f0b2..7895f466a 100644 --- a/test/UnitTest/Components/EditorFormTest.cs +++ b/test/UnitTest/Components/EditorFormTest.cs @@ -118,11 +118,18 @@ public class EditorFormTest : BootstrapBlazorTestBase 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), 0); + builder.AddAttribute(4, nameof(EditorItem.Rows), 3); builder.CloseComponent(); }; } -- Gitee From 2fb31afb223561a8d3a3c254db2bcae126b23e46 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 16:15:34 +0800 Subject: [PATCH 8/9] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/CacheManagerTest.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/UnitTest/Services/CacheManagerTest.cs b/test/UnitTest/Services/CacheManagerTest.cs index 226696a98..769336b0e 100644 --- a/test/UnitTest/Services/CacheManagerTest.cs +++ b/test/UnitTest/Services/CacheManagerTest.cs @@ -11,14 +11,7 @@ public class CacheManagerTest : BootstrapBlazorTestBase { Cache.SetStartTime(); - var expected = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - Assert.Equal(expected, Cache.GetStartTime().ToString("yyyy-MM-dd HH:mm:ss")); - - var v = Cache.GetOrCreate("BootstrapBlazor_StartTime", entry => - { - return DateTimeOffset.Now.AddDays(-1); - }); - Assert.Equal(expected, v.ToString("yyyy-MM-dd HH:mm:ss")); + Assert.True(DateTime.Now > Cache.GetStartTime()); } [Fact] -- Gitee From f2bd9ff0ddbcb07bcbdb8040f2bf1a3235ed5297 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 6 Jun 2022 16:15:58 +0800 Subject: [PATCH 9/9] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Display=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Utils/UtilityTest.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs index a871e7853..eba49f1ea 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!; + } } -- Gitee