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
Tried to do something that may just be me, but may be a constraint of using the framework - I'm evaluating so while simple, is demonstrative of how I'll want to use the framework.

Below we have a class that I'm mocking the accessor for (the existing brown-field application that I'd be introducing Typemock to already uses private accessors like this). The method I'm mocking is actually an overload of another method with the same number of parameters, but different type.

When running test, it appears to be mocking all signatures; the first Assert fails because the return is 'Mocked Return', not 'Mocked Return5' as I'd expect:

Code we're testing with mocks:
   internal static class MocksExampleManager
   {
      //This is the method we mock in our test...
      private static string GetCustomer(string customerId)
      {
         throw new NotImplementedException();
      }

      //The Assert call in our test calls this method, so the return
      //should always be 'Mocked ReturnX' where 'X' is the int passed.
      internal static string GetCustomer(int id)
      {
         string tmp = GetCustomer(id.ToString());
         return tmp + id.ToString();
      }
   }


Actual test itself:

      [TestMethod(), Isolated()]
      [DeploymentItem("MocksExample.Test.dll")]
      public void GetCustomerUsingAAATest()
      {
         using (RecordExpectations recorder = new RecordExpectations())
         {
            MocksExampleManager_Accessor.GetCustomer(string.Empty);
            //by default only returned once
            recorder.Return("Mocked return");
         }

         //FAILING HERE!
         Assert.AreEqual<string>("Mocked return5", MocksExampleManager_Accessor.GetCustomer(5));

         try
         {
            Assert.AreEqual<string>("Mocked return5", MocksExampleManager_Accessor.GetCustomer(5));
            Assert.Fail("Only returns once!  Shouldn't of succeeded");
         }
         catch (NotImplementedException)
         {
            //expected.
         }
      }


Update: I actually added a parameter to the method being called (the 'int' version) to see if that would make a difference; it didn't (the below has the same problem):

      //Still fails after adding second parameter
      internal static string GetCustomer(int id, bool test)
      {
         string tmp = GetCustomer(id.ToString());
         return tmp + id.ToString();
      }


Another Update: I have confirmed that if I change the signature of GetCustomer(int, bool) to something like GetCustomer1(int, bool) or just GetCustomer1(int) everything works as expected (test passes).
asked by boo (21.8k points)

3 Answers

0 votes
Hi Brian,

You are correct, Isolator does not support overloads. Trying to mock an overload may work, but may also result in unexpected behavior.

Supporting overloads is on our feature list. It's going to enter into our one of our next future releases.

Thanks
answered by gilz (14.5k points)
0 votes
Cool. Looking forward to it. Is there a link to a road map with dates on upcoming features such as this somewhere or is it too far off for that?
answered by boo (21.8k points)
0 votes
Hi Brian,

Now that version 5.0 is out, we are working on updating our roadmap for our next releases. We then going to publish it.

Thanks,
answered by gilz (14.5k points)
...