EF6 - Cannot Mock Return Value for ObjectResult for Unit Test

c# entity-framework-6 mocking moq unit-testing

Accepted Answer

I may be mistaken, but why can't you just do this:

class TestableObjectResult<T> : ObjectResult<T>
{
}

then during your test:

var mockObjectResult = new Mock<TestableObjectResult<usp_get_Some_Data_Result>>();

I'm not sure what you mean when you say that you're "calling base() on the constructor" because MockObject does have a protected constructor, and since it doesn't have any parameters, the auto-wiring will take care of it when you construct the tested version.

This is what the top of the file looks like if I right-click on ObjectResult and choose Go To Definition:

public class ObjectResult<T> : ObjectResult, IEnumerable<T>, IEnumerable, IDbAsyncEnumerable<T>, IDbAsyncEnumerable
{
    // Summary:
    //     This constructor is intended only for use when creating test doubles that
    //     will override members with mocked or faked behavior. Use of this constructor
    //     for other purposes may result in unexpected behavior including but not limited
    //     to throwing System.NullReferenceException.
    protected ObjectResult();
7
6/26/2015 7:12:16 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow