The Funct is defined as a property so you should use SetupSet within Moq
public interface IPersona
{
string nome { get; set; }
string cognome { get; set; }
Func<Owned<ISomeInterface>> somemethod { get; set; }
}
. In your test :
You create a mock for the Func:
Func<Owned<ISomeInterface>> somemethodMock = () => new Mock<Owned<ISomeInterface>>().Object;
THen you setup the mock for the Class containing the Func as a property and you setup the expectation on the Set method :
var obj = new Mock<IMyInterface>();
obj.SetupSet(x => x.somemethod = somemethodMock).Verifiable();
You create the container object for the mock:
//We pass the mocked object to the constructor of the container class
var container = new Container(obj.Object);
container.AnotherMethod(somemethodMock);
obj.VerifyAll();
Here is the definition of Another method of the Container class, if get the func as an input parameter and set it to the property of the contained object
enter public class Container
{
private IPersona _persona;
public Container(IPersona persona)
{
_persona = persona;
}
public void AnotherMethod(Func<MyClass<IMyInterface>> myFunc)
{
_persona.somemethod = myFunc;
}
}