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 was assuming that TypeMock would automatically created recursive fakes and support nested calls to verify method calls. However, I had to use the below code

        private static Environment SetUpFakeEnvironmentToGetSettings(int settingIndex, EnvironmentSettings settings)
        {
            var env = Isolate.Fake.Instance<Environment>();
            Isolate.WhenCalled(() => env.Settings).WillReturn(settings);
            Isolate.WhenCalled(() => settings.ElementAt(settingIndex)).WillReturn(Isolate.Fake.Instance<EnvironmentSetting>());
            return env;
        }


To get the below code working.

        
        [TestMethod]
        [Isolated]
        public void UseTheFirstSettingInEnvironmentSettingsToSetAndGetTheDatabaseConnectionString()
        {
            const int firstSetting = 0;
            var sets = Isolate.Fake.Instance<EnvironmentSettings>();
            var env = SetUpFakeEnvironmentToGetSettings(firstSetting, sets);
            var genv = new GenFormEnvironment(env);

            try
            {
                var cs = genv.GenFormDatabaseConnectionString;
                Isolate.Verify.WasCalledWithExactArguments(() => sets.ElementAt(firstSetting));
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
        }


If I simply return Isolate.Fake.Instance<Environment>() without:
Isolate.WhenCalled(() => env.Settings).WillReturn(settings);
Isolate.WhenCalled(() => settings.ElementAt(settingIndex)).WillReturn(Isolate.Fake.Instance<EnvironmentSetting>());

then I get TypeMock errors. If I do not explicitly fake EnvironmentSettings, the I get a Verify exception telling me that ElementAt was not called.

Am I missing something?
asked by halcwb (5.5k points)

1 Answer

0 votes
Hi,

Can you post what Typemock errors do you get?

About not faking ElementAt explicitly - since ElementAt is an extension method it is not faked by default as a method which is defined on the type. The error message is misleading, it should have warned you that the type being verified is not tracked.

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
...