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
Take this simple test:
[TestMethod]
public void TestProperty()
{
   MockManager.Init();
   MockObject<Test> t = MockManager.MockObject<Test>();
   t.ExpectGetAlways("TestProperty", "test");
   Assert.IsNotNull(t);
   MockManager.Verify();
}

I would expect the test to fail on the verify, but it doesn't. Am I missing something? This is with 5.1.1.0, but other people in our organization have had the same problems with 5.2.2 and 5.2.3. Verify seems to work if I use ExpectGet instead of ExpectGetAlways.
asked by nbrett (1.7k points)

3 Answers

0 votes
I'm not sure why you're having this issue - I need to further investigate this.

Is there a reason you're not using AAA API?

[TestMethod]
public void TestPropertyUsingAAA()
{
    var t = Isolate.Fake.Instance<Test>();

    Isolate.WhenCalled(() => t.TestProperty).WillReturn("test");

    Isolate.Verify.WasCalledWithAnyArguments(() => t.TestProperty);
}


Seems like a better way to write the test you've posted
answered by dhelper (11.9k points)
0 votes
hi,

ExpectGetAlways semantics means that it will expect zero or more calls to it.
which mens that not having any calls will not fail the verify.

You can either use the AAA syntax as Dror has suggested,
or if you want to code something in the spirit of expect 1 or more calls
try adding a regular ExpectGet statement just before the ExpectGetAlways
answered by error (6.6k points)
0 votes
I figured that out, but nowhere in the documentation is that mentioned, and the name indicates you are setting up an expectation. It is just confusing the way it is named.

The reason this isn't using AAA is because this is one of hundreds of unit tests that were written prior to AAA being supported, and I am not interested in going back and rewriting them.
answered by nbrett (1.7k points)
...