
Md.Hasanuzzaman
Top achievements
Rank 1
Md.Hasanuzzaman
asked on 25 Feb 2014, 03:57 PM
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);
}
}
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);
}
}
5 Answers, 1 is accepted
0
Accepted
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
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
0

Md.Hasanuzzaman
Top achievements
Rank 1
answered on 28 Feb 2014, 03:42 PM
Thanks
0

andrew
Top achievements
Rank 1
answered on 28 Feb 2020, 08:04 AM
Sorry to revive an old thread, trying to test some very similar code. Has there been a fix since for this. using ignore instance as a work around but that is not ideal.
0
Hi Andrew,
We are working with limited resources because of the national holidays in Bulgaria and will need some more time to look into the case. We will get back to you as soon as we have more information regarding your case.
Thank you for your understanding.
Regards,
Dinko
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Hello Andrew,
JustMock is still having this limitation, as you mentioned the desired behavior can be achieved using future mocking, see below:
public class UnitTest1
{
[Fact]
public void TestUsingPartialMocking()
{
var foo = new Class1();
Mock.Arrange(() => (foo as Class2).Method1()).IgnoreInstance().OccursOnce();
Mock.Arrange(() => foo.Method1()).CallOriginal().OccursOnce();
foo.Method1();
Mock.Assert(foo);
Mock.Assert((foo as Class2));
Assert.True(foo.IsCall);
}
[Fact]
public void TestUsingMockWithCallOriginalBehavior()
{
var foo = Mock.Create<Class1>(Behavior.CallOriginal);
Mock.Arrange(() => (foo as Class2).Method1()).IgnoreInstance().OccursOnce();
Mock.Arrange(() => foo.Method1()).CallOriginal().OccursOnce();
foo.Method1();
Mock.Assert(foo);
Mock.Assert((foo as Class2));
Assert.True(foo.IsCall);
}
}
I hope that this information answers your questions.
Regards,
Ivo
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items