mercredi 29 juillet 2015

Possible to Freeze a Mock of a func?

I want to test that my func type is actually executed. To do that I have created a mock, but I run into an Exception from Autofixture. I tried to Freeze just the func (without the mock) and this works. Can someone explain whats happening or guide me to the right way of doing this?

Exception message:

An exception of type 'Ploeh.AutoFixture.Kernel.IllegalRequestException' occurred in Ploeh.AutoFixture.dll but was not handled in user code Additional information: A request for an IntPtr was detected. This is an unsafe resource that will crash the process if used, so the request is denied. A common source of IntPtr requests are requests for delegates such as Func or Action. If this is the case, the expected workaround is to Customize (Register or Inject) the offending type by specifying a proper creational strategy.

Code:

var frozenFunc = F.Freeze<Func<int, DomainClassDummy>>(); //works
var frozenMockOfFunc = F.Freeze<Mock<Func<int,DomainClassDummy>>>(); //fails 
public class DomainClassDummy
{
    public int Id { get; set; }
}

Aucun commentaire:

Enregistrer un commentaire