I have one method like below -
public string SomeMethod() {
var resultfromdb = from u in dbContext.TableOne.FromSql("Some select query here")
join rm in dbContext.TableTwo on u.Id equals rm.FId
select new SomeObject() {
/* returning some prperty */
};
//some business code here
return someresult;
}
Now, when I write Unit test for this method using Xunit i am facing below error on FromSql method
Error:
Could not parse expression 'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[TableOne]).FromSql(value(Microsoft.EntityFrameworkCore.RawSqlString), __p_0)': This overload of the method 'Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.FromSql' is currently not supported.
Test Method
[Fact]
public void Test_Method()
{
using (var context = new dbContext())
{
//Arrange
PrefillData(context);//In this method i wll add some dummy data to dbcontext
//some mocking for other code
//Act
var result = SomeMethod();
//Assert
Assert.Equal(expectedString, result);
}
It seems you are using In-Memory Database. Since it is not a real database, you can't use FromSQL method.
Change the FromSql
to FromSqlRaw
dbContext.TableOne.FromSqlRaw("Some select query here")