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
The below test will fail with null reference exception:
    public enum Country
    {
        Antartica
    }

        [Test, Isolated]
        public void BigCountry()
        {

            Isolate.WhenCalled(()=>Enum.GetNames(typeof(Country))).WillReturn(new[]{"A"});
        }


The exception is
TestCase 'BigCountry' failed: System.NullReferenceException : Object reference not set to an instance of an object.
   at c9.a(et A_0)
   at c9.a(Object A_0)
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy Documentsjobs	hird party components	ypemockEnumMockEnumMockEnumMockCountryTest.cs(23,0): at EnumMock.CountryTest.BigCountry()
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy Documentsjobs	hird party components	ypemockEnumMockEnumMockEnumMockCountryTest.cs(20,0): at EnumMock.CountryTest.BigCountry()



I think this is pretty unclear; it should be TypeMockException, rather than a null reference exception.
________
Babi mac proved that
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon

You are right about the message. We fixed this bug in the upcoming version and indeed you'll get TypeMockException.

Please note that currently the test will not pass since the Enum class is defined in mscorlib so we can't fake the GetNames method :(
answered by ohad (35.4k points)
...