public void GetHashCode_TwoIdenticalObjects_BothUninitialized_HashCodesAreEqual()
        {
            // Arrange
            var package1 = new SystemMemoryInformation();
            var package2 = new SystemMemoryInformation();

            // Act
            int hashCodeObject1 = package1.GetHashCode();
            int hashCodeObject2 = package2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var object1 = new SystemMemoryInformation { AvailableMemoryInGB = 8.0d, UsedMemoryInGB = 3.0d };
            var object2 = new SystemMemoryInformation { AvailableMemoryInGB = 8.0d, UsedMemoryInGB = 3.0d };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            var availableMemoryInGB = 8.0d;
            var usedMemoryInGB = 3.0d;
            var object1 = new SystemMemoryInformation { AvailableMemoryInGB = availableMemoryInGB, UsedMemoryInGB = usedMemoryInGB };

            int expectedHashcode = object1.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                object1.AvailableMemoryInGB = availableMemoryInGB;
                object1.UsedMemoryInGB = usedMemoryInGB;
                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var object1 = new SystemMemoryInformation { AvailableMemoryInGB = 8.0d, UsedMemoryInGB = 3.0d };
            var object2 = new SystemMemoryInformation { AvailableMemoryInGB = 16.0d, UsedMemoryInGB = 7.0d };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            var hashCodes = new Dictionary<int, SystemMemoryInformation>();

            for (var i = 0; i < 1000; i++)
            {
                // Act
                var object1 = new SystemMemoryInformation { AvailableMemoryInGB = i, UsedMemoryInGB = i / 2.0d };

                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.IsFalse(hashCodes.ContainsKey(generatedHashCode));
                hashCodes.Add(generatedHashCode, object1);
            }
        }