简体   繁体   中英

How to Assert DataTable in NUnit?

I've written a Unit Test based on NUnit framework and I'd like to know how should I Assert DataTable that returned from my methods.

Currently, I've done that like below:

[Test]
public void GetTableColumns_WhenCalled_ShouldReturnTableColumnList()
{
    // Act
    DataTable dataTable = _sut.GetTableColumns(Statics.SystemUsersTableName);

    // Assert
    Assert.IsNotNull(dataTable, "DataTable is empty");

}

Is it best practice to Assert DataTable data's with Assert.IsNotNull method?

[Test]
public void GetTableColumns_WhenCalled_ShouldReturnTableColumnList()
{
    // Act
    var dt= _sut.GetTableColumns(Statics.SystemUsersTableName);

    // Assert
    Assert.That(!dt.HasRow());

}

public static bool HasRow(this DataTable dt)
{
 return dt != null && dt.Rows.Count > 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM