Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument 1: cannot convert from 'Moq.Mock<System.Data.Entity.DbContext>' to 'System.Data.Entity.DbContext'

on my mocked context I have the following:

 var mockContext = new Mock<DbContext>();
 mockContext.Setup(c => c.Set<Track>()).Returns(mockSet.Object);

an when I try to create mocked object for my repository I use the following code

EfRepository<Track> _efTrackRepository = new EfRepository<Shelf>(mockContext);

and I get the following error, is there any way I can solve this out?

error:

Argument 1: cannot convert from 'Moq.Mock<System.Data.Entity.DbContext>' to 'System.Data.Entity.DbContext'

like image 741
ravi Avatar asked Oct 13 '15 20:10

ravi


1 Answers

You should use mockContext.Object

//
// Summary:
//     Exposes the mocked object instance.
public virtual T Object { get; }
like image 77
Jakub Lortz Avatar answered Nov 14 '22 22:11

Jakub Lortz