Sunday, 15 June 2014

c# - How to Unit Test GetNewValues() which contains EntityFunctions.AddDays function -



c# - How to Unit Test GetNewValues() which contains EntityFunctions.AddDays function -

below sample code working fine in production, cannot unit tested because entityfunctions.

my unit test project using inmemorydatabase instead of real sql database. can solve problem creating view in sql database computed column myvalue , newvalue. find way unit test work without changing method , without creating new sql view

public class ecasereferralcaserepository : repository { public class mytype { public datetime myvalue; public datetime newvalue; } public mytype getnewvalues() { homecoming (mytype)(from o in context.ecasereferralcases select new mytype { // linq entity myvalue = (datetime)system.data.objects.entityfunctions.adddays(o.startdate, 0), newvalue = (datetime)system.data.objects.entityfunctions.adddays(o.startdate, 30) // linq object //myvalue = o.startdate.adddays(0), //newvalue = o.startdate.adddays(30) }); } }

this link shows illustration unit test entityfunctions, used approach solve 1 of unit test difficulty, don't know how solve problem.

rather phone call

system.data.objects.entityfunctions.adddays

directly, inject custom interface, forwards phone call method can mocked testing purposes.

c# unit-testing frameworks entity

No comments:

Post a Comment