I have written an Azure durable function in F# and am trying to write unit tests, following the guidelines at https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-unit-testing. I have attempted to use Foq to create a mock instance of the abstract class DurableOrchestrationContextBase
, but that fails with the following error:
System.TypeLoadException : Method 'set_InstanceId' on type 'Mock.DurableOrchestrationContextBase1953fcc2-be15-41fc-850c-5a5813aace89' from assembly 'Foq.Dynamic, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.
The error relates to this property:
public virtual string InstanceId { get; internal set; }
Further investigation shows that Foq is able to mock non-virtual, non-abstract properties with internal setters on abstract C# classes, but can't cope with such properties if they are virtual.
Is there any way to mock such a class in an F# test? Rolling my own implementation would be awkward in this case, as DurableOrchestrationContextBase
is a large class with many members that would need implementing.