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
22 changes: 22 additions & 0 deletions test/UnitTest/Dynamic/DataTableDynamicContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>("Id"));
Assert.Equal(1, table.Rows[1].Field<int>("Id"));
}

[Fact]
public async Task DeleteAsync_Ok()
{
Expand Down
43 changes: 43 additions & 0 deletions test/UnitTest/Extensions/DataRowExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -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 })!;
}
}
}
Loading