I don't know why i'm having this behavior with my code coverage, maybe someone knows the reasson. As you may know, code coverage is blue when reached, red when not reached, yellow when partially reached a line of code.
I coded a little mapper that receives a IDataReader and turns into object thanks to reflection.
internal IEnumerable<T> Convert<T>(System.Data.IDataReader dataReader) where T : new()
{
var columns = this.GetColumns(dataReader); // get a list of column name... not important.
var result = new List<T>();
while (dataReader.Read())
{
var nuevoObjeto = new T(); // <-- this line is yellow in code coverage.
foreach (var item in columns)
{
var pi = nuevoObjeto.GetType().GetProperty(item);
pi.SetValue(nuevoObjeto, dataReader[columns.IndexOf(item)]);
}
result.Add(nuevoObjeto);
}
return result;
}
As you can see, the yellow line is not a conditional like IF or WHILE... is just a simple "new T" And if you debug this code, debug reaches very well that line, in fact test is green with expected results.
Test performs this steps.
- Fake IDataReader (with nSubstitute)
- Only 1 result on the datareader.
- T is tested with only one TestClass... like USERTEST.
hope someone knows why this happens... thanks!
Aucun commentaire:
Enregistrer un commentaire