In order to test a method that uses a stored procedure, a fake method has been created. This method is to return a list of ints.
Something like this …
public virtual ObjectResult<Nullable<int>> available_IDs( ... )
{
List<int?> fakeAvailableIDList = new List<int?>();
fakeAvailableIDList.Add(1);
fakeAvailableIDList.Add(2);
fakeAvailableIDList.Add(3);
ObjectResult<Nullable<int>> result = fakeAvailableIDList.All(m => m > 0);
return result;
}
which fails with
Cannot implicitly convert type 'bool' to 'System.Data.Objects.ObjectResult<int?>'
tried (amoungst other things)
ObjectResult<Nullable<int>> result = fakeAvailableIDList.All(m => m > 0);
which gives
Cannot implicitly convert type 'System.Collections.Generic.List<int?>' to 'System.Data.Objects.ObjectResult<int?>'
how can I get a List<> into ObjectResult ?
The line
returns a boolean because
.AllreturnsTrueorFalsedepending on whether or not all elements in the collection meet the specified condition.So, a variable of type
ObjectResultcan’t be set to a variable of typeBool.The
ObjectResultandObjectResult<T>types have hidden constructors, which means you can’t create instances at will. Also, theObjectResult<T>type is sealed, which means it can’t be extended. So, you might be out of luck if you’re looking for an easy way to create anObjectResultfrom anEnumerable.The easiest thing to do, I think, would be to change the type used by the method you’re trying to test. So, if that method has the signature:
Change it to:
That will allow you to create a fake collection with which the method can be tested, and you’ll still be able to pass the method an
ObjectContext<int?>type becauseObjectContext<int?>extendsIEnumerable<int?>.