Ejemplo n.º 1
0
            public void UsesProvidedEqualityComparer()
            {
                var comparer = new ObjectEqualityComparer();

                Assert.That(2 + 2, Is.EqualTo(4).Using(comparer));
                Assert.That(comparer.Called, "Comparer was not called");
            }
Ejemplo n.º 2
0
        public void Teammate_to_GetTeammateResponse()
        {
            var subject  = ObjectFactory.Create <Teammate>() as Teammate;
            var comparer = new ObjectEqualityComparer();

            var result = mapper.Map <GetTeammateResponse>(subject);

            Assert.IsTrue(comparer.Equals(subject, result));
        }
Ejemplo n.º 3
0
        public void CreateTeammateRequest_to_Teammate()
        {
            var subject  = ObjectFactory.Create <CreateTeammateRequest>() as CreateTeammateRequest;
            var comparer = new ObjectEqualityComparer();

            var result = mapper.Map <Teammate>(subject);

            Assert.IsTrue(comparer.Equals(subject, result));
        }
Ejemplo n.º 4
0
        public void ObjectEqualityComparer_Equals_True()
        {
            ObjectEqualityComparer comparer = new ObjectEqualityComparer();

            var testClass = base.GetPointFeatureClass();
            var row       = testClass.Fetch(1);

            var equals = comparer.Equals(row, row);

            Assert.IsTrue(equals);
        }
Ejemplo n.º 5
0
        public bool Equals(DbaseFieldValue left, DbaseFieldValue right)
        {
            if (left == null && right == null)
            {
                return(true);
            }
            if (left == null || right == null)
            {
                return(false);
            }
            var leftInspector  = new ValueInspector();
            var rightInspector = new ValueInspector();

            left.Inspect(leftInspector);
            right.Inspect(rightInspector);
            var sameField = left.Field.Equals(right.Field);

            if (left.Field.Length.Equals(new DbaseFieldLength(15)) &&
                left.Field.DecimalCount.Equals(new DbaseDecimalCount(0)) &&
                right.Field.Length.Equals(new DbaseFieldLength(15)) &&
                right.Field.DecimalCount.Equals(new DbaseDecimalCount(0)) &&
                (
                    (
                        left.Field.FieldType == DbaseFieldType.Character
                        ||
                        left.Field.FieldType == DbaseFieldType.DateTime
                    )
                    &&
                    (
                        right.Field.FieldType == DbaseFieldType.Character
                        ||
                        right.Field.FieldType == DbaseFieldType.DateTime
                    )
                ) &&
                (
                    leftInspector.Value == null
                    ||
                    (leftInspector.Value is string leftString && leftString == "")
                ) &&
                (
                    rightInspector.Value == null
                    ||
                    (rightInspector.Value is string rightString && rightString == "")
                )
                )
            {
                return(sameField);
            }

            IEqualityComparer <object> comparer = new ObjectEqualityComparer(left.Field.DecimalCount);
            var sameValue = comparer.Equals(leftInspector.Value, rightInspector.Value);

            return(sameField && sameValue);
        }
        public static void Equals___Should_return_true___When_both_objects_are_the_same_object_reference()
        {
            // Arrange
            object item            = Some.Dummies <byte>().ToArray();
            var    systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual = systemUnderTest.Equals(item, item);

            // Assert
            actual.Should().BeTrue();
        }
        public static void Equals___Should_return_true___When_both_objects_are_null()
        {
            // Arrange
            object item1           = null;
            object item2           = null;
            var    systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual = systemUnderTest.Equals(item1, item2);

            // Assert
            actual.Should().BeTrue();
        }
Ejemplo n.º 8
0
        public void ObjectEqualityComparer_Equals_False()
        {
            ObjectEqualityComparer comparer = new ObjectEqualityComparer();

            var testClass = base.GetPointFeatureClass();
            var rows      = testClass.Fetch(1, 2);

            Assert.AreEqual(2, rows.Count);

            var equals = comparer.Equals(rows.First(), rows.Last());

            Assert.IsFalse(equals);
        }
        public static void Equals___Should_return_true___When_objects_runtime_types_are_object()
        {
            // Arrange
            var item1 = new object();
            var item2 = new object();

            var systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual = systemUnderTest.Equals(item1, item2);

            // Assert
            actual.Should().BeTrue();
        }
        public static TResult ComputeFormula <TResult, TParameter>
        (
            string formula
            , params Tuple <string, TParameter>[] parameters
        )
        {
            var dt       = new DataTable();
            var comparer = new ObjectEqualityComparer <Tuple <string, TParameter> >
                           (
                (x, y) =>
            {
                return(x.Item1 == y.Item1);
            }
                , (x) =>
            {
                return(x.Item1.GetHashCode());
            }
                           );
            var list = parameters.Distinct
                       (
                comparer
                       )
                       .ToList();

            list.ForEach
            (
                (x) =>
            {
                var dc = new DataColumn
                         (
                    x.Item1
                    , x.Item2.GetType()
                         );
                dt.Columns.Add(dc);
            }
            );
            dt.Columns.Add(new DataColumn("Microshaoft", typeof(TResult), formula));
            var dr = dt.NewRow();

            list.ForEach
            (
                (x) =>
            {
                dr[x.Item1] = x.Item2;
            }
            );
            dt.Rows.Add(dr);
            return((TResult)dr["Microshaoft"]);
        }
        public static void Equals___Should_return_false___When_objects_have_different_runtime_types()
        {
            // Arrange
            object item1 = Some.Dummies <byte>().ToArray();
            object item2 = new object();

            var systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual1 = systemUnderTest.Equals(item1, item2);
            var actual2 = systemUnderTest.Equals(item2, item1);

            // Assert
            actual1.Should().BeFalse();
            actual2.Should().BeFalse();
        }
        public static void Equals___Should_return_true___When_objects_are_not_equal_using_runtime_types_as_declared_type()
        {
            // Arrange
            var item1 = new List <string> {
                "abc", null, "def"
            };
            var item2 = new List <string> {
                "abc", null
            };

            var systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual = systemUnderTest.Equals(item1, item2);

            // Assert
            actual.Should().BeFalse();
        }
        public static void Equals___Should_return_false___When_one_object_is_null_and_the_other_is_not_null()
        {
            // Arrange
            object item1a = new Version();
            object item1b = null;

            object item2a = null;
            object item2b = new Version();

            var systemUnderTest = new ObjectEqualityComparer();

            // Act
            var actual1 = systemUnderTest.Equals(item1a, item1b);
            var actual2 = systemUnderTest.Equals(item2a, item2b);

            // Assert
            actual1.Should().BeFalse();
            actual2.Should().BeFalse();
        }
Ejemplo n.º 14
0
 public bool Equals(Dictionary <string, object> dict, bool ignoreCase)
 {
     return(this.Groups.Count == dict.Count &&
            this.Groups.Values.All(g => ObjectEqualityComparer.Equals(dict[g.Key], g.Value, ignoreCase)));
 }