} // toString();

        // @Override
        public bool equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj == this)
            {
                return(true);
            }
            if (obj is Schema)
            {
                Schema        other = (Schema)obj;
                EqualsBuilder eb    = new EqualsBuilder();
                eb.append(getName(), other.getName());
                eb.append(getQuote(), other.getQuote());
                if (eb.isEquals())
                {
                    try
                    {
                        int tableCount1 = getTableCount();
                        int tableCount2 = other.getTableCount();
                        eb.append(tableCount1, tableCount2);
                    }
                    catch (Exception e)
                    {
                        // might occur when schemas are disconnected. Omit this
                        // check then.
                    }
                }
                return(eb.isEquals());
            }
            return(false);
        } // equals()
Exemple #2
0
        public virtual bool SameValueAs(PermissionCatalog other)
        {
            var builder = new EqualsBuilder();

            builder.Append(this.Permissions, other.Permissions);
            return(builder.IsEquals());
        }
 public void Equals_DifferentObjectsDifferentProperties_False()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.WithProp1(ONE).Build();
     var foo2 = fooBuilder.WithProp1(TWO).Build();
     AssertFalse(equalsBuilder, foo1, foo2);
 }
Exemple #4
0
        public void ShouldCalculateCorrectlyArrayComparison(int[] firstArg, int[] secondArg, bool result)
        {
            var response = new EqualsBuilder().
                           Append(firstArg, secondArg).
                           IsEquals();

            result.Should().Be(response);
        }
Exemple #5
0
 public override bool Equals(object obj)
 {
     if (obj.GetType() != this.GetType())
     {
         return(false);
     }
     return(EqualsBuilder.ReflectionEquals(this, obj));
 }
 public void Equals_DifferentObjectsSamePropertiesWithNullObject_True()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.Build();
     var foo2 = fooBuilder.Build();
     AssertTrue(equalsBuilder, foo1, foo2);
 }
Exemple #7
0
 public override bool Equals(object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     return(EqualsBuilder.ReflectionEquals(obj, this));
 }
Exemple #8
0
        public virtual bool SameValueAs(Permission other)
        {
            var builder = new EqualsBuilder();

            builder.Append(this.MethodName, other.MethodName);
            builder.Append(this.Actions, other.Actions);
            return(builder.IsEquals());
        }
 public void Equals_DifferentObjectsSamePropertiesTwoParamsObjectTyped_True()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     object foo1 = fooBuilder.Build();
     object foo2 = fooBuilder.Build();
     Assert.IsTrue(equalsBuilder.Equals(foo1, foo2));
     Assert.IsTrue(equalsBuilder.Equals(foo2, foo1));
 }
        public void ToStringAppendNonProperty()
        {
            // setup
            var dictionaryContainerA = new MethodDictionaryContainer();
            var dictionaryContainerB = new MethodDictionaryContainer();
            var equalsBuilder        = new EqualsBuilder <MethodDictionaryContainer>(dictionaryContainerA, dictionaryContainerB);

            // test
            equalsBuilder.Append <string>(x => x.TestMethod());
        }
Exemple #11
0
        public virtual bool SameValueAs(EmployeeJobPosition other)
        {
            var builder = new EqualsBuilder();

            builder.Append(this.JobPositionId, other.JobPositionId);
            builder.Append(this.FromDate.Date, other.FromDate.Date);
            builder.Append(this.ToDate.Date, other.ToDate.Date);

            return(builder.IsEquals());
        }
Exemple #12
0
        public virtual bool SameValueAs(EmployeeUnitCustomFieldValue other)
        {
            var builder = new EqualsBuilder();

            builder.Append(this.UnitCustomFieldId, other.UnitCustomFieldId);
            builder.Append(this.UnitCustomFieldValue, other.UnitCustomFieldValue);


            return(builder.IsEquals());
        }
Exemple #13
0
        public bool SameValueAs(UnitUnitIndex other)
        {
            var builder = new EqualsBuilder();

            builder.Append(UnitIndexId, other.UnitIndexId);
            builder.Append(ShowforTopLevel, other.ShowforTopLevel);
            builder.Append(ShowforSameLevel, other.ShowforSameLevel);
            builder.Append(showforLowLevel, other.showforLowLevel);
            return(builder.IsEquals());
        }
Exemple #14
0
        public virtual bool SameValueAs(UnitEmployee other)
        {
            var builder = new EqualsBuilder();

            builder.Append(this.EmployeeId, other.EmployeeId);
            builder.Append(this.Unit, other.Unit);
            builder.Append(this.FromDate.Date, other.FromDate.Date);
            builder.Append(this.ToDate.Date, other.ToDate.Date);
            //builder.Append(this, other.UnitIndexId);
            return(builder.IsEquals());
        }
        public void ReflectionEquals_should_return_false_When_two_objects_are_different()
        {
            //Arrange
            var vehicle1 = new Vehicle("11-D-214", "BMW S6", "1212");
            var vehicle2 = new Vehicle("11-D-214", "BMW S6", "1313");

            //Act
            var equalityResult = EqualsBuilder.ReflectionEquals(vehicle1, vehicle2);

            //Assert
            equalityResult.Should().BeFalse();
        }
        public void ReflectionEquals_should_return_true_When_two_objects_are_same()
        {
            //Arrange
            var person1 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));
            var person2 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));

            //Act
            var equalityResult = EqualsBuilder.ReflectionEquals(person1, person2);

            //Assert
            equalityResult.Should().Be(true);
        }
Exemple #17
0
        public void Test__Equals_False()
        {
            // Arrange
            var c1 = _fixture.Create <ParentModel>();
            var c2 = _fixture.Create <ParentModel>();

            // Act
            var result = new EqualsBuilder().BuildFunc <ParentModel>()(c1, c2);

            // Assert
            Assert.False(result);
        }
Exemple #18
0
        public void Test__Equals_True()
        {
            // Arrange
            var c1 = _fixture.Create <ParentModel>();
            var c2 = _fixture.Build <ParentModel>().FromSeed(_ => c1).Create();

            // Act
            var result = new EqualsBuilder().BuildFunc <ParentModel>()(c1, c2);

            // Assert
            Assert.True(result);
        }
Exemple #19
0
        //CP: TODO: Move these methods up to the CodeImpl class.
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        ///
        public override bool Equals(Object that)
        {
            if (!type.IsInstanceOfType(that))
            {
                return(false);
            }

            EqualsBuilder equalsBuilder = new EqualsBuilder();

            equalsBuilder.Append(this.CodeValue, ((Code)that).CodeValue);
            equalsBuilder.Append(this.CodeSystem, ((Code)that)
                                 .CodeSystem);

            return(equalsBuilder.IsEquals());
        }
        public void testReflectionEquals()
        {
            TestObject o1 = new TestObject(4);
            TestObject o2 = new TestObject(5);

            Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o1));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, o2));
            o2.setA(4);
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o2));

            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, this));

            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, null));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, o2));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object)null, (Object)null));
        }
 public void testReflectionHierarchyEquals()
 {
     testReflectionHierarchyEquals(false);
     testReflectionHierarchyEquals(true);
     // Transients
     Assert.IsTrue(EqualsBuilder.ReflectionEquals(new TestTTLeafObject(1, 2, 3, 4),
                                                  new TestTTLeafObject(1, 2, 3, 4), true));
     Assert.IsTrue(EqualsBuilder.ReflectionEquals(new TestTTLeafObject(1, 2, 3, 4),
                                                  new TestTTLeafObject(1, 2, 3, 4), false));
     Assert.IsTrue(
         !EqualsBuilder.ReflectionEquals(new TestTTLeafObject(1, 0, 0, 4), new TestTTLeafObject(1, 2, 3, 4), true));
     Assert.IsTrue(
         !EqualsBuilder.ReflectionEquals(new TestTTLeafObject(1, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 0), true));
     Assert.IsTrue(
         !EqualsBuilder.ReflectionEquals(new TestTTLeafObject(0, 2, 3, 4), new TestTTLeafObject(1, 2, 3, 4), true));
 }
        /**
         * Equivalence relationship tests inspired by "Effective Java":
         * <ul>
         * <li>reflection</li>
         * <li>symmetry</li>
         * <li>transitive</li>
         * <li>consistency</li>
         * <li>non-null reference</li>
         * </ul>
         * @param to a TestObject
         * @param toBis a TestObject, equal to to and toTer
         * @param toTer Left hand side, equal to to and toBis
         * @param to2 a different TestObject
         * @param oToChange a TestObject that will be changed
         */

        public void testReflectionEqualsEquivalenceRelationship(
            TestObject to,
            TestObject toBis,
            TestObject toTer,
            TestObject to2,
            TestObject oToChange,
            bool testTransients)
        {
            // reflection test
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, to, testTransients));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to2, to2, testTransients));

            // symmetry test
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, toBis, testTransients) &&
                          EqualsBuilder.ReflectionEquals(toBis, to, testTransients));

            // transitive test
            Assert.IsTrue(
                EqualsBuilder.ReflectionEquals(to, toBis, testTransients) &&
                EqualsBuilder.ReflectionEquals(toBis, toTer, testTransients) &&
                EqualsBuilder.ReflectionEquals(to, toTer, testTransients));

            // consistency test
            oToChange.setA(to.getA());
            if (oToChange is TestSubObject)
            {
                ((TestSubObject)oToChange).setB(((TestSubObject)to).getB());
            }
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients));
            oToChange.setA(to.getA() + 1);
            if (oToChange is TestSubObject)
            {
                ((TestSubObject)oToChange).setB(((TestSubObject)to).getB() + 1);
            }
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients));

            // non-null reference test
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to, null, testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to2, null, testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to, testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to2, testTransients));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object)null, (Object)null, testTransients));
        }
        public void IsEquals_should_return_true_When_two_objects_are_same()
        {
            //Arrange
            var person1 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));
            var person2 = new Person(1, "Hadi", "Ahmadi", new DateTime(1991, 1, 7));

            //Act
            var equalityResult = new EqualsBuilder()
                                 .Append(person1.Id, person2.Id)
                                 .Append(person1.Firstname, person2.Firstname)
                                 .Append(person1.Lastname, person2.Lastname)
                                 .Append(person1.BirthDate, person2.BirthDate)
                                 .Append(person1.Fullname, person2.Fullname)
                                 .IsEquals();

            //Assert
            equalityResult.Should().BeTrue();
        }
 // @Override
 public bool equals(Object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (obj == this)
     {
         return(true);
     }
     if (this.GetType() == obj.GetType())
     {
         DataSetTableModel that = (DataSetTableModel)obj;
         EqualsBuilder     eb   = new EqualsBuilder();
         eb.append(_materializedRows, that._materializedRows);
         eb.append(_selectItems, that._selectItems);
         return(eb.isEquals());
     }
     return(false);
 }
Exemple #25
0
 public bool IsEqualTo(Object obj0)
 {
     if (obj0 == null)
     {
         return(false);
     }
     else if (!(obj0   is  Code))
     {
         return(false);
     }
     else
     {
         Code          that    = (Code)obj0;
         EqualsBuilder builder = new EqualsBuilder();
         builder.Append(this.code, that.CodeValue);
         builder.Append(this.codeSystem, that.CodeSystem);
         builder.Append(this.nullFlavor, null);
         return(builder.IsEquals());
     }
 }
Exemple #26
0
        public bool equalsIgnoreAlias(SelectItem that, bool exactColumnCompare)
        {
            if (that == null)
            {
                return(false);
            }
            if (that == this)
            {
                return(true);
            }

            EqualsBuilder eb = new EqualsBuilder();

            if (exactColumnCompare)
            {
                eb.append(this._column == that._column);
                eb.append(this._fromItem, that._fromItem);
            }
            else
            {
                eb.append(this._column, that._column);
            }
            eb.append(this._function, that._function);
            eb.append(this._functionApproximationAllowed, that._functionApproximationAllowed);
            eb.append(this._expression, that._expression);
            if (_subQuerySelectItem != null)
            {
                eb.append(_subQuerySelectItem.equalsIgnoreAlias(that._subQuerySelectItem));
            }
            else
            {
                if (that._subQuerySelectItem != null)
                {
                    eb.append(false);
                }
            }
            return(eb.isEquals());
        } // equalsIgnoreAlias()
Exemple #27
0
        public override bool Equals(object obj) {
            App other = obj as App;
            if (other == null) {
                return false;
            }

            EqualsBuilder builder = new EqualsBuilder();
            builder.Append(Id, other.Id);
            builder.Append(Description, other.Description);
            builder.Append(ReleaseNotes, other.ReleaseNotes);
            builder.Append(CensoredName, other.CensoredName);
            builder.Append(ContentRating, other.ContentRating);
            builder.Append(ContentAdvisoryRating, other.ContentAdvisoryRating);
            builder.Append(AverageUserRating, other.AverageUserRating);
            builder.Append(UserRatingCount, other.UserRatingCount);
            builder.Append(Seller, other.Seller);
            builder.Append(Brief, other.Brief);
            builder.AppendSequence(Languages, other.Languages);
            builder.AppendSequence(Categories, other.Categories);
            builder.AppendSequence(ScreenshotUrls, other.ScreenshotUrls);
            builder.AppendSequence(IPadScreenshotUrls, other.IPadScreenshotUrls);
            return builder.AreEqual;
        }
 public void Equals_DifferentObjectsSamePropertiesOnlyOnePropertyChecked_True()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().With(m => m.Prop1).Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     var foo2 = fooBuilder.Build();
     AssertTrue(equalsBuilder, foo1, foo2);
 }
Exemple #29
0
 public override bool Equals(object obj)
 {
     return(EqualsBuilder.ReflectionEquals(this, obj));
 }
Exemple #30
0
 public override bool Equals(object that)
 {
     return(EqualsBuilder.reflectionEquals(typeof(Handling), this, that));
 }
 /// <summary>
 /// Static constructor
 /// </summary>
 static EqualityComparerBase()
 {
     EqualsFunc   = new EqualsBuilder().BuildFunc <T>();
     HashCodeFunc = new HashCodeBuilder().BuildFunc <T>();
 }
 public void Equals_UncompiledBuilder_Exception()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     var foo2 = fooBuilder.Build();
     equalsBuilder.Equals(foo1, foo2);
 }
 public void Equals_OneNullParameter_False()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     AssertFalse(equalsBuilder, fooBuilder.Build(), null);
 }
 public void Equals_SameObjects_True()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var foo = FooBuilder.AFoo().WithFullDummyData().Build();
     Assert.IsTrue(equalsBuilder.Equals(foo, foo));
 }
 public void Equals_WrongTypeForOneParam_False()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     Assert.IsFalse(equalsBuilder.Equals(foo1, String.Empty));
     Assert.IsFalse(equalsBuilder.Equals(String.Empty, foo1));
 }
Exemple #36
0
    /// <summary>
    ///     This method uses reflection to determine if the two Object
    ///     are equal.
    ///     It uses AccessibleObject.setAccessible to gain access to private
    ///     fields. This means that it will throw a security exception if run under
    ///     a security manager, if the permissions are not set up correctly. It is also
    ///     not as efficient as testing explicitly.
    ///     If the testTransients parameter is set to true, transient
    ///     members will be tested, otherwise they are ignored, as they are likely
    ///     derived fields, and not part of the value of the Object.
    ///     Static fields will not be included. Superclass fields will be appended
    ///     up to and including the specified superclass. A null superclass is treated
    ///     as java.lang.Object.
    /// </summary>
    /// <param name="lhs">this object</param>
    /// <param name="rhs">the other object</param>
    /// <param name="testTransients">whether to include transient fields</param>
    /// <param name="reflectUpToClass">the superclass to reflect up to (inclusive), may be null</param>
    /// <returns>true if the two Objects have tested equals.</returns>
    public static bool ReflectionEquals(object lhs, object rhs, bool testTransients, Type reflectUpToClass)
    {
        if (lhs == rhs)
        {
            return(true);
        }
        if (lhs == null || rhs == null)
        {
            return(false);
        }
        // Find the leaf class since there may be transients in the leaf
        // class or in classes between the leaf and root.
        // If we are not testing transients or a subclass has no ivars,
        // then a subclass can test equals to a superclass.
        var  lhsClass = lhs.GetType();
        var  rhsClass = rhs.GetType();
        Type testClass;

        if (lhsClass.IsInstanceOfType(rhs))
        {
            testClass = lhsClass;
            if (!rhsClass.IsInstanceOfType(lhs))
            {
                // rhsClass is a subclass of lhsClass
                testClass = rhsClass;
            }
        }
        else if (rhsClass.IsInstanceOfType(lhs))
        {
            testClass = rhsClass;
            if (!lhsClass.IsInstanceOfType(rhs))
            {
                // lhsClass is a subclass of rhsClass
                testClass = lhsClass;
            }
        }
        else
        {
            // The two classes are not related.
            return(false);
        }

        var equalsBuilder = new EqualsBuilder();

        try
        {
            ReflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients);
            while (testClass.BaseType != null && testClass != reflectUpToClass)
            {
                testClass = testClass.BaseType;
                ReflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients);
            }
        }
        catch (ArgumentException e)
        {
            // In this case, we tried to test a subclass vs. a superclass and
            // the subclass has ivars or the ivars are transient and
            // we are testing transients.
            // If a subclass has ivars that we are trying to test them, we get an
            // exception and we know that the objects are not equal.
            return(false);
        }

        return(equalsBuilder.IsEquals());
    }
Exemple #37
0
    /// <summary>
    ///     Appends the fields and values defined by the given object of the given Class.
    /// </summary>
    /// <param name="builder">the builder to Append to</param>
    /// <param name="clazz">the class to Append details of</param>
    /// <param name="lhs">the left hand object</param>
    /// <param name="rhs">the right hand object</param>
    /// <param name="useTransients">whether to test transient fields</param>
    private static void ReflectionAppend(
        object lhs,
        object rhs,
        Type clazz,
        EqualsBuilder builder,
        bool useTransients)
    {
        /*
         * In Java version of this ReflectionAppend, we have to call
         * AccessibleObject.setAccessible() right after class.GetFields() to
         * make non-public fields accessible. In C#, it is easier to do. We simply
         * add BindingFlags.NonPublic, which makes non-public fields accessible
         * (subject to security manager restrictions, of course).
         */
        var fields = clazz.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
                                     BindingFlags.DeclaredOnly);

        for (var i = 0; i < fields.Length && builder.isEqual; i++)
        {
            var f = fields[i];
            if (f.Name.IndexOf('$') == -1 &&
                (useTransients || !isTransient(f)) &&
                !f.IsStatic)
            {
                try
                {
                    builder.Append(f.GetValue(lhs), f.GetValue(rhs));
                }

                /*
                 * According to FieldInfo's documentation, getValue() can throw the
                 * following exceptions: TargetException, NotSupportedException,
                 * FieldAccessException and ArgumentException.
                 *
                 * TargetException is thrown if the field is non-static and obj is
                 * a null reference. In our case, the field is non-static (because of
                 * BindingFlags.Instance) but obj should never be null because of
                 * null checks in the calling method (i.e. reflectionEquals()).
                 * I guess we can just throw an unexpected exception.
                 *
                 * NotSupportedException is thrown if the field is marked Literal, but
                 * the field does not have one of the accepted literal types. Literal
                 * means that the field's value is a compile-time (static or early
                 * bound) constant. I think this exception can be just eaten because
                 * constants should always be equal in lhs and rhs and default value
                 * of isEqual is true.
                 *
                 * FieldAccessException is thrown if the caller does not have
                 * permission to access this field. If this code is fully trusted
                 * (not sure how to verify this), access restrictions are ignored.
                 * This means that private fields are accessible. If this code is not
                 * fully trusted, it can still access private fields if this code
                 * has been granted ReflectedPermission with the
                 * ReflectionPermisionFlag.RestrictedMemberAccess flag and if the
                 * grant set of the non-public members is restricted to the caller's
                 * grant set, or subset thereof. Whew, that's a mouthful to say!
                 * I guess it's best just to let FieldAccessException bubble up
                 * to callers so that user can grant permissions, if desired.
                 *
                 * Finally, ArgumentException is thrown if the method is neither
                 * declared nor inherited by the class of obj. This could happen
                 * if lhs is a subclass of rhs (or vice-versa) and the field is
                 * declared in the subclass. In Java, Field.get() would throw
                 * IllegalArgumentException in this case. In Java version of
                 * reflectionAppend(), IllegalArgumentException
                 * bubbles up to reflectionEquals(), where it is dealt with.
                 * It seems logical that use the same technique in the C#
                 * version. That is, we allow ArgumentException to bubble up
                 * to ReflectionEquals() and deal with it there.
                 */
                catch (TargetException te)
                {
                    throw new Exception("Unexpected TargetException", te);
                }
            }
 private static void AssertFalse(EqualsBuilder<Foo> equalsBuilder, Foo foo1, Foo foo2)
 {
     Assert.IsFalse(equalsBuilder.Equals(foo1, foo2));
     Assert.IsFalse(equalsBuilder.Equals(foo2, foo1));
 }
        public void testReflectionHierarchyEquals(bool testTransients)
        {
            TestObject         to1     = new TestObject(4);
            TestObject         to1Bis  = new TestObject(4);
            TestObject         to1Ter  = new TestObject(4);
            TestObject         to2     = new TestObject(5);
            TestEmptySubObject teso    = new TestEmptySubObject(4);
            TestTSubObject     ttso    = new TestTSubObject(4, 1);
            TestTTSubObject    tttso   = new TestTTSubObject(4, 1, 2);
            TestTTLeafObject   ttlo    = new TestTTLeafObject(4, 1, 2, 3);
            TestSubObject      tso1    = new TestSubObject(1, 4);
            TestSubObject      tso1bis = new TestSubObject(1, 4);
            TestSubObject      tso1ter = new TestSubObject(1, 4);
            TestSubObject      tso2    = new TestSubObject(2, 5);

            testReflectionEqualsEquivalenceRelationship(to1, to1Bis, to1Ter, to2, new TestObject(), testTransients);
            testReflectionEqualsEquivalenceRelationship(tso1, tso1bis, tso1ter, tso2, new TestSubObject(),
                                                        testTransients);

            // More sanity checks:

            // same values
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(ttlo, ttlo, testTransients));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(new TestSubObject(1, 10), new TestSubObject(1, 10),
                                                         testTransients));
            // same super values, diff sub values
            Assert.IsTrue(
                !EqualsBuilder.ReflectionEquals(new TestSubObject(1, 10), new TestSubObject(1, 11), testTransients));
            Assert.IsTrue(
                !EqualsBuilder.ReflectionEquals(new TestSubObject(1, 11), new TestSubObject(1, 10), testTransients));
            // diff super values, same sub values
            Assert.IsTrue(
                !EqualsBuilder.ReflectionEquals(new TestSubObject(0, 10), new TestSubObject(1, 10), testTransients));
            Assert.IsTrue(
                !EqualsBuilder.ReflectionEquals(new TestSubObject(1, 10), new TestSubObject(0, 10), testTransients));

            // mix super and sub types: equals
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to1, teso, testTransients));
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(teso, to1, testTransients));

            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to1, ttso, false));
            // Force testTransients = false for this assert
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(ttso, to1, false));
            // Force testTransients = false for this assert

            Assert.IsTrue(EqualsBuilder.ReflectionEquals(to1, tttso, false));
            // Force testTransients = false for this assert
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(tttso, to1, false));
            // Force testTransients = false for this assert

            Assert.IsTrue(EqualsBuilder.ReflectionEquals(ttso, tttso, false));
            // Force testTransients = false for this assert
            Assert.IsTrue(EqualsBuilder.ReflectionEquals(tttso, ttso, false));
            // Force testTransients = false for this assert

            // mix super and sub types: NOT equals
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestObject(0), new TestEmptySubObject(1), testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestEmptySubObject(1), new TestObject(0), testTransients));

            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestObject(0), new TestTSubObject(1, 1), testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestTSubObject(1, 1), new TestObject(0), testTransients));

            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestObject(1), new TestSubObject(0, 10), testTransients));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(new TestSubObject(0, 10), new TestObject(1), testTransients));

            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to1, ttlo));
            Assert.IsTrue(!EqualsBuilder.ReflectionEquals(tso1, this));
        }
 public void Equals_DifferentObjectsDifferentPropertyWhichWillNotChecked_True()
 {
     var equalsBuilder = new EqualsBuilder<Foo>().With(m => m.Prop2).Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.WithProp1(ONE).Build();
     var foo2 = fooBuilder.WithProp1(TWO).Build();
     AssertTrue(equalsBuilder, foo1, foo2);
 }
 public override bool Equals(object obj)
 {
     return(obj != null && (obj.GetType() == this.GetType() && EqualsBuilder.ReflectionEquals(this, obj)));
 }
Exemple #42
0
        public override bool Equals(object obj) {
            AppBrief other = obj as AppBrief;
            if (other == null) {
                return false;
            }

            // 不需要计算LastUpdate
            EqualsBuilder builder = new EqualsBuilder();
            builder.Append(Id, other.Id);
            builder.Append(Name, other.Name);
            builder.Append(Version, other.Version);
            builder.Append(ReleaseDate, other.ReleaseDate);
            builder.Append(Price, other.Price);
            builder.Append(Currency, other.Currency);
            builder.Append(FileSize, other.FileSize);
            builder.Append(ViewUrl, other.ViewUrl);
            builder.Append(PrimaryCategory, other.PrimaryCategory);
            builder.Append(Developer, other.Developer);
            builder.Append(AverageUserRatingForCurrentVersion, other.AverageUserRatingForCurrentVersion);
            builder.Append(UserRatingCountForCurrentVersion, other.UserRatingCountForCurrentVersion);
            builder.Append(DeviceType, other.DeviceType);
            builder.Append(LanguagePriority, other.LanguagePriority);
            builder.AppendSequence(Features, other.Features);
            builder.AppendSequence(SupportedDevices, other.SupportedDevices);
            return builder.AreEqual;
        }