Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moq mocking a class

I'm new to Moq and mocking.

I have a class Car and I want to Mock this class:

Car car = Mock<Car>();

I'm getting the error "Cannot implicitly convert type 'Moc.Mock' to 'Car'.

It seems I could do this if I had:

Car car = Mock<ICar>();

However I don't actually have a ICar

Can anyone tell me how to achieve the mock of Car?

like image 855
AnonyMouse Avatar asked Jul 28 '11 20:07

AnonyMouse


1 Answers

var mockCar = Mock<Car>();
// Configure the mock properties and methods.

Car car = mockCar.Object;
like image 182
blowdart Avatar answered Sep 21 '22 00:09

blowdart