public override bool Equals(object obj)
        {
            //1- Guard against null
            if (obj == null)
            {
                return(false);
            }

            //2 - Check reference equality
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            //3 - Check type
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            //4 - Casting
            PersonOverride _localP = (PersonOverride)obj;

            //5 - Custom equality behavior
            return(FirstName == _localP.FirstName &&
                   LastName == _localP.LastName);
        }
Пример #2
0
        public void LINQSingleSuccess()
        {
            people.Add(_globalPerson);

            PersonOverride _localPerson = new PersonOverride {
                FirstName = "Enrico", LastName = "Tirotta"
            };
            PersonOverride query = people.Single(p => p.Equals(_localPerson));

            Assert.NotNull(query);
        }
Пример #3
0
        public void LINQAnySuccess()
        {
            people.Add(_globalPerson);

            PersonOverride _localPerson = new PersonOverride {
                FirstName = "Enrico", LastName = "Tirotta"
            };
            //bool check = people.Any(p => p == _psOne); == FAILS << no override
            bool check = people.Any(p => p.Equals(_localPerson));

            Assert.True(check);
        }
Пример #4
0
        public void LINQDistinctSuccess()
        {
            people.Add(_globalPerson);

            PersonOverride _localPerson = new PersonOverride {
                FirstName = "Enrico", LastName = "Tirotta"
            };

            people.Add(_localPerson);

            int numberDistinctPeople = people.Distinct().Count();

            Assert.Equal(1, numberDistinctPeople);
        }
        public bool Equals(PersonOverride p)
        {
            if (p == null)
            {
                return(false);
            }

            //Same object
            if (ReferenceEquals(this, p))
            {
                return(true);
            }

            return(FirstName == p.FirstName && LastName == p.LastName);
        }