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
Mocking ToolStrip, and instantiate it will cause InvalidCastException.

Here's the production code:
    public class ToolStripWrapper
    {
        public ToolStrip mNeuStrip
        { get; private set; }
        public ToolStripWrapper(ToolStrip menuStrip)
        {
            mNeuStrip = menuStrip;
        }
    }


Here's the test code:
        [Test, Isolated]
        public  void  ToolStripTest()
        {
            ToolStripWrapper toolStrip = new ToolStripWrapper(Isolate.Fake.Instance<ToolStrip>(Members.ReturnRecursiveFakes));
            ToolStrip ts = new ToolStrip();
        }


Here's the exception trace:
failed: System.InvalidCastException : Unable to cast object of type 'System.EventHandler' to type 'System.Windows.Forms.LayoutEventHandler'.
   at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
   at System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)
   at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
   at System.Windows.Forms.Control.PerformLayout()
   at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
   at System.Windows.Forms.ToolStrip..ctor()

________
Fourth-generation Mustang
asked by nsoonhui (59.1k points)

3 Answers

0 votes
This is also quite an urgent case for me.. thanks
________
Comparison of Toyota hybrids specifications
answered by nsoonhui (59.1k points)
0 votes
Hi Soon Hui,

The bug reproduces nicely and we have started to investigate it.
In the meantime I'd like to offer you a workaround that might help:

It seems the issue happens due to a bug in the recursive fakes so instead of using RecursiveFakes use Members.MustSpecifyReturnValues:

ToolStripWrapper toolStrip = new ToolStripWrapper(Isolate.Fake.Instance<ToolStrip>(Members.MustSpecifyReturnValues));


Please let me know if this workaround is good for your needs (until we fix this bug and release a patch)
answered by dhelper (11.9k points)
0 votes
Hi,

Actually this is not my original problem; I got to this problem because some other bigger tests were failing and this was the simplest related bug I could come up with to show to you guys.

So I afraid the workaround won't be of much help, but thanks anyway 8)
________
vaporizer store
answered by nsoonhui (59.1k points)
...