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 am trying to upgrade our projects to use Isolator 5.4.5 and am running into issues. A handful of our tests follow the pattern of the below code snippet. If you run the test you will get this error:

TypeMock.TypeMockException:
*** No method with name <AreAnyActive in type TEST.Acme exists.
at cn.b(Type A_0, String A_1)
at cn.c(Type A_0, String A_1)
at ce.a(String A_0, Object[] A_1, Object A_2, Object A_3, String A_4, Type A_5)
at c8.a(String A_0, Object A_1, MethodBase A_2, Object[] A_3, Object A_4, String A_5, ce A_6)
at c8.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
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, Object p1)
at TEST.Acme.<AreAnyActive>b__0(Acme acme) in TestTests.cs: line 27
at System.Collections.Generic.List`1.FindIndex(Int32 startIndex, Int32 count, Predicate`1 match)
at System.Collections.Generic.List`1.FindIndex(Predicate`1 match)
at System.Collections.Generic.List`1.Exists(Predicate`1 match)
at TEST.Acme.AreAnyActive() in TestTests.cs: line 27
at TEST.Tests.Should_return_false_if_no_active_acmes() in TestTests.cs: line 62

However, if you comment out the AreAnyActive() method and un-comment the alternate implementation the test functions properly. The only difference between these methods is the second is manually foreaching over the acmes collection instead of using the implicit iteration of the Exists() method.

using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using TypeMock.ArrangeActAssert;

namespace TEST
{
    public class Acme
    {
        public bool IsActive { get; set; }

        public Acme(bool isActive)
        {
            IsActive = isActive;
        }

        public static List<Acme> GetCollection()
        {
            // data access stuff we want to mock
            return null;
        }

        public static bool AreAnyActive()
        {
            var acmes = GetCollection();
            return acmes != null && acmes.Exists(acme => !acme.IsActive);
        }

        //public static bool AreAnyActive()
        //{
        //    var acmes = GetCollection();

        //    if (acmes == null)
        //    {
        //        return false;
        //    }

        //    foreach (var acme in acmes)
        //    {
        //        if (acme.IsActive)
        //        {
        //            return true;
        //        }
        //    }

        //    return false;
        //}
    }

    [TestFixture]
    public class Tests
    {
        [Test]
        public void Should_return_false_if_no_active_acmes()
        {
            // mocked list of acmes
            var acmes = new List<Acme>();
            acmes.Add(new Acme(false));
   
            Isolate.WhenCalled(() => Acme.GetCollection()).WillReturn(acmes);
            Assert.That(Acme.AreAnyActive(), Is.Not.True);
        }
    }
}
asked by MikeAtConix (600 points)

1 Answer

0 votes
Hi Mike,

This issue seemed to be resolved in our upcoming version that will be out soon.
I'll send a preview version, please check it out and let me know if it solves your problem.
answered by ohad (35.4k points)
...