none
EF 4.2 doesn't support Mocking the CRUD RRS feed

  • Question

  • I was trying to use Moq to mock CRUD of the dbcontext but I got this error:

        Invalid setup on a non-virtual (overridable in VB) member: x => x.Add(.pricingTest)

    Is there any future feature relating to defining CRUD methods with virtual?

    Monday, February 20, 2012 8:02 PM

Answers

  • You don't need to use any mocking library with EF. Just use different connection strings with different database (e.g. SQL CE) in test project ... 

    Michael Sync: blog: http://michaelsync.net

    Wednesday, February 22, 2012 5:20 AM

All replies

  • Hi,

    In order to control the behavior of a mock object (in Moq, at least), you either need to mock an interface, or make sure that the behavior you're trying to control is marked virtual. Try to add virtual before Add method.


    I am fish.

    Tuesday, February 21, 2012 7:35 AM
  • You don't need to use any mocking library with EF. Just use different connection strings with different database (e.g. SQL CE) in test project ... 

    Michael Sync: blog: http://michaelsync.net

    Wednesday, February 22, 2012 5:20 AM
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 6:43 AM
    Moderator