Protected Properties¶
Virtual and abstract protected properties can be configured on the imposter.
Getter/Setter with wrapper¶
Example
[assembly: GenerateImposter(typeof(MyService))]
public class MyService
{
protected virtual int ProtectedAge { get; set; } = 7;
public virtual int ReadProtected() => ProtectedAge;
public virtual void WriteProtected(int value) => ProtectedAge = value;
}
var imposter = new MyServiceImposter();
// Arrange getter
imposter.ProtectedAge.Getter().Returns(33);
// Forward the public wrappers to the real implementation so they use the protected property
imposter.ReadProtected().UseBaseImplementation();
imposter.WriteProtected(Arg<int>.Any()).UseBaseImplementation();
var service = imposter.Instance();
service.WriteProtected(10);
service.ReadProtected(); // 33
imposter.ProtectedAge.Setter(Arg<int>.Is(10)).Called(Count.Once());