chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have the following production code:

private void InitializeInstrumentTemplateLoaderParams()
      {
         this.instrumentTemplateLoaderParams = new DefaultInstrumentTemplateLoaderParams();

         this.instrumentTemplateLoaderParams.InstrumentTemplateMetaList = this.GetInstrumentMetas();

         this.stateProvider.SetSessionData(this.sessionId, this.instrumentTemplateLoaderParamsKey, this.instrumentTemplateLoaderParams);   
      }


As you can see - I instantiate a DefaultInstrumentTemplateLoaderParams instance which is then later passed as an argument to a dependency which I wish to mock.

My test case is as follows:

[Test]
      public void InitializeInstrumentTemplateLoaderParamsTest()
      {
         Mock mockDefaultInstrumentTemplateLoaderParams = MockManager.Mock(typeof(DefaultInstrumentTemplateLoaderParams), Constructor.Mocked);
         mockDefaultInstrumentTemplateLoaderParams.ExpectConstructor();

         this.mockBasePage.ExpectAndReturn("GetInstrumentMetas", this.expectedInstrumentMetas);

         mockDefaultInstrumentTemplateLoaderParams.ExpectSet("InstrumentTemplateMetaList");

         this.mockStateProvider.ExpectCall("SetSessionData");//.Args(this.expectedSessionId, this.expectedInstrumentTemplateLoaderParamsKey, <the instance I created>);

         base.InvokeMethod("InitializeInstrumentTemplateLoaderParams", null);
      }


I have been forced to remove the .Args check from the ExpectCall because I don't see a way to set the arg?

/NB/ The base.InvokeMethod is just a wrapper around some reflection code to invoke a protected/private member.

Regards,

c0d3-m0nk3y
asked by c0d3-m0nk3y (8.7k points)

4 Answers

0 votes
Hi c0d3-m0nk3y,
What a great scenario!!

:arrow: From what I understand you want to check if the parameter passed is the instance of a mocked type.
Hmmm, I can't think of a way to do this, I think that we will have to add this scenario to our new feature list.
Probably something like Check.IsMockedInstance(mock)

In the meantime untill this feature is completed you can ignore just that argument as follows:
this.mockStateProvider.ExpectCall("SetSessionData").
    Args(this.expectedSessionId,Check.IsAny()); 
answered by scott (32k points)
0 votes
Thanks, Scott! Prompt reply as always :wink: If I come up with any other head-scratchers I'll forward them on!

Look forward to seeing the next release, will use the CheckAny() in the meantime....
answered by c0d3-m0nk3y (8.7k points)
0 votes
c0d3-m0nk3y,

You should check this in version 3.1.4.

this.mockStateProvider.ExpectCall("SetSessionData"). Args(this.expectedSessionId,
        Check.IsMock(mockDefaultInstrumentTemplateLoaderParams ));
answered by richard (3.9k points)
0 votes
I would but my clients free upgrades ran out on 17th May!!

For now I am using Cjeck.IsTypeOf() but will definitely .IsMock() when budget > license price :lol:

Thanks again.
answered by c0d3-m0nk3y (8.7k points)
...