How to Arrange a base class method?

3 posts, 1 answers
  1. Md.Hasanuzzaman
    Md.Hasanuzzaman avatar
    31 posts
    Member since:
    Apr 2011

    Posted 25 Feb 2014 Link to this post

    I am trying Arrange a  base class method which is override in drive class but I can`t

    Here is my Code :

     public class Class1 : Class2
        {
            public bool Class1Call { get; set; }

            public override void Method1()
            {
                Class1Call = true;
               base.Method1();      //<<<<< want to ensure that base.Method1 ic call during Method1 call
            }
        }

        public class Class2
        {
            public bool IsCall { get; set; }

            public virtual void Method1()
            {
                IsCall = true;
            }
        }


        public class TestClass
        {
            [Fact]
            public void Class_1_Test()
            {
                var foo = Mock.Create<Class1>();
                Mock.Arrange(() => (foo as Class2).Method1()).CallOriginal().OccursOnce();
                Mock.Arrange(() => foo.Method1()).CallOriginal().OccursOnce();

                foo.Method1();

                Mock.Assert(foo);

                Assert.True(foo.IsCall);

            }
        } 
  2. Answer
    Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 27 Feb 2014 Link to this post

    Hi,

    Unfortunately, this is not possible in the current version of JustMock. It is impossible to arrange the base method of an overriden virtual method right now. I've logged an issue aboout this and it should be fixed in one of our upcoming releases. Please note, however, that intercepting base virtual methods (like Class1.Method1 in your example) will require the profiler to be enabled - it will not work with JustMock Lite.

    Unfortunately, I cannot provide you with a workaround. I suggest you test this specific behavior by means other than JustMock.

    Regards,
    Stefan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
  4. Md.Hasanuzzaman
    Md.Hasanuzzaman avatar
    31 posts
    Member since:
    Apr 2011

    Posted 28 Feb 2014 in reply to Stefan Link to this post

    Thanks
Back to Top