Ejemplo n.º 1
0
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var timeStamp = DateTime.UtcNow;
            var object1 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName + "A", Timestamp = timeStamp });
            var object2 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName + "B", Timestamp = timeStamp });

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

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
Ejemplo n.º 2
0
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            int numberOfItems = 10000;
            var items = TestUtilities.GetSystemInformationObjects(numberOfItems);
            var hashCodes = new Dictionary<int, SystemInformationQueueItem>();

            for (var i = 0; i < numberOfItems; i++)
            {
                // Act
                var object1 = new SystemInformationQueueItem(items[i]);

                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.IsFalse(hashCodes.ContainsKey(generatedHashCode));
                hashCodes.Add(generatedHashCode, object1);
            }
        }
Ejemplo n.º 3
0
        public void GetHashCode_TwoIdenticalObjects_WithDifferentEnqueueCountValues_HashCodesAreEqual()
        {
            // Arrange
            var timeStamp = DateTime.UtcNow;
            var object1 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName, Timestamp = timeStamp })
                {
                    EnqueuCount = 1
                };

            var object2 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName, Timestamp = timeStamp })
                {
                    EnqueuCount = 3
                };

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_TwoIdenticalObjects_WithDifferentEnqueueCountValues_HashCodesAreEqual()
        {
            // Arrange
            var timeStamp = DateTime.UtcNow;
            var object1 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName, Timestamp = timeStamp })
                {
                    EnqueuCount = 1
                };

            var object2 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName, Timestamp = timeStamp })
                {
                    EnqueuCount = 3
                };

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var timeStamp = DateTime.UtcNow;
            var object1 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName + "A", Timestamp = timeStamp });
            var object2 = new SystemInformationQueueItem(new SystemInformation { MachineName = Environment.MachineName + "B", Timestamp = timeStamp });

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

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            int numberOfItems = 10000;
            var items = TestUtilities.GetSystemInformationObjects(numberOfItems);
            var hashCodes = new Dictionary<int, SystemInformationQueueItem>();

            for (var i = 0; i < numberOfItems; i++)
            {
                // Act
                var object1 = new SystemInformationQueueItem(items[i]);

                int generatedHashCode = object1.GetHashCode();

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