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
Hi i m facing some problems with overloading methods could u please point the correct way
public class Class6
   {
      public Class6()
      {
         
      }

      

      public RepositoryItemLookUpEdit RepositoryItemLookUpEdit(TextEditStyles textEditStyles,Type xpBaseObjectType, string displayMember, bool isMock)
      {
         RepositoryItemLookUpEdit lookUpEdit=RepositoryItemLookUpEdit(xpBaseObjectType,displayMember,isMock);
         lookUpEdit.TextEditStyle=textEditStyles;
         return lookUpEdit;
      }
      public RepositoryItemLookUpEdit RepositoryItemLookUpEdit(Type xpBaseObjectType, string displayMember, bool isMock)
      {
         RepositoryItemLookUpEdit repositoryItemLookUpEdit = new RepositoryItemLookUpEdit();
         return repositoryItemLookUpEdit;
      }
   }
   [TestFixtureAttribute]
   public class test
   {
      [Test]
      public void MethodName()
      {
         MockManager.Init();
         Mock mock=MockManager.Mock(typeof(Class6));
         mock.Strict = true;
         
         mock.ExpectAndReturn("RepositoryItemLookUpEdit",MockManager.CONTINUE_WITH_METHOD).Args(
            TextEditStyles.Standard, typeof(Stoiheio),"StoiheioName",true);


         mock.ExpectAndReturn("RepositoryItemLookUpEdit",
            new Class6().RepositoryItemLookUpEdit(TextEditStyles.Standard, typeof(Stoiheio),"StoiheioName",true)) 
            .Args(typeof (Stoiheio));
      }
   }
asked by tolisss (28.8k points)

4 Answers

0 votes
Hi,
TypeMock does NOT diffrentiate between overload methods.
There is no need to add Arg() tests, this doesn't help.

The only way to look at it is by seeing the overload methods as one method and knowning when each one will be called.

So if you know that RepositoryItemLookUpEdit will be called the first time with (Type...) and the second time with (TectEditStyles...) you can do the following:

// The first time , just continue
mock.ExpectAndReturn("RepositoryItemLookUpEdit",MockManager.CONTINUE_WITH_METHOD);
// The second time - mock
Class6 returnClass = new Class6().RepositoryItemLookUpEdit(TextEditStyles.Standard, typeof(Stoiheio),"StoiheioName",true);
mock.ExpectAndReturn("RepositoryItemLookUpEdit", returnClass);


I hope this clear things up
answered by scott (32k points)
0 votes
the above code fails when i initialize for 2nd time the repositoryItem class if i have a way of setting constructor expectations shouldn't it pass

ps:I consider the strict mode as an always on feature never work on off mode
answered by tolisss (28.8k points)
0 votes
the above code fails when i initialize for 2nd time the repositoryItem class if i have a way of setting constructor expectations shouldn't it pass

ps:I consider the strict mode as an always on feature never work on off mode
answered by tolisss (28.8k points)
0 votes
the above code fails when i initialize for 2nd time the repositoryItem class if i have a way of setting constructor expectations shouldn't it pass

Hi
I don't really understand your problem, do you need constructor expectation? can you please elaborate

ps:I consider the strict mode as an always on feature never work on off mode

This is not always the best way to go, if you keep Strict on, you will find allot of maintainance of your tests. There are times when Strict is needed and others not. To decide, remember that you should mock methods that have a large setup, or that take a long time to run (Basiclly the same goes to regular Mock Objects), but then this is a discussion for the Patterns Forum.
answered by scott (32k points)
...