Code coverage in VS2012 not showing dynamically typed object used for Dapper as covered

c# dapper integration-testing visual-studio-2012

Question

We're using VS2012 Ultimate (thanks BizSpark!) and we've started to get into integration testing to ensure our Dapper queries are working with the DB in the loop. I'm trying to ensure 100% code coverage for all the database related classes.

In one of our classs, code coverage report from tests for our AddDelay() function is showing that the lines declaring and initialising the data anonymous object aren't covered, however it must be for the Execute to work. There's a mock object being passed in and everything seems to be working but I can't figure out why the code coverage isn't 100% for that method.

Any suggestions as to why the report is showing it's not covered given it's a super simple function, and the data object is passed to the execute function as a parameter?

    public bool AddDelay(DelayInformationModel delay)
    {
        const string sql = @"INSERT INTO EquipmentDelay(EquipmentID, DelayID, StartTime, EndTime, Actual, Comment) VALUES (@EquipmentID, @DelayID, @StartTime, @EndTime, @Actual, @Comment)";

        using (IDbConnection con = DataFactory.CreateOpenConnection())
        {
            var data = new 
            { 
                    EquipmentID = delay.EquipmentID, 
                    DelayID = delay.DelayCode, 
                    StartTime = delay.StartTime, 
                    EndTime = delay.EndTime, 
                    Actual = delay.Actual, 
                    Comment = (delay.Comment ?? "")
            };

            con.Execute(sql, data);
            return true;
        }

    }

Accepted Answer

I think problem with
Comment = (delay.Comment ?? "")

delay.Comment is not null so this check will never execute. Use temp variable and get value in it

something like this

var a= delay.Comment;
var data = new 
            { 
                    EquipmentID = delay.EquipmentID, 
                    DelayID = delay.DelayCode, 
                    StartTime = delay.StartTime, 
                    EndTime = delay.EndTime, 
                    Actual = delay.Actual, 
                    Comment = a ?? ""
            };


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why