/// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            if (_isFrozen)
            {
                return(_frozenHashCode);
            }

            // see Effective Java by Joshua Bloch
            int hash = 17;

            hash = 37 * hash + _chunkSize.GetHashCode();
            hash = 37 * hash + _root.GetHashCode();
            hash = 37 * hash + _updateMD5.GetHashCode();
            hash = 37 * hash + _verifyMD5.GetHashCode();
            hash = 37 * hash + _writeConcern.GetHashCode();
            return(hash);
        }
 public void Equals_should_return_true_if_all_fields_are_equal(int? w, int? wTimeoutSeconds, bool? fsync, bool? journal)
 {
     var wCount = w.HasValue ? (WriteConcern.WValue)w.Value : null;
     var wTimeout = wTimeoutSeconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeoutSeconds.Value) : null;
     var writeConcern1 = new WriteConcern(wCount, wTimeout, fsync, journal);
     var writeConcern2 = new WriteConcern(wCount, wTimeout, fsync, journal);
     writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeTrue();
     writeConcern1.Equals((object)writeConcern2).Should().BeTrue();
     writeConcern1.GetHashCode().Should().Be(writeConcern2.GetHashCode());
 }
 public void Equals_should_return_false_if_wTimeout_is_not_equal(int? wTimeout1Seconds, int? wTimeout2Seconds)
 {
     var wTimeout1 = wTimeout1Seconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeout1Seconds.Value) : null;
     var wTimeout2 = wTimeout2Seconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(wTimeout2Seconds.Value) : null;
     var writeConcern1 = new WriteConcern(null, wTimeout1, null, null);
     var writeConcern2 = new WriteConcern(null, wTimeout2, null, null);
     writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
     writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
     writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
 }
 public void Equals_should_return_false_if_w_is_not_equal(int? w1, int? w2)
 {
     var wCount1 = w1.HasValue ? (WriteConcern.WValue)w1.Value : null;
     var wCount2 = w2.HasValue ? (WriteConcern.WValue)w2.Value : null;
     var writeConcern1 = new WriteConcern(wCount1, null, null, null);
     var writeConcern2 = new WriteConcern(wCount2, null, null, null);
     writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
     writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
     writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
 }
 public void Equals_should_return_false_if_journal_is_not_equal(bool? journal1, bool? journal2)
 {
     var writeConcern1 = new WriteConcern(null, null, null, journal1);
     var writeConcern2 = new WriteConcern(null, null, null, journal2);
     writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
     writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
     writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
 }
 public void Equals_should_return_false_if_fsync_is_not_equal(bool? fsync1, bool? fsync2)
 {
     var writeConcern1 = new WriteConcern(null, null, fsync1, null);
     var writeConcern2 = new WriteConcern(null, null, fsync2, null);
     writeConcern1.Equals((WriteConcern)writeConcern2).Should().BeFalse();
     writeConcern1.Equals((object)writeConcern2).Should().BeFalse();
     writeConcern1.GetHashCode().Should().NotBe(writeConcern2.GetHashCode());
 }
        public void Equals_should_return_true_when_all_fields_are_equal()
        {
            var subject1 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);
            var subject2 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);

            var result1 = subject1.Equals(subject2);
            var result2 = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeTrue();
            result2.Should().BeTrue();
            hashCode1.Should().Be(hashCode2);
        }
        public void Equals_should_return_false_when_any_fields_are_not_equal(
            [Values("fsync", "journal", "w", "wTimeout")]
            string notEqualFieldName)
        {
            var subject1 = new WriteConcern(1, TimeSpan.FromSeconds(1), false, false);
            WriteConcern subject2;
            switch (notEqualFieldName)
            {
                case "fsync": subject2 = subject1.With(fsync: true); break;
                case "journal": subject2 = subject1.With(journal: true); break;
                case "w": subject2 = subject1.With(w: 2); break;
                case "wTimeout": subject2 = subject1.With(wTimeout: TimeSpan.FromSeconds(2)); break;
                default: throw new ArgumentException("notEqualFieldName");
            }

            var result1 = subject1.Equals(subject2);
            var result2 = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeFalse();
            result2.Should().BeFalse();
            hashCode1.Should().NotBe(hashCode2);
        }