I wanted to map a data table to a Model. And I used AutoMapper to do the job. I wrote I unit test using NUnit. This is how I did it
The model
public class DataTableModelTest
{
public int Dosage { get; set; }
public string Drug { get; set; }
}
Mapper Method
class MapperClass{
public IList<TResultType> MapToModel<TResultType>(DataTable datatable)
{
AutoMapper.Mapper.Reset();
AutoMapper.Mapper.CreateMap<IDataReader, IList<TResultType>>();
var re = AutoMapper.Mapper.Map<IDataReader, IList<TResultType>>(datatable.CreateDataReader());
return re;
}
}
The unit test for the Mapper
[Test]
public void TestTheJob() // don't mind the method name
{
const int expectedListCount = 3;
var dataTables = GetDataTable();
var mapperClass = new MapperClass();
var result = mapperClass.MapToModel<DataTable>(dataTables);
Assert.AreEqual(expectedListCount, result.Count);
}
Data table getter.. this is included with the unit test
public DataTable GetDataTable()
{
var dataTable = new DataTable();
dataTable.Columns.Add("Drug", typeof(string));
dataTable.Columns.Add("Dosage", typeof(int));
dataTable.Rows.Add("Indocin", 25);
dataTable.Rows.Add("Enebrel", 50);
dataTable.Rows.Add("Hydralazine", 10);
return dataTable;
}
THE PROBLEM
What am I missing?
FYI: I'm using the latest stable version of AutoMapper 6.1.1 and NUnit version 3.8.1