I am trying to make fun of the SearchResultCollection class. However, when I try to catch the GetSourceLoaded call, my test throws an exception:
System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: x => x.PropertiesLoaded
My code is:
Mock<SearchResultCollection> searchResultMock = new Mock<SearchResultCollection>(); // Set up collection that will be returned string[] tempData = { "one", "two" }; searchResultMock.SetupGet(x => x.PropertiesLoaded).Returns(tempData);
Has anyone successfully mocked such a class? The property in question has only a getter and is not virtual.
// // Summary: // Gets the System.DirectoryServices.DirectorySearcher properties that were // specified before the search was executed. // // Returns: // An array of type System.String that contains the properties that were specified // in the System.DirectoryServices.DirectorySearcher.PropertiesToLoad property // collection before the search was executed. public string[] PropertiesLoaded { get; }
Markp source share