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 don't quite understand why WhenArgumentsMatch does not work well with Repeat Always. Here is the test code:
      [Test, VerifyMocks]
      public void TestMessageBoxNatural2()
      {
         using(RecordExpectations recorder = RecorderManager.StartRecording())
         {
            MessageBox.Show("Lita");
            recorder.Return(DialogResult.OK).WhenArgumentsMatch("Welcome!");
            recorder.RepeatAlways();
         }
         epsilonT eps = new epsilonT();
         eps.MessageBoxShow();
         Assert.AreEqual(100.0, eps.Tol);
      }


And here's the Logic code:
   public class epsilonT
   {
      private double tol;
      public double Tol
      {
         get { return tol; }
         set { tol = value; }
      }
      public epsilonT()
      {

      }

   //   public epsilonT(double wu)
      public static bool IsEpsilon(double ptValue)
      {
         return ptValue==0;
      }

      public void MessageBoxShow()
      {
            MessageBox.Show("Welcome!");
         MessageBox.Show("Welcome!");
         tol = 100.0;
      }
   }

When I ran the code, only one MessageBox.Show is mocked away even though I specify that the mock should be RepeatAlways.
________
hashish
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi,

If you want to do this, you should use:
         using(RecordExpectations recorder = RecorderManager.StartRecording()) 
         { 
            MessageBox.Show("Lita");
            recorder.Return(DialogResult.OK).RepeatAlways().WhenArgumentsMatch("Welcome!"); 
         } 


which will do the trick.

And, appearantly, you have found us a bug :twisted: . Because it is likely that the code you've written is expected to work, despite breaking it into 2 lines.

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