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'm running into a weird issue when returning a struct from a mock object. The wierd thing is that if the mock is an interface or I step through the test with the debugger then everything works fine. If the mock is of a concrete class or I dont use the debugger, the test will fail.

Here is a test method and some classes you can use to reproduce this

[TestMethod, VerifyMocks]
      public void Test() {
         ResultFacade facade = new ResultFacade();
         ResultService service = RecorderManager.CreateMockedObject<ResultService>();
         facade.ResultService = service;
         
         KeyValuePair<bool, bool> trackResult = new KeyValuePair<bool, bool>(true, true);

         using(RecordExpectations recorder = RecorderManager.StartRecording()){
            recorder.ExpectAndReturn(service.GetResult(null), trackResult);
            service.Publish();
         }
         
         facade.PublishResult(null);
      }


public class ResultService {
      public KeyValuePair<bool, bool> GetResult(object id) {
         return new KeyValuePair<bool, bool>(false, false); 
      }
      
      public void Publish() {
         
      }
   }
   
   public class ResultFacade {
      private ResultService _resultService;

      public ResultService ResultService {
         get {return this._resultService;}
         set {this._resultService = value;}
      }

      public void PublishResult(object id) {
         KeyValuePair<bool, bool> result = this.ResultService.GetResult(id);

         if (result.Key) {
            this.ResultService.Publish();
         }
      }
   }


I have trimmed this problem down to the bare bones as you can see. Basically when mocking the GetResult method and returning a KeyValuePair, the publish method will never get called because the key always returns false for some reason even though the mocked GetResult method is supposed to return a KeyValuePair with the key equal to true.

Let me know if you need anymore info but everything should be there.
asked by juice_johnson (9.8k points)

5 Answers

0 votes
Hi
You have found a bug. :oops:
Thanks for pointing it out. We will fix it and I'll send you the patch.
answered by ohad (35.4k points)
0 votes
was this fixed in the latest release?
answered by juice_johnson (9.8k points)
0 votes
Hi
No its a new one.
I hopefully it will be in our next release.
answered by ohad (35.4k points)
0 votes
Can you send me the patch then as you mentioned on 11/14. Thanks.
answered by juice_johnson (9.8k points)
0 votes
Hi
Sorry I think there's a misunderstanding here.
The patch is not ready yet :(
As I said: I will send you the patch when it will be ready.
answered by ohad (35.4k points)
...