File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -138,6 +138,28 @@ public async Task OnChanged_Ok()
138138 Assert . True ( changed ) ;
139139 }
140140
141+ [ Fact ]
142+ public async Task AddAsync_AutoIncrementColumn_Ok ( )
143+ {
144+ var table = new DataTable ( ) ;
145+ table . Columns . Add ( new DataColumn ( "Id" , typeof ( int ) )
146+ {
147+ AutoIncrement = true ,
148+ AutoIncrementSeed = 1 ,
149+ AutoIncrementStep = 1
150+ } ) ;
151+ table . Columns . Add ( "Name" , typeof ( string ) ) ;
152+ table . Rows . Add ( null , "test-1" ) ;
153+
154+ var context = new DataTableDynamicContext ( table ) ;
155+
156+ await context . AddAsync ( [ ] ) ;
157+
158+ Assert . Equal ( 2 , table . Rows . Count ) ;
159+ Assert . Equal ( 2 , table . Rows [ 0 ] . Field < int > ( "Id" ) ) ;
160+ Assert . Equal ( 1 , table . Rows [ 1 ] . Field < int > ( "Id" ) ) ;
161+ }
162+
141163 [ Fact ]
142164 public async Task DeleteAsync_Ok ( )
143165 {
Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the Apache 2.0 License
3+ // See the LICENSE file in the project root for more information.
4+ // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
5+
6+ using System . Data ;
7+ using System . Reflection ;
8+
9+ namespace UnitTest . Extensions ;
10+
11+ public class DataRowExtensionsTest
12+ {
13+ [ Fact ]
14+ public void IsDeletedOrDetached_Ok ( )
15+ {
16+ var type = Type . GetType ( "BootstrapBlazor.Components.DataRowExtensions, BootstrapBlazor" ) ;
17+ Assert . NotNull ( type ) ;
18+
19+ var method = type . GetMethod ( "IsDeletedOrDetached" , BindingFlags . Static | BindingFlags . Public ) ;
20+ Assert . NotNull ( method ) ;
21+
22+ var table = new DataTable ( ) ;
23+ table . Columns . Add ( "Id" , typeof ( int ) ) ;
24+
25+ var row = table . Rows . Add ( 1 ) ;
26+ Assert . False ( IsDeletedOrDetachedInvoke ( row ) ) ;
27+ table . AcceptChanges ( ) ;
28+
29+ row . Delete ( ) ;
30+ Assert . True ( IsDeletedOrDetachedInvoke ( row ) ) ;
31+
32+ var detachedRow = table . NewRow ( ) ;
33+ Assert . True ( IsDeletedOrDetachedInvoke ( detachedRow ) ) ;
34+
35+ table . Rows . Add ( detachedRow ) ;
36+ Assert . False ( IsDeletedOrDetachedInvoke ( detachedRow ) ) ;
37+
38+ bool IsDeletedOrDetachedInvoke ( DataRow row )
39+ {
40+ return ( bool ) method . Invoke ( null , new object [ ] { row } ) ! ;
41+ }
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments