예제 #1
0
        public void Test_Object_Is_Null_Throws()
        {
            //Arrange
            RevokeNotifierTestClass target = null;

            //Act & Assert
            Assert.Throws <NullReferenceException>(() => new EquatableWeakReference <RevokeNotifierTestClass>(target));
        }
        public bool Equals(RevokeNotifierTestClass other)
        {
            if (other == null)
            {
                return(false);
            }

            return(_hashcode == other._hashcode);
        }
예제 #3
0
        private RevokeContext CreateRevokeContextRooted(int hashcode = 1234)
        {
            var           target = new RevokeNotifierTestClass();
            RevokeContext res    = new RevokeContext(target,
                                                     (s) => Task.CompletedTask,
                                                     TaskScheduler.Current);

            _anchor.Add(target);
            return(res);
        }
예제 #4
0
        private RevokeContext CreateRevokeContextRooted(int hashcode = 1234)
        {
            var           target = new RevokeNotifierTestClass();
            RevokeContext res    = new RevokeContext(target,
                                                     RevokeContextConcurrentCollectionTests.RevokeKeySubstitute.Instance,
                                                     TaskScheduler.Current);

            _anchor.Add(target);
            return(res);
        }
예제 #5
0
        public void Test_Object_Is_Collected()
        {
            //Arrange
            var wr = CreateEquatableWeakReference(false);

            //Act
            RevokeNotifierTestClass.CallGC();

            //Assert
            Assert.Null(wr.Target);
        }
예제 #6
0
        public void GetHashCode_EquatableWeakReference_Equals_Target_HashCode()
        {
            // Arrange
            var target = new RevokeNotifierTestClass();
            var wr     = new EquatableWeakReference <RevokeNotifierTestClass>(target);

            // Act
            var result = wr.GetHashCode();

            // Assert
            Assert.AreEqual(result, target.GetHashCode());
        }
예제 #7
0
        public void Equals_EquatableWeakReference_Are_Reference_Equal()
        {
            // Arrange
            var target = new RevokeNotifierTestClass();
            var wr1    = new EquatableWeakReference <RevokeNotifierTestClass>(target);
            var wr2    = new EquatableWeakReference <RevokeNotifierTestClass>(target);

            // Act
            var result = wr1.Equals(wr2);

            // Assert
            Assert.True(result);
        }
예제 #8
0
        public void RemoveEntryMatchingObject_None_Existing_Object_Should_Fail()
        {
            // Arrange
            var    revokeContextConcurrentCollection = this.CreateRevokeContextConcurrentCollection();
            object obj = new RevokeNotifierTestClass();

            // Act
            var result = revokeContextConcurrentCollection.RemoveEntryMatchingObject(
                obj);

            // Assert
            Assert.False(result);
        }
예제 #9
0
        public void ObjectEqual_RevokeContext_Is_Equal_If_Revokee_Equal2()
        {
            // Arrange
            var revokee        = new RevokeNotifierTestClass();
            var revokeContext1 = CreateRevokeContext(revokee);

            // Act
            var result = revokeContext1.ObjectEqual(
                revokee);

            // Assert
            Assert.True(result);
        }
예제 #10
0
        public void Test_Object_Is_Not_Collected()
        {
            //Arrange
            var target = new RevokeNotifierTestClass();

            _anchor.Add(target);
            var wr = new EquatableWeakReference <RevokeNotifierTestClass>(target);

            //Act
            RevokeNotifierTestClass.CallGC();

            //Assert
            Assert.NotNull(wr.Target);
        }
예제 #11
0
        private EquatableWeakReference <RevokeNotifierTestClass> CreateEquatableWeakReference(bool collectObject = false)
        {
            EquatableWeakReference <RevokeNotifierTestClass> res = null;
            Action notRootByDebuger = () =>
            {
                res = new EquatableWeakReference <RevokeNotifierTestClass>(new RevokeNotifierTestClass());
            };

            notRootByDebuger();
            if (collectObject)
            {
                RevokeNotifierTestClass.CallGC();
            }
            return(res);
        }
예제 #12
0
        public void Equals_EquatableWeakReference_Are_Not_Equal_Even_If_HashCode_is_And_Target_collected()
        {
            // Arrange
            var wr     = CreateEquatableWeakReference(true);
            var target = new RevokeNotifierTestClass();
            var wr2    = new EquatableWeakReference <RevokeNotifierTestClass>(target);

            // Act
            var result1 = wr2.Equals(wr);

            // Assert
            Assert.Null(wr.Target);
            Assert.AreEqual(wr.GetHashCode(), wr2.GetHashCode());
            Assert.AreNotEqual(wr, wr2);
        }
예제 #13
0
        private RevokeContext CreateRevokeContext(int hashcode = 1234)
        {
            RevokeContext res = null;
            Action        notRootByDebuger = () =>
            {
                res = new RevokeContext(new RevokeNotifierTestClass(),
                                        (s) => Task.CompletedTask,
                                        TaskScheduler.Current);
            };

            notRootByDebuger();

            RevokeNotifierTestClass.CallGC();

            return(res);
        }
예제 #14
0
        private RevokeContext CreateRevokeContext(int hashcode = 1234)
        {
            RevokeContext res = null;
            Action        notRootByDebuger = () =>
            {
                res = new RevokeContext(new RevokeNotifierTestClass(),
                                        RevokeContextConcurrentCollectionTests.RevokeKeySubstitute.Instance,
                                        TaskScheduler.Current);
            };

            notRootByDebuger();

            RevokeNotifierTestClass.CallGC();

            return(res);
        }
예제 #15
0
        private RevokeContext CreateRevokeContext(RevokeNotifierTestClass revokee = null, bool collectObject = false)
        {
            RevokeContext res = null;
            Action        notRootByDebuger = () =>
            {
                res = new RevokeContext(revokee ?? new RevokeNotifierTestClass(),
                                        collectObject?new RevokeContextConcurrentCollectionTests.RevokeKeySubstitute():this.subRevokeKey,
                                        this.subTaskScheduler);
            };

            notRootByDebuger();

            if (collectObject)
            {
                RevokeNotifierTestClass.CallGC();
            }
            return(res);
        }
예제 #16
0
        private RevokeContext CreateRevokeContext(RevokeNotifierTestClass revokee = null, bool collectObject = false)
        {
            RevokeContext res = null;
            Action        notRootByDebuger = () =>
            {
                res = new RevokeContext(revokee ?? new RevokeNotifierTestClass(),
                                        this.subFunc,
                                        this.subTaskScheduler);
            };

            notRootByDebuger();

            if (collectObject)
            {
                RevokeNotifierTestClass.CallGC();
            }
            return(res);
        }