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 using TypeMock 3.6.
I have an abstract class which I am trying to get an instance of. When I use
MockObject absItemMock = MockManager.MockObject(typeof(AbsItem), Constructor.NotMocked);
it works fine. However, if I change the call to pass a parameter to the constructor like this:
MockObject absItemMock = MockManager.MockObject(typeof(AbsItem), Constructor.NotMocked, "8");
it fails with this error:

TestCase 'AbstractMocking.Tests.TestFails'
failed: System.MissingMethodException : Constructor on type MockAbsItem not found.
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
   c:bstractmockingmain.cs(26,0): at AbstractMocking.Tests.TestFails()


1 passed, 1 failed, 0 skipped, took 0.91 seconds.


Here is the full source of a test scenario:

using System;
using NUnit.Framework;
using TypeMock;

namespace AbstractMocking {
    public abstract class AbsItem {
        public int val = 0;

        public AbsItem() {
            val = 5;
        }

        public AbsItem(string sval) {
            val = Int32.Parse(sval);
        }

        public void Configure() {
            val = 10;
        }
    }

    [TestFixture]
    public class Tests {
        [Test]
        public void TestFails() {
            MockObject absItemMock = MockManager.MockObject(typeof(AbsItem), Constructor.NotMocked, "8");
            
            AbsItem item = (AbsItem)absItemMock.Object;
            absItemMock.ExpectCall("Configure");
            
            item.Configure();
        }

        [Test]
        public void TestPasses() {
            MockObject absItemMock = MockManager.MockObject(typeof(AbsItem), Constructor.NotMocked);
            
            AbsItem item = (AbsItem)absItemMock.Object;
            absItemMock.ExpectCall("Configure");
            
            item.Configure();
        }

        [SetUp]
        public void Init() {
            MockManager.Init();
        }

        [TearDown]
        public void Dispose() {
            MockManager.Verify();
            MockManager.ClearAll();
        }
    }
}



Thank you,

Ian Davis
asked by traffic (1.2k points)

3 Answers

0 votes
Hi Ian,
This is a bug :twisted:,
Thanks for reporting this, we will fix it and send you a patch offline.
answered by scott (32k points)
0 votes
I am glad to help.


Regards,

Ian
answered by traffic (1.2k points)
0 votes
Hi Ian.

A patch was created and sent offline.
Thanks for your help. 8)
answered by ohad (35.4k points)
...