lundi 19 septembre 2016

How to unit test DataRow with a lot of columns in C#

What is the best way to unit test DataRows in C#?

I have a class architecture where all data is stored inside DataRow variable. How it works? For example when i double click on one record in the customers list the whole record from Customer table i loaded into _dataRow variable. The problem is that Customer table has over 200 columns.

The question is, do I need to manually create DataRow variable and fill all columns in every test method? Or maybe there is some mocking tool to mock all DataRow columns?

class Customer
{
    private DataRow _dataRow;

    public Customer(DataRow dataRow)
    {
        _dataRow = dataRow;
    }

    private string GetCustomerName()
    {
        return Convert.ToString(_dataRow["Name"]);
    }

    private string GetCustomerAddress()
    {
        return Convert.ToString(_dataRow["Street"]) + " " + Convert.ToString(_dataRow["House_No"]);
    }

    private int GetAge()
    {
        DateTime birthdate = Convert.ToDateTime(_dataRow["Birthdate"]);
        DateTime today = DateTime.Today;
        int age = today.Year - birthdate.Year;
        if (birthdate > today.AddYears(-age))
            age--;
        return age;
    }
}

Aucun commentaire:

Enregistrer un commentaire