コード例 #1
0
            public void ReturnsReferenceInfoForNonExistingId()
            {
                var obj1 = new object();
                var obj2 = new object();
                var obj3 = new object();

                var referenceManager = new ReferenceManager();

                referenceManager.GetInfo(obj1);
                referenceManager.GetInfo(obj2);
                referenceManager.GetInfo(obj3);

                Assert.IsNotNull(referenceManager.GetInfoById(3));
            }
コード例 #2
0
            public void RegistersManualIds()
            {
                var obj1 = new object();
                var obj2 = new object();
                var obj3 = new object();
                var obj4 = new object();

                var referenceManager = new ReferenceManager();

                referenceManager.RegisterManually(2, obj4);

                referenceManager.GetInfo(obj1);
                referenceManager.GetInfo(obj2);
                referenceManager.GetInfo(obj3);

                var obj4ReferenceInfo = referenceManager.GetInfo(obj4);
                Assert.AreEqual(2, obj4ReferenceInfo.Id);

                var obj3ReferenceInfo = referenceManager.GetInfo(obj3);
                Assert.AreEqual(4, obj3ReferenceInfo.Id);
            }
コード例 #3
0
            public void ReturnsTrueForFirstUsageOnFirstUsage()
            {
                var referenceManager = new ReferenceManager();
                var referenceInfo = referenceManager.GetInfo(new object());

                Assert.IsTrue(referenceInfo.IsFirstUsage);
            }
コード例 #4
0
            public void ReturnsNullForNullInstance()
            {
                var referenceManager = new ReferenceManager();

                Assert.IsNull(referenceManager.GetInfo(null));
            }
コード例 #5
0
            public void ReturnsSameInfoForSameReference()
            {
                var obj1 = new object();
                var obj2 = new object();
                var obj3 = new object();

                var referenceManager = new ReferenceManager();
                referenceManager.GetInfo(obj1);
                referenceManager.GetInfo(obj2);
                referenceManager.GetInfo(obj3);

                var referenceInfo = referenceManager.GetInfo(obj2);

                Assert.AreEqual(2, referenceInfo.Id);
                Assert.IsTrue(ReferenceEquals(obj2, referenceInfo.Instance));
            }
コード例 #6
0
            public void ReturnsFalseForFirstUsageOnSecondUsage()
            {
                var referenceManager = new ReferenceManager();
                var obj = new object();

                referenceManager.GetInfo(obj);
                var referenceInfo = referenceManager.GetInfo(obj);

                Assert.IsFalse(referenceInfo.IsFirstUsage);
            }