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 am writing unit tests for a windows form named User. A picture box which is named as guiPictureBox is located int the form. I'm trying to write unit test for function UpdateGuiPictureBox (signature is private void UpdateGuiPictureBox()) which is loads a new picture to picturebox if a boolean value(named updateIndicator) is true. I tried to verify that if updateIndicator is false; guiPictureBox.Load() function is not called. I achieved to test it using ReflectiveMocks, but could not achieve it with AAA API. I would appreciate if you tell me what to do

My test code:
User user = new User();
ObjectState.GetField(user,"updateIndicator", false);
PictureBox pb = ObjectState.GetField(user, "guiPictureBox") as PictureBox;
Isolate.WhenCalled(() => pb.Load()).IgnoreCall();

Isolate.Invoke.Method(user, "UpdateGuiPictureBox");

Isolate.Verify.WasNotCalled(() => pb.Load()); ===============>Here I got Nested Call Exception was unhandled by user code error. I states "Verify doesn't support using a method call as an argument. To fix this pass null instead of PictureBox.ToString()"
asked by mkg (24.3k points)

3 Answers

0 votes
I am not sure, but try this:
User user = new User();
ObjectState.SetField(user,"updateIndicator", false);
PictureBox pb = Isolate.Fake.Instance<PictureBox>();
ObjectState.SetField(user, "guiPictureBox",pb)
Isolate.WhenCalled(() => pb.Load()).IgnoreCall();

Isolate.Invoke.Method(user, "UpdateGuiPictureBox");

Isolate.Verify.WasNotCalled(() => pb.Load())
answered by scott (32k points)
0 votes
When I tried this a got the same error message in the row marked as ****

User user = new User();
ObjectState.SetField(user,"updateIndicator", false);
PictureBox pb = Isolate.Fake.Instance<PictureBox>();
ObjectState.SetField(user, "guiPictureBox",pb)
Isolate.WhenCalled(() => pb.Load()).IgnoreCall();   ****

Isolate.Invoke.Method(user, "UpdateGuiPictureBox");

Isolate.Verify.WasNotCalled(() => pb.Load())


Any idea is welcomed :)
answered by mkg (24.3k points)
0 votes
Please send me the code to support at typemock.com so that I can help.
answered by scott (32k points)
...