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

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var object1 = new RESTServiceConfiguration { Hostaddress = "127.0.0.1", Hostname = "localhost", ResourcePath = "some/path" };
            var object2 = new RESTServiceConfiguration { Hostaddress = "127.0.0.1", Hostname = "localhost", ResourcePath = "some/path" };

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

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            var hostaddress = "127.0.0.1";
            var hostname = "localhost";
            var resourcePath = "some/path";
            var object1 = new RESTServiceConfiguration { Hostaddress = hostaddress, Hostname = hostname, ResourcePath = resourcePath };

            int expectedHashcode = object1.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                object1.Hostaddress = hostaddress;
                object1.Hostname = hostname;
                object1.ResourcePath = resourcePath;
                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var object1 = new RESTServiceConfiguration { Hostaddress = "127.0.0.1", Hostname = "localhost", ResourcePath = "some/path" };
            var object2 = new RESTServiceConfiguration { Hostaddress = "127.0.0.1", Hostname = "localhost", ResourcePath = "another/path" };

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

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

            for (var i = 0; i < 10000; i++)
            {
                // Act
                var object1 = new RESTServiceConfiguration { Hostaddress  = "127.0.0.1", Hostname = Guid.NewGuid().ToString(), ResourcePath = "api/" + Guid.NewGuid().ToString() };

                int generatedHashCode = object1.GetHashCode();

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