Exemple #1
0
        public void CheckAndRecord(ConstraintsViolations violations)
        {
            var instance1 = _activator.CreateInstanceAsValueObjectWithFreshParameters();
            var instance3 = _activator.CreateInstanceAsValueObjectWithPreviousParameters();

            for (var i = 0; i < _activator.GetConstructorParametersCount(); ++i)
            {
                if (ArgumentIsPartOfValueIdentity(i))
                {
                    var instance2 = _activator.CreateInstanceAsValueObjectWithModifiedParameter(i);
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.NotEqual(instance1.GetHashCode(), instance2.GetHashCode(),
                                                                                "b.GetHashCode() and b.GetHashCode() should return different values when both are created with different argument" + i, violations),
                                                    "b.GetHashCode() and b.GetHashCode() should return different values when both are created with different argument" + i, violations);
                }
            }

            RecordedAssertions.DoesNotThrow(() =>
                                            RecordedAssertions.Equal(instance1.GetHashCode(), instance3.GetHashCode(),
                                                                     "a.GetHashCode() and b.GetHashCode() should return same values when both are created with same arguments", violations),
                                            "a.GetHashCode() and b.GetHashCode() should return same values when both are created with same arguments", violations);
            RecordedAssertions.DoesNotThrow(() =>
                                            RecordedAssertions.Equal(instance1.GetHashCode(), instance3.GetHashCode(),
                                                                     "a.GetHashCode() and b.GetHashCode() should return same values when both are created with same arguments", violations),
                                            "a.GetHashCode() and b.GetHashCode() should return same values when both are created with same arguments", violations);
        }
Exemple #2
0
        public void CheckAndRecord(ConstraintsViolations violations)
        {
            foreach (var factory1 in _equalInstances)
            {
                foreach (var factory2 in _otherInstances)
                {
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.NotEqual(factory1().GetHashCode(), factory2().GetHashCode(),
                                                                                "b.GetHashCode() and b.GetHashCode() should return different values for not equal objects", violations),
                                                    "b.GetHashCode() and b.GetHashCode() should return different values for not equal objects", violations);
                }
            }

            foreach (var factory in _equalInstances.Concat(_otherInstances))
            {
                var instance = factory();
                RecordedAssertions.DoesNotThrow(() =>
                                                RecordedAssertions.Equal(instance.GetHashCode(), instance.GetHashCode(),
                                                                         "a.GetHashCode() should consistently return the same value", violations),
                                                "a.GetHashCode() should consistently return the same value", violations);
            }

            foreach (var factory1 in _equalInstances)
            {
                foreach (var factory2 in _equalInstances)
                {
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.Equal(factory1().GetHashCode(), factory2().GetHashCode(),
                                                                             "a.GetHashCode() and b.GetHashCode() should be equal for equal objects",
                                                                             violations),
                                                    "a.GetHashCode() and b.GetHashCode() should be equal for equal objects",
                                                    violations);
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.Equal(factory1().GetHashCode(), factory2().GetHashCode(),
                                                                             "a.GetHashCode() and b.GetHashCode() should be equal for equal objects",
                                                                             violations),
                                                    "a.GetHashCode() and b.GetHashCode() should be equal for equal objects",
                                                    violations);
                }
            }
        }