Question about using GetObjectQuery method with Test Automation

Dave Ford asked on July 17, 2014 16:34

I am working with the Sample Unit Tests provided and the Test Automation article [here].(

I am trying to figure out how to use GetObjectQuery method mentioned in this paragraph.

Note: To be able to completely fake a provider object it must run all involved operations via the GetObjectQuery method – see the list of all providers whose all read methods can be used in a faked provider. Every provider method that uses ObjectQuery for reading data can be used in the unit test with a particular provider faked.  If you miss the possibility to fake any particular provider, please let us know.

I am not sure how to Fake the DataClassInfoProvider in the SimpleUnitTests example. Can someone help me with this.


Correct Answer

Michal Pietrik answered on July 21, 2014 16:58

Hello Dave,

DataClassInfoProvider in SampleUnitTests is already faked using Fake method.

    public void Init()
        // Fake the data of a particular provider
        Fake<DataClassInfo, DataClassInfoProvider>().WithData(
            DataClassInfo.New(dc =>
                dc.ClassID = 1;
                dc.ClassName = "MyTest.MyClass";

When you use DataClassInfoProvider to get DataClassInfo(s), it gets the faked data instead of accessing the database. In SampleUnitTests exapmle it behaves as if there was single DataClass (with ClassID = 1 and ClassName = "MyTest.MyClass") in the database.

The prerequisite for getting faked data (provided by Fake method) and not accessing the database is that method (eg. DataClassInfoProvider.GetDataClassInfo) gets the data using the ObjectQuery internally.

You don't need to do anything with GetObjectQuery method in your tests.

Best regards, Michal

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.