예제 #1
0
        public void GetHashCode_WhenTwoDifferentInstancesAreCreated_ThenInstanceHashCodesAreNotEqual()
        {
            // arrange
            GPSBuilder builder = GPSBuilder.Create()
                                 .WithAltitude(100)
                                 .WithLatitude(123.3m)
                                 .WithLongitude(180.11m);

            GPSBuilder builder1 = GPSBuilder.Create()
                                  .WithAltitude(1030)
                                  .WithLatitude(1233.3m)
                                  .WithLongitude(180.131m);

            GPS instance0 = builder.Build();
            GPS instance1 = builder1.Build();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.False);
        }
예제 #2
0
        public void Clone_WhenInstanceCloned_ThenInstancesHashCodesAreEqual()
        {
            // arrange
            GPSBuilder builder = GPSBuilder.Create()
                                 .WithAltitude(100)
                                 .WithLatitude(123.3m)
                                 .WithLongitude(180.11m);

            GPS instance0 = builder.Build();

            object instance1 = instance0.Clone();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(instance1, Is.InstanceOf <GPS>());
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.True);
        }
예제 #3
0
        public void GetHashCode_WhenInstanceIsDeseraializeAndSerializedBack_ThenInstancesHashCodesAreEqual()
        {
            // arrange
            GPSBuilder builder = GPSBuilder.Create()
                                 .WithAltitude(100)
                                 .WithLatitude(123.3m)
                                 .WithLongitude(180.11m);

            GPS instance0 = builder.Build();

            string serializedText = instance0.Serialize();

            GPS instance1 = serializedText.Deserialize <GPS>();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.True);
        }