Unit testing - Operation is not valid due to the current state of the object when using a HasDbFunction()

Viewed 19

I have added a HasDbFunction() into my modelBuilder to allow access to oracles LPad function like so:

modelBuilder.HasDbFunction(() => OracleDbFunctions.LPad(default, default, default));

The OracleDbFunction Class is:

public static class OracleDbFunctions
{
    [DbFunction(IsBuiltIn = true)]
    public static string LPad(this string text, int totalWidth, string padding)
          => throw new InvalidOperationException();
}

It all works perfectly fine and does what I expect. However, now I am trying to unit test all my apis call which use this function. I get the following error: "Operation is not valid due to the current state of the object"

I have ensured all data my DbContextMock uses is populated so not sure why this error occurs. Would I have to somehow initialise my OracleDbFunction.LPad in my DbContextMock?

0 Answers
Related