diff --git a/test/UnitTest/Dynamic/DataTableDynamicContextTest.cs b/test/UnitTest/Dynamic/DataTableDynamicContextTest.cs index d6e6833e82b..fb297f8c96f 100644 --- a/test/UnitTest/Dynamic/DataTableDynamicContextTest.cs +++ b/test/UnitTest/Dynamic/DataTableDynamicContextTest.cs @@ -138,6 +138,28 @@ public async Task OnChanged_Ok() Assert.True(changed); } + [Fact] + public async Task AddAsync_AutoIncrementColumn_Ok() + { + var table = new DataTable(); + table.Columns.Add(new DataColumn("Id", typeof(int)) + { + AutoIncrement = true, + AutoIncrementSeed = 1, + AutoIncrementStep = 1 + }); + table.Columns.Add("Name", typeof(string)); + table.Rows.Add(null, "test-1"); + + var context = new DataTableDynamicContext(table); + + await context.AddAsync([]); + + Assert.Equal(2, table.Rows.Count); + Assert.Equal(2, table.Rows[0].Field("Id")); + Assert.Equal(1, table.Rows[1].Field("Id")); + } + [Fact] public async Task DeleteAsync_Ok() { diff --git a/test/UnitTest/Extensions/DataRowExtensionsTest.cs b/test/UnitTest/Extensions/DataRowExtensionsTest.cs new file mode 100644 index 00000000000..6e748c14089 --- /dev/null +++ b/test/UnitTest/Extensions/DataRowExtensionsTest.cs @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +using System.Data; +using System.Reflection; + +namespace UnitTest.Extensions; + +public class DataRowExtensionsTest +{ + [Fact] + public void IsDeletedOrDetached_Ok() + { + var type = Type.GetType("BootstrapBlazor.Components.DataRowExtensions, BootstrapBlazor"); + Assert.NotNull(type); + + var method = type.GetMethod("IsDeletedOrDetached", BindingFlags.Static | BindingFlags.Public); + Assert.NotNull(method); + + var table = new DataTable(); + table.Columns.Add("Id", typeof(int)); + + var row = table.Rows.Add(1); + Assert.False(IsDeletedOrDetachedInvoke(row)); + table.AcceptChanges(); + + row.Delete(); + Assert.True(IsDeletedOrDetachedInvoke(row)); + + var detachedRow = table.NewRow(); + Assert.True(IsDeletedOrDetachedInvoke(detachedRow)); + + table.Rows.Add(detachedRow); + Assert.False(IsDeletedOrDetachedInvoke(detachedRow)); + + bool IsDeletedOrDetachedInvoke(DataRow row) + { + return (bool)method.Invoke(null, new object[] { row })!; + } + } +}