Ejemplo n.º 1
0
        public void Add_A_Handle_Only_Once()
        {
            // arrange
            var sut    = new DumpAppDomain();
            var handle = new DumpHandle();

            // act
            sut.AddHandle(handle);
            sut.AddHandle(handle);

            // assert
            sut.Handles.Should().HaveCount(1);
        }
Ejemplo n.º 2
0
        public void Exhibit_Entity_Equality()
        {
            // arrange
            var a = new DumpHandle()
            {
                Address = 0
            };
            var b = new DumpHandle()
            {
                Address = 0
            };
            var c = new DumpHandle()
            {
                Address = 1
            };

            // act
            // assert
            a.GetHashCode().Should().Be(b.GetHashCode());
            a.GetHashCode().Should().NotBe(c.GetHashCode());

            a.Equals(a).Should().BeTrue();
            a.Equals(b).Should().BeTrue();
            a.Equals(c).Should().BeFalse();
            a.Equals(null).Should().BeFalse();
            a.Equals("").Should().BeFalse();
            a.CompareTo(a).Should().Be(0);
            a.CompareTo(b).Should().Be(0);
            a.CompareTo(c).Should().Be(-1);
            a.CompareTo(null).Should().Be(1);
            a.Equals((object)a).Should().BeTrue();
            a.Equals((object)b).Should().BeTrue();
            a.Equals((object)c).Should().BeFalse();
            a.Equals((object)null).Should().BeFalse();
            a.CompareTo((object)a).Should().Be(0);
            a.CompareTo((object)b).Should().Be(0);
            a.CompareTo((object)c).Should().Be(-1);
            a.CompareTo((object)null).Should().Be(1);
            (a < b).Should().BeFalse();
            (a <= b).Should().BeTrue();
            (c > a).Should().BeTrue();
            (c >= a).Should().BeTrue();
            Action throws = () => a.CompareTo("");

            throws.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates the handles.
        /// </summary>
        public void CreateHandles()
        {
            Handles                      = new Dictionary <ulong, DumpHandle>();
            HandleToTypeMapping          = new Dictionary <ulong, DumpTypeKey>();
            HandleToDependentTypeMapping = new Dictionary <ulong, DumpTypeKey>();
            HandleToAppDomainMapping     = new Dictionary <ulong, ulong>();
            foreach (var handle in Runtime.EnumerateHandles())
            {
                var newHandle = new DumpHandle
                {
                    Address         = handle.Address,
                    HandleType      = handle.HandleType,
                    DependentTarget = handle.DependentTarget,
                    IsPinned        = handle.IsPinned,
                    IsStrong        = handle.IsStrong,
                    ObjectAddress   = handle.Object,
                    RefCount        = handle.RefCount
                };

                if (!Handles.ContainsKey(newHandle.Address))
                {
                    Handles.Add(newHandle.Address, newHandle);
                }

                if (!HandleToTypeMapping.ContainsKey(newHandle.Address))
                {
                    HandleToTypeMapping.Add(newHandle.Address, handle.Type.ToKeyType());
                }

                if (!HandleToAppDomainMapping.ContainsKey(newHandle.Address))
                {
                    HandleToAppDomainMapping.Add(newHandle.Address, handle.AppDomain.Address);
                }

                if (handle.DependentType != null && !HandleToDependentTypeMapping.ContainsKey(handle.Address))
                {
                    HandleToDependentTypeMapping.Add(handle.Address, handle.DependentType.ToKeyType());
                }
            }
        }