Exemplo n.º 1
0
        public void InsertarParte(IParteAuto parte)
        {
            if (NoCumpleRestricciones(parte))
            {
                throw new Exception("Esa parte esta restringida a una unica");
            }

            _partesAuto.Add(parte);
        }
Exemplo n.º 2
0
        private bool NoCumpleRestricciones(IParteAuto parte)
        {
            var esTanqueCombustible = parte.GetType() == typeof(TanqueCombustible);
            var esMotor             = parte.GetType() == typeof(Motor);

            var existeTanqueCombustible = _partesAuto.Any(x => x.GetType() == typeof(Motor) && esMotor);
            var existeMotor             = _partesAuto.Any(x => x.GetType() == typeof(Motor) && esMotor);

            return(existeMotor || existeTanqueCombustible);
        }