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
Hi

please explain to me why the the code bellow fails at 2nd assertion
var searchAlwaysEnableController = Isolate.Fake.Instance<LookUpListSearchAlwaysEnableController>(Members.CallOriginal);

            Isolate.SwapNextInstance<LookUpListSearchAlwaysEnableController>().With(searchAlwaysEnableController);


            Assert.IsNotNull(searchAlwaysEnableController.Active);
            Assert.IsNotNull(new LookUpListSearchAlwaysEnableController().Active);
asked by (28.8k points)

3 Answers

0 votes
Hi Tolisss,

We couldn't recreate this behavior locally. Can you post the class under test or the implementation of the Active property here?

Thanks,
Doron
Typemock support
answered by (16.5k points)
0 votes
Hi Doron

1st i m complaining long time now that i do not receive mails from the post that i m subscribed could u please check my account again. it is very important to me. please do some tests/checks on that

2nd see this code
[Test]
        [VerifyMocks]
        [ClearMocks]
        public void Test()
        {
            var searchAlwaysEnableController = Isolate.Fake.Instance<testClass>(Members.CallOriginal);

            Isolate.SwapNextInstance<testClass>().With(searchAlwaysEnableController);


            Assert.IsNotNull(searchAlwaysEnableController.Active);
            Assert.IsNotNull(new testClass().Active); 


        }
    public class testClass
    {
        private BoolList activeList;

        protected internal testClass()
        {
            activeList = new BoolList(false);
        }

        [Browsable(false)]
        public BoolList Active
        {
            get { return activeList; }
        }

    }
    public class BoolList 
    {
        public static implicit operator bool(BoolList b)
        {
            return b.ResultValue;
        }
        public static bool operator ==(BoolList a, bool b)
        {
            return a.Equals(b);
        }
        public static bool operator !=(BoolList a, bool b)
        {
            return !a.Equals(b);
        }
        public static bool operator !(BoolList a)
        {
            return !a.resultValue;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            if (obj is bool)
            {
                return ((bool)obj) == resultValue;
            }
            return base.Equals(obj);
        }
        private bool oldResultValue;
        private bool resultValue;
        private bool emptyListValue;
        private int lockCount;
        private LightDictionary<string, bool> list = new LightDictionary<string, bool>();
        private BoolListOperatorType operatorType = BoolListOperatorType.And;
        protected void OnResultValueChanged(bool oldResultValue, bool resultValue)
        {
            if (ResultValueChanged != null)
            {
                ResultValueChanged(this, new BoolValueChangedEventArgs(oldResultValue, resultValue));
            }
        }
        public BoolList(bool emptyListValue, BoolListOperatorType operatorType)
        {
            this.emptyListValue = emptyListValue;
            this.resultValue = emptyListValue;
            this.operatorType = operatorType;
        }
        public BoolList(bool emptyListValue) : this(emptyListValue, BoolListOperatorType.And) { }
        public BoolList() : this(true, BoolListOperatorType.And) { }
        public bool ResultValue
        {
            get
            {
                return resultValue;
            }
        }
        public bool this[string key]
        {
            get
            {
                return list[key];
            }
            set
            {
                BeginUpdate();
                try
                {
                    list[key] = value;
                }
                finally
                {
                    EndUpdate();
                }
            }
        }
        public void Clear()
        {
            BeginUpdate();
            try
            {
                list.Clear();
            }
            finally
            {
                EndUpdate();
            }
        }
        public void RemoveItem(string key)
        {
            BeginUpdate();
            try
            {
                list.Remove(key);
            }
            finally
            {
                EndUpdate();
            }
        }
        public void SetItemValue(string key, bool value)
        {
            this[key] = value;
        }
        public IEnumerable<string&
answered by (28.8k points)
0 votes
Hi Tolisss,

First off, I apologize for the inconvenience regarding your forum auto notification; I will have our IT resolve this.

Second, the code you posted helped me recreate the issue. What I am seeing that there is a bug when using Swap.NextInstance() in conjunction with a CallOriginal fake; the problem is that the requirement of creating the fake object with its original constructor (rather than fake out the c'tor) is not passed to the swapped object.

I will work on getting a solution out to you as soon as possible; I will get back to you by email when we can send you a patch.

Thanks,
Doron
answered by (16.5k points)
...