You cannot tell SqlFunctions.StringConvert to return a mock object as it is a static method. But you can make an interface for it and create a facade class.
Create an interface like so and be sure to include the attribute
public interface ISqlFunctions
{
[System.Data.Entity.Core.Objects.DataClasses.EdmFunction("SqlServer", "STR")]
string StringConvert(Decimal? number);
}
Then write your facade class. This should be the C# way of doing whatever you want Linq to Entity to do.
public class SqlFunctionsFacade : ISqlFunctions
{
public string StringConvert(decimal? number)
{
return number?.ToString();
}
}
In your implementation, use your interface in your linq query
public SomethingOrOther(ISqlFunctions sqlFunctions)
{
var convertError = models
.Where(x => sqlFunctions.StringConvert((decimal?)(x.convert ?? 0)) == "0")
.Any();
}
Entity Framework will use the attribute on the interface in the same way it was used on SqlFunctions.StringConvert(decimal?).
In your unit test, you can supply your system under test with your facade class or a mock of the interface.