Sto provando a prendere in giro la classe SearchResultCollection. Tuttavia, quando si tenta di intercettare una chiamata al getter PropertiesLoaded, la mia prova genera un'eccezione:Moq C# integrato nella classe
System.NotSupportedException: Invalid setup on a non-virtual (overridable in VB) member: x => x.PropertiesLoaded
My Code:
Mock<SearchResultCollection> searchResultMock = new Mock<SearchResultCollection>();
// Set up collection that will be returned
string[] tempData = { "one", "two" };
searchResultMock.SetupGet(x => x.PropertiesLoaded).Returns(tempData);
Qualcuno ha preso in giro con successo una classe come questa? La proprietà in questione ha solo un getter e non è virtuale.
//
// 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; }
possibile duplicato di [? Perché non posso prendere in giro MouseButtonEventArgs.GetPosition() con Moq] (http://stackoverflow.com/questions/1918208/why-cant-i-mock-mousebuttoneventargs-getposition-with-moq) – TrueWill