c# unit test datetime against string -
i doing unit test datetime , fails because test name:
getdatetime2 result message: assert.areequal failed. expected:<28/05/2017 20:00:00 (system.string)>. actual:<28/05/2017 20:00:00 (system.datetime)>.
is there way of comparing string against datetime of have change properties of string date , string time?
public void getdatetime() { footballevent football = new footballevent(); football.time = "20:00:00"; football.date = "28/05/2017"; var footballtime = football.getdatetime(); var expected = "28/05/2017 20:00:00"; assert.areequal(expected, footballtime); }
you call tostring() whatever format want time in comparison.
var expected = "28/05/2017 20:00:00"; //use hh 00-23, use h 0-23, use hh 01-12 , use h 1-12 assert.areequal(expected, footballtime.tostring("dd/mm/yyyy hh:mm:ss")); however seems should comparing both in proper format (datetime).
ask why initializing times via string (football.time = "20:00:00";), why not use proper data type dates , times (datetime)
Comments
Post a Comment