After some experimentation, I found a working solution, although this is not the most elegant.
This is your regular code:
public interface ISecuredItem<TChildType> where TChildType : ISecuredItem<TChildType> { SecurityDescriptor Descriptor { get; } IEnumerable<TChildType> Children { get; } }
In the test project, you create the StubImplemtation interface
public interface StubImplemtation : ISecuredItem<StubImplemtation> { }
Then in unit test you can do the following:
var securedItemStub = new StubISecuredItem<StubImplemtation> { ChildrenGet = () => new List<StubImplemtation>(), DescriptorGet = () => new SecurityDescriptor() }; var children = securedItemStub.ChildrenGet(); var descriptor = securedItemStub.DescriptorGet();
You can skip all StubImplementation and use RegistryKey if this is not a problem.
Wouter de kort
source share