c# - Mocking Func property of a class -
One of my repository classes (called person Rippo) has a representative, as its property is something like this
Private Readonly Func & lt; INameRepo & gt; _nameRepo; And apart from this it is inherited by a class which expects itself to be another object (the session says).
Thus, when I put my intentions in my test such as something
var funcNameRepo = automock.mock & lt; Funk & lt; INameRepo & gt; & Gt; (); _personRepo = new person repo (session, funka name ripper. Object); But when I run this test, I get the following error:
Unable to remove type object 'System.Func1' [ Repositories.Interfaces. INameRepo] to type 'Moq.IMocked `1 [System.Func`1 [Repositories.Interfaces.IEMRepo]]'. Do you think I am doing wrong here, please help me?
Why Func & lt; INameRepo & gt; Duplicate? If you want to duplicate INameRepo , then make a duplicate for INameRepo and pass it through your PersonRepo one lambda (which That funk & lt; INameRepo & gt; ):
var nameRepo = autoMock.Mock & lt; INameRepo & gt; (); _personRepo = New person Repo (session, () = & gt; nameRepo.Object);
Comments
Post a Comment