public void CheckAndRecord(ConstraintsViolations violations)
        {
            RecordedAssertions.DoesNotThrow(() =>
            {
                var equatableEquality = TypeOf <T> .EquatableEquality();
                if (equatableEquality.HasValue)
                {
                    foreach (var factory1 in _equalInstances)
                    {
                        foreach (var factory2 in _equalInstances)
                        {
                            RecordedAssertions.DoesNotThrow(() =>
                                                            RecordedAssertions.True((bool)equatableEquality.Value().Evaluate(factory1(), factory2()),
                                                                                    "a.Equals(T b) should return true for equal objects", violations),
                                                            "a.Equals(T b) should return true for equal objects", violations);
                            RecordedAssertions.DoesNotThrow(() =>
                                                            RecordedAssertions.True((bool)equatableEquality.Value().Evaluate(factory2(), factory1()),
                                                                                    "b.Equals<T>(a) should return true for equal objects", violations),
                                                            "b.Equals(T a) should return true for equal objects", violations);

                            RecordedAssertions.DoesNotThrow(() =>
                                                            RecordedAssertions.True(factory1().Equals(factory2()),
                                                                                    "a.Equals(object b) should return true for equal objects", violations),
                                                            "a.Equals(object b) should return true for equal objects", violations);
                            RecordedAssertions.DoesNotThrow(() =>
                                                            RecordedAssertions.True(factory2().Equals(factory1()),
                                                                                    "b.Equals(object a) should return true for equal objects", violations),
                                                            "b.Equals(object a) should return true for equal objects", violations);
                        }
                    }
                }
            }, "Should be able to create an object of type " + typeof(T), violations);
        }
Beispiel #2
0
        public void CheckAndRecord(ConstraintsViolations violations)
        {
            foreach (var factory1 in _equalInstances)
            {
                foreach (var factory2 in _otherInstances)
                {
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.False(factory1().Equals(factory2()),
                                                                             "a.Equals(object b) should return false if they are not equal", violations),
                                                    "a.Equals(object b) should return false if they are not equal", violations);
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.False(factory2().Equals(factory1()),
                                                                             "b.Equals(object a) should return false if they are not equal", violations),
                                                    "b.Equals(object a) should return false if they are not equal", violations);

                    var equatableEquals = TypeOf <T> .EquatableEquality();

                    if (equatableEquals.HasValue)
                    {
                        RecordedAssertions.DoesNotThrow(() =>
                                                        RecordedAssertions.False((bool)equatableEquals.Value().Evaluate(factory1(), factory2()),
                                                                                 "a.Equals(T b) should return false if they are not equal", violations),
                                                        "a.Equals(T b) should return false if they are not equal", violations);
                        RecordedAssertions.DoesNotThrow(() =>
                                                        RecordedAssertions.False((bool)equatableEquals.Value().Evaluate(factory2(), factory1()),
                                                                                 "b.Equals(T a) should return false if they are not equal", violations),
                                                        "b.Equals(T a) should return false if they are not equal", violations);
                    }
                }
            }
        }
        public void CheckAndRecord(ConstraintsViolations violations)
        {
            foreach (var factory in _equalInstances.Concat(_otherInstances))
            {
                RecordedAssertions.DoesNotThrow(() =>
                {
                    var instance1 = factory();

                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.True(instance1.Equals(instance1),
                                                                            "a.Equals(object a) should return true", violations),
                                                    "a.Equals(object a) should return true", violations);
                }, "Should be able to create an object of type " + typeof(T), violations);

                var equatableEquals = TypeOf <T> .EquatableEquality();

                if (equatableEquals.HasValue)
                {
                    var instance1 = factory();
                    RecordedAssertions.DoesNotThrow(() =>
                                                    RecordedAssertions.True((bool)equatableEquals.Value().Evaluate(instance1, instance1),
                                                                            "a.Equals(a) should return true", violations),
                                                    "a.Equals(a) should return true", violations);
                }
            }
        }