I'm having an issue where MS Fakes is not adding a couple delegate properties to the fakes assembly even though they are showing up in the metadata.
I have a class A
that inherits from an abstract generic class B<T>
and implements an interface IA
. All except T
are defined in the same namespace and all are in the same assembly.
B
has a method (BMethod
) and IA
defines a method (IAMethod
) that is implemented in A
.
In my test project I have added a fakes assembly for the one containing these classes/interfaces. I have specified that the fakes assembly should only add a stub for class A
as StubA
, which by default also stubs the interface IA
as StubIA
.
When creating an instance of StubA
I can assign function definitions to all of the delegates created from class B
, but I cannot reference the delegate property names for the functions defined in A
and required by contract from IA
. (ex. I can reference and assign StubA.BMethodArgType
, but not StubA.IAMethodArgType
)
When I navigate to the definition of StubA
in VS2015 I can see that the properties VS is telling me are missing are actually there in the metadata.
...
public class StubA : A, IStub<A>, IStub, IStubObservable, IPartialStub
{
...
//
// Summary:
// Sets the stub of B`1.BMethod(ArgType arg)
public FakesDelegates.Func<ArgType, ReturnType> BMethodArgType;
//
// Summary:
// Sets the stub of A.IAMethod(ArgType arg)
public FakesDelegates.Func<ArgType, ReturnType> IAMethodArgType;
...
}
...
But when I open the FakesAssemblies/ProjectName.Fakes.xml I do not see a member for IAMethodArgType
defined for StubA
, but I do see a member for IAMethodArgType
defined in StubIA
, the stubbed interface. Also, if I add the Interfaces="false"
attribute to the Add
tag in ProjectName.fakes the ProjectName.Fakes.xml file would no longer contain a member for IAMethodArgType
.
Nonetheless I am given error CS0117 and cannot build my test project. I have already tried clearing my FakesAssembly folder and rebuilding. I have tried removing all fakes assembly references and adding them back in. I have tried making the IAMethod
implementations virtual
. Nothing seems to help.
Can anyone tell me what might be going on or where I can check to see why this might be happening?
Ok so I'm posting this here in case anyone else is having this headache, but it seems like the issue was that the implementations in A
for the IA
methods do need to be virtual
for a stub to use them. What I was seeing when I initially made them virtual
was a lag between the metadata and the actual build so it appeared as though they still weren't in the metadata even though they had actually been picked up by the build process and no longer produced error CS0117