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
Following on the discussing on
this post, I found that the calloriginal setter property is not chainable. Here's the production code:
    public  class MyWrap
    {
        public Hulala baseAttach
        { get;  set; }
    }
    public abstract class Hulala

{
    public MyBase MBUnit
    { get;  set;}
}
    public  class HulalaDerived: Hulala
    {
        
    }
    public  class MyBase
    {
        public double FirstNumber
        { get; private set; }
        public MyBase()
        {
            FirstNumber = 10; }
    }


And here's the test code:
        [Test, Isolated]
        public void BaseTop()
        {
            MyWrap wrap = Isolate.Fake.Instance<MyWrap>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => wrap.baseAttach.MBUnit = null).CallOriginal();
            Isolate.WhenCalled(() => wrap.baseAttach.MBUnit).CallOriginal();
            wrap.baseAttach.MBUnit=new MyBase();
            Assert.IsNotNull(wrap.baseAttach.MBUnit);
            
        }

The test will fail because the wrap.baseAttach.MBUnit is a null.
________
Jaguar XJ13 specifications
asked by nsoonhui (59.1k points)

3 Answers

0 votes
Hi Soon

Indeed This is a bug. :evil:

Until it's fixed how about this workaround:
[Test]
public void BaseTop()
{
    MyWrap wrap = Isolate.Fake.Instance<MyWrap>(Members.ReturnRecursiveFakes);
    Isolate.WhenCalled(() => wrap.baseAttach).WillReturn(Isolate.Fake.Instance<Hulala>(Members.CallOriginal));
    wrap.baseAttach.MBUnit = new MyBase();
    Assert.IsNotNull(wrap.baseAttach.MBUnit);
}
answered by ohad (35.4k points)
0 votes
Hi Soon

Indeed This is a bug. :evil:

Until it's fixed how about this workaround:
[Test]
public void BaseTop()
{
    MyWrap wrap = Isolate.Fake.Instance<MyWrap>(Members.ReturnRecursiveFakes);
    Isolate.WhenCalled(() => wrap.baseAttach).WillReturn(Isolate.Fake.Instance<Hulala>(Members.CallOriginal));
    wrap.baseAttach.MBUnit = new MyBase();
    Assert.IsNotNull(wrap.baseAttach.MBUnit);
}


Hi,

I afraid that this is not going to be helpful because If I create a fake object for Hulala, then I can't set the value for MBUnit already.

To be more explicit, the following test is what I want to achieve, but I afraid it will still fail.
[Test] 
public void BaseTop() 
{ 
    MyWrap wrap = Isolate.Fake.Instance<MyWrap>(Members.ReturnRecursiveFakes); 
    Isolate.WhenCalled(() => wrap.baseAttach).WillReturn(Isolate.Fake.Instance<Hulala>(Members.CallOriginal));
    wrap.baseAttach.MBUnit = new MyBase(); 
    Assert.IsNotNull(wrap.baseAttach.MBUnit); 
   Assert.AreEqual(10, wrap.baseAttach.MBUnit.FirstNumber);
} 

________
free themes
answered by nsoonhui (59.1k points)
0 votes
This is indeed an interesting issue. let's take it offline and see how we can resolve it.
answered by dhelper (11.9k points)
...