I am writing some unit tests for an extension method I have written on IPrincipal
. To assist, I have created a couple of helper classes (some code for not-implemented members of the interfaces has been omitted for brevity):
public class IPrincipalStub : IPrincipal
{
private IIdentity identityStub = new IIdentityStub();
public IIdentity Identity
{
get { return identityStub; }
set { identityStub = value; }
}
}
public class IIdentityStub : IIdentity
{
public string Name { get; set; } // BZZZT!!!
}
However, the Name
property in the IIdentity
interface is read-only (the IIDentity
interface specifies a getter but not a setter for the Name property).
How can I set the Name property in my stub object for testing purposes if the interface has defined it as a read-only property?