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
Hi TypeMock

I am trying to use Isolate.Swap.CallsOn, to swap calls on A to B:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock;
using TypeMock.ArrangeActAssert;

namespace TestProject1
{
    [TestClass]
    public class ProgramTest
    {
        public class A
        {
            public void Method() 
            {
                Console.WriteLine("A Method()");
            }

            public void Method(int i) 
            {
                Console.WriteLine("A Method(int i)");
            }
        }

        public class B
        {
            public void Method() 
            {
                Console.WriteLine("B Method()");
            }

            public void Method(int i) 
            {
                Console.WriteLine("B Method(int i)");
            }
        }

        [TestMethod]
        [Isolated]
        public void OverloadedMethodSwapTest()
        {
            var a = new A();
            var b = new B();

            Isolate.Swap.CallsOn(a).WithCallsTo(b);

            a.Method(); // Fails
            // a.Method(1); // Works
            Assert.IsTrue(true);
        }
    }
}


But when I execute the test I get this exception:

Test method TestProject1.ProgramTest.OverloadedMethodSwapTest threw exception: System.Reflection.TargetParameterCountException: Parameter count mismatch..

Calling a.Method(1) works, and if I comment out public void Method(int i) in both classes it also works.

Is this a but or am i doing something wrong?
asked by ahvam (1.7k points)

4 Answers

0 votes
Hi,

This is a bug. Thanks for reporting it, we will fix it and update you once it's fixed.
answered by ohad (35.4k points)
0 votes
Has this been fixed? I'm using Isolator 6.0.8 and have what appears to be a related issue. If I try to Swap.CallsOn a collection-based object (with parameterized property indexer overloads) I get something similar.

System.Web.SessionState.HttpSessionState is basically a wrapper around a System.Collections.Specialized.NameObjectCollectionBase. The System.Collections.Specialized.NameValueCollection derives from NameObjectCollectionBase.

So in a web-related test, I have:

var session = Isolate.Fake.Instance<HttpSessionState>();
var coll = new NameValueCollection();
Isolate.Swap.CallsOn(session).WithCallsTo(coll);


Later, in my tests, I do:

Assert.IsNull(session["key"]);


On this line, I get an exception:

System.ArgumentException: Object of type 'System.String' cannot be converted to type 'System.Int32'.


The reason for this, it appears, is that the collection has two indexer properties:

public string this[string] { get; set; }
public string this[int] { get; set; }


That is, you can access items in HttpSessionState OR in NameValueCollection by item index or by item key. The swapper is, I'm guessing, picking the wrong indexer and trying to call the int-based collection indexer when I'm passing a string key.

I can work around this, but it would be nice to have this work out of the box.
answered by tillig (6.7k points)

Hi,

We fixed this bug in the new version which is avalible in our website.smiley

 

 

0 votes
Hi Travis,

Sorry not yet :oops:
answered by ohad (35.4k points)
0 votes
Hi,

This bug is fixed in version 8.0.4 which is avaliable on our website :)
answered by inga (280 points)
edited by alex
...