Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/BootstrapBlazor.Server/Data/Foo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class Foo
/// Generate Foo class, random data
/// </summary>
/// <returns>返回一个Foo类的List,Return a List of Foo class</returns>
public static List<Foo> GenerateFoo(IStringLocalizer<Foo> localizer, int count = 80) => Enumerable.Range(1, count).Select(i => new Foo()
public static List<Foo> GenerateFoo(IStringLocalizer<Foo> localizer, int count = 80) => [.. Enumerable.Range(1, count).Select(i => new Foo()
{
Id = i,
Name = localizer["Foo.Name", $"{i:d4}"],
Expand All @@ -119,7 +119,7 @@ public class Foo
Complete = Random.Shared.Next(1, 100) > 50,
Education = Random.Shared.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middle,
ReadonlyColumn = Random.Shared.Next(10, 50)
}).ToList();
})];

/// <summary>
/// 生成 Foo 类 Hobbies 数据
Expand Down
18 changes: 5 additions & 13 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,12 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
set => IsVisibleWhenEdit = value ?? true;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool? Required { get; set; }
bool? IEditorItem.Required { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool? IsRequiredWhenAdd { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool? IsRequiredWhenEdit { get; set; }
bool? ITableColumn.IsRequiredWhenAdd { get; set; }

bool? ITableColumn.IsRequiredWhenEdit { get; set; }

/// <summary>
/// <inheritdoc/>
Expand All @@ -109,7 +101,7 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
bool? IEditorItem.ShowLabelTooltip
{
get => ShowLabelTooltip;
set => ShowLabelTooltip = value.HasValue && value.Value;
set => ShowLabelTooltip = value ?? false;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.3.1-beta26</Version>
<Version>9.3.1-beta27</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 9 additions & 7 deletions test/UnitTest/Attributes/AutoGenerateClassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ public void AutoGenerateColumn_Ok()
HeaderTextWrap = true,
IsMarkupString = true,

Required = true,
RequiredErrorMessage = "test",
IsRequiredWhenAdd = true,
IsRequiredWhenEdit = true
RequiredErrorMessage = "test"
};
Assert.Equal(1, attr.Order);
Assert.True(attr.Ignore);
Expand Down Expand Up @@ -201,6 +198,11 @@ public void AutoGenerateColumn_Ok()
attrInterface.ToolboxTemplate = col => builder => builder.AddContent(0, "test");
Assert.NotNull(attrInterface.ToolboxTemplate);

attrInterface.IsRequiredWhenAdd = true;
Assert.True(attrInterface.IsRequiredWhenAdd);
attrInterface.IsRequiredWhenEdit = true;
Assert.True(attrInterface.IsRequiredWhenEdit);

var attrEditor = (IEditorItem)attr;
attrEditor.Items = null;
Assert.Null(attrEditor.Items);
Expand All @@ -226,13 +228,13 @@ public void AutoGenerateColumn_Ok()
attrEditor.LookupService = new LookupService();
Assert.NotNull(attrEditor.LookupService);

attrEditor.Required = true;
Assert.True(attrEditor.Required);

// 增加 GetDisplay 单元覆盖率
attr.Text = null;
Assert.Equal(string.Empty, attr.GetDisplayName());

Assert.True(attr.Required);
Assert.True(attr.IsRequiredWhenEdit);
Assert.True(attr.IsRequiredWhenAdd);
Assert.Equal("test", attr.RequiredErrorMessage);
}

Expand Down