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
0 votes
I'm probably missing something here but suppose I have a method to test which returns an object:e.g.

public Control CreateAndInitialiseCounterpartyControl() {   
         CounterpartyCombo cbo = new CounterpartyCombo();
         cbo.CounterpartySearchType = CounterpartSearchType.Counterparty;
         cbo.AutoComplete = true;
         return cbo;
      }


In my test I want to mock the CounterpartyCombo control and verify that the returned Control is the mock CounterpartyCombo?

Mock mockCounterpartyCombo = MockManager.Mock(typeof (CounterpartyCombo), Constructor.Mocked);
         
         mockCounterpartyCombo.ExpectSet("CounterpartySearchType").Args(CounterpartSearchType.Counterparty);
         mockCounterpartyCombo.ExpectSet("AutoComplete").Args(true);
         
         Control actual = this.bulkAmendEditorFactory.CreateAndInitialiseCounterpartyControl();
         
         Assert.AreEqual(mockCounterpartyCombo.MockedType, actual.GetType());


How do I check that 'actual' is under the control of the mockCounterpartyCombo?

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

1 Answer

0 votes
We support this scenario in the version 3.5. have Look at
mock.MockedInstance.
The documentation links below:
:arrow: Asserting Fields by Accessing Future Instances
:arrow: Mock.MockedInstance

The test method should look like this:

        
Mock mockCounterpartyCombo = MockManager.Mock(typeof(CounterpartyCombo), Constructor.Mocked);
        
mockCounterpartyCombo.ExpectSet("CounterpartySearchType").Args(CounterpartSearchType.Counterparty);
mockCounterpartyCombo.ExpectSet("AutoComplete").Args(true);

Control actual = this.bulkAmendEditorFactory.CreateAndInitialiseCounterpartyControl();
Assert.AreSame(mockCounterpartyCombo.MockedInstance, actual);


This will verify that the object 'actual' is mocked.
:idea: However if you just want to to see once that actual object is mocked and not include that in your tests you can use the the TypeMock tracer (Tools -> TypeMock Trace)
answered by ohad (35.4k points)
...