I am trying to use unit test some Active Directory code, almost the same as in this question:
Create an instance of DirectoryEntry for use in the test.
The accepted answer suggests implementing a wrapper / adapter for the class DirectoryEntrythat I have:
public interface IDirectoryEntry : IDisposable
{
PropertyCollection Properties { get; }
}
public class DirectoryEntryWrapper : DirectoryEntry, IDirectoryEntry
{
}
The problem is that the Properties property in my layout is IDirectoryEntrynot initialized. Trying to set the layout like this:
this._directoryEntryMock = new Mock<IDirectoryEntry>();
this._directoryEntryMock.Setup(m => m.Properties)
.Returns(new PropertyCollection());
Results with the following error:
The type 'System.DirectoryServices.PropertyCollection' does not contain constructors
As I understand it, this error occurs when trying to create an instance of a class with only internal constructors:
Type '...' does not contain constructors
/ PropertyCollection, , .
, / "" DirectoryEntry ?