07-20-2023, 02:35 PM
> Below sample code is working fine in production, but cannot be unit
> tested because the EntityFunctions.
> my unit test project is using
> InMemoryDatabase instead of real SQL database. I can easily solve my
> problem by creating a View in SQL database with computed column
> myValue and newValue. I like to find a way to do the unit test work
> without changing my method and without creating new SQL view
------------------------------------------------------------------------
public class EcaseReferralCaseRepository : Repository
{
public class myType
{
public DateTime myValue;
public DateTime newValue;
}
public myType GetNewValues()
{
return
(myType)(from o in context.EcaseReferralCases
select new myType
{
// LINQ to Entity
myValue = (DateTime)System.Data.Objects.EntityFunctions.AddDays(o.StartDate, 0),
newValue = (DateTime)System.Data.Objects.EntityFunctions.AddDays(o.StartDate, 30)
// LINQ to Object
//myValue = o.StartDate.AddDays(0),
//newValue = o.StartDate.AddDays(30)
});
}
}
----------
[This link shows a good example to unit test EntityFunctions][1], I used that approach to solve one of my unit test difficulty, but don't know how to solve this problem.
[1]:
> tested because the EntityFunctions.
> my unit test project is using
> InMemoryDatabase instead of real SQL database. I can easily solve my
> problem by creating a View in SQL database with computed column
> myValue and newValue. I like to find a way to do the unit test work
> without changing my method and without creating new SQL view
------------------------------------------------------------------------
public class EcaseReferralCaseRepository : Repository
{
public class myType
{
public DateTime myValue;
public DateTime newValue;
}
public myType GetNewValues()
{
return
(myType)(from o in context.EcaseReferralCases
select new myType
{
// LINQ to Entity
myValue = (DateTime)System.Data.Objects.EntityFunctions.AddDays(o.StartDate, 0),
newValue = (DateTime)System.Data.Objects.EntityFunctions.AddDays(o.StartDate, 30)
// LINQ to Object
//myValue = o.StartDate.AddDays(0),
//newValue = o.StartDate.AddDays(30)
});
}
}
----------
[This link shows a good example to unit test EntityFunctions][1], I used that approach to solve one of my unit test difficulty, but don't know how to solve this problem.
[1]:
[To see links please register here]