Пример #1
0
        public override bool Equals(object?obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }

            CookedFood rhs = obj as CookedFood;

            return(this._cookingMethod == rhs._cookingMethod);
        }
Пример #2
0
        public void it_checks_equality_for_inherited_reference_types()
        {
            // Arrange
            Food       apple        = new Food("apple", FoodGroup.Fruit);
            Food       apple1       = new Food("apple", FoodGroup.Fruit);
            CookedFood stewedApple  = new CookedFood("stewed", "apple", FoodGroup.Fruit);
            CookedFood bakedApple   = new CookedFood("baked", "apple", FoodGroup.Fruit);
            CookedFood stewedApple1 = new CookedFood("stewed", "apple", FoodGroup.Fruit);

            // Act
            bool areTwoApplesEqual = (apple == apple1);
            bool areTwoApplesEqualWithEqualsMethod = (apple.Equals(apple1));
            bool areAppleEqualStewedApple          = (apple.Equals(stewedApple));

            // Assert
            Assert.True(areTwoApplesEqual);
            Assert.True(areTwoApplesEqualWithEqualsMethod);

            Assert.False(areAppleEqualStewedApple);
        }