Beispiel #1
0
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            var deviceName             = "C:";
            var freeDiscSpaceInPercent = 30.0d;
            var object1 = new SystemStorageDeviceInformation {
                DeviceName = deviceName, FreeDiscSpaceInPercent = freeDiscSpaceInPercent
            };

            int expectedHashcode = object1.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                object1.DeviceName             = deviceName;
                object1.FreeDiscSpaceInPercent = freeDiscSpaceInPercent;
                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
Beispiel #2
0
        public void GetHashCode_TwoIdenticalObjects_BothUninitialized_HashCodesAreEqual()
        {
            // Arrange
            var package1 = new SystemStorageDeviceInformation();
            var package2 = new SystemStorageDeviceInformation();

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Beispiel #3
0
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var object1 = new SystemStorageDeviceInformation {
                DeviceName = "C:", FreeDiscSpaceInPercent = 30.0d
            };
            var object2 = new SystemStorageDeviceInformation {
                DeviceName = "E:", FreeDiscSpaceInPercent = 10.0d
            };

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

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
Beispiel #4
0
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var object1 = new SystemStorageDeviceInformation {
                DeviceName = "C:", FreeDiscSpaceInPercent = 30.0d
            };
            var object2 = new SystemStorageDeviceInformation {
                DeviceName = "C:", FreeDiscSpaceInPercent = 30.0d
            };

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Beispiel #5
0
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            var hashCodes = new Dictionary <int, SystemStorageDeviceInformation>();

            for (var i = 0; i < 1000; i++)
            {
                // Act
                var object1 = new SystemStorageDeviceInformation {
                    DeviceName = i.ToString(), FreeDiscSpaceInPercent = i
                };

                int generatedHashCode = object1.GetHashCode();

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