示例#1
0
        private int BuscaVíasConParámetrosDeRutaInválidos(Vía laVía)
        {
            int númeroDeProblemasDetectados = 0;

            // Excluye la vía si tiene el Atributo "NoParámetrosDeRutaEstándar".
            if (laVía.TieneAtributo(AtributoNoParámetrosDeRutaEstándar))
            {
                return(númeroDeProblemasDetectados);
            }

            IList <string> alertas = new List <string>();

            #region Valida el límite de velocidad.
            // El límite de velocidad debe ser el esperado.
            Tipo?tipo = laVía.Tipo;
            if (tipo != null)
            {
                if (RestriccionesDeParámetrosDeRuta.LímitesDeVelocidad.ContainsKey((Tipo)tipo))
                {
                    LímiteDeVelocidad límiteDeVelocidad         = laVía.CampoParámetrosDeRuta.LímiteDeVelocidad;
                    LímiteDeVelocidad límiteDeVelocidadEsperado = RestriccionesDeParámetrosDeRuta.LímitesDeVelocidad[(Tipo)tipo];
                    if (límiteDeVelocidad != límiteDeVelocidadEsperado)
                    {
                        alertas.Add(string.Format("A102: Límite de Velocidad debería ser {0}, pero es {1}.", límiteDeVelocidadEsperado, límiteDeVelocidad));
                    }
                }
            }
            #endregion

            #region Valida la clase de ruta.
            // La clase de ruta debe ser la esperado.
            if (tipo != null)
            {
                if (RestriccionesDeParámetrosDeRuta.ClasesDeRuta.ContainsKey((Tipo)tipo))
                {
                    ClaseDeRuta claseDeRuta         = laVía.CampoParámetrosDeRuta.ClaseDeRuta;
                    ClaseDeRuta claseDeRutaEsperada = RestriccionesDeParámetrosDeRuta.ClasesDeRuta[(Tipo)tipo];
                    if (claseDeRuta != claseDeRutaEsperada)
                    {
                        alertas.Add(string.Format("A103: Clase de Ruta debería ser {0}, pero es {1}.", claseDeRutaEsperada, claseDeRuta));
                    }
                }
            }
            #endregion

            if (alertas.Count > 0)
            {
                ++númeroDeProblemasDetectados;
                misAlertas.Add(laVía, alertas);
            }

            return(númeroDeProblemasDetectados);
        }
        public void PruebaToString()
        {
            #region Caso 1: Indice en rango válido.
            {
                // Preparación.
                int índice = 3;
                LímiteDeVelocidad objectoEnPrueba   = new LímiteDeVelocidad(índice);
                string            resultadoEsperado = "(3) 60 km/h";

                // Llama al método en prueba.
                string resultado = objectoEnPrueba.ToString();

                // Prueba resultado.
                Assert.That(resultado, Is.EqualTo(resultadoEsperado), "Resultado");
            }
            #endregion
        }
        public void PruebaConstructor()
        {
            #region Caso 1: Indice en rango válido.
            {
                // Preparación.
                int índice = 3;

                // Llama al constructor en prueba.
                LímiteDeVelocidad objectoEnPrueba = new LímiteDeVelocidad(índice);

                // Prueba Propiedades.
                Assert.AreEqual(índice, objectoEnPrueba.Indice, "Indice");
            }
            #endregion

            #region Caso 2: Indice fuera de rango.
            {
                // Preparación.
                int  índiceFueraDeRango = 40;
                bool lanzóExcepción     = false;
                ArgumentOutOfRangeException excepciónEsperada = new ArgumentOutOfRangeException(
                    "El índice del límite de velocidad debe estar entre 0 y menor o igual a 7, pero es: 40");

                // Llama al constructor en prueba.
                try
                {
                    LímiteDeVelocidad objectoEnPrueba = new LímiteDeVelocidad(índiceFueraDeRango);
                }
                catch (Exception e)
                {
                    // Prueba las propiedades de la excepción.
                    Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
                    Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

                    lanzóExcepción = true;
                }

                Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
            }
            #endregion
        }
            protected override void ProcesaLínea(string laLínea)
            {
                // Elimina espacios en blanco.
                string línea = laLínea.Trim();

                // Saltarse lineas en blanco y comentarios.
                bool laLíneaEstaEnBlanco = (línea == string.Empty);
                bool laLíneaEsComentario = línea.StartsWith("//");

                if (!laLíneaEstaEnBlanco & !laLíneaEsComentario)
                {
                    // Separa las letras.
                    string[] partes = línea.Split(',');

                    // Verifica que tenemos a menos 3 partes.
                    if (partes.Length < 3)
                    {
                        throw new ArgumentException("No se encontraron 3 partes separadas por coma en la linea: " + línea);
                    }

                    // Lee las tres partes.
                    Tipo tipo = new Tipo(partes[0]);
                    LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(Convert.ToInt32(partes[1]));
                    ClaseDeRuta       claseDeRuta       = new ClaseDeRuta(Convert.ToInt32(partes[2]));

                    // Asegura que el tipo es válido.
                    if (!TiposDeVías.Tipos.Contains(tipo))
                    {
                        throw new ArgumentException("El tipo de vía no es válido: " + tipo);
                    }

                    // Llena los diccionarios.
                    misLímitesDeVelocidad.Add(tipo, límiteDeVelocidad);
                    misClasesDeRuta.Add(tipo, claseDeRuta);
                }
            }
        public void PruebaConstructorConString()
        {
            #region Caso 1: Indice en rango válido.
            {
                // Preparación.
                LímiteDeVelocidad límiteDeVelocidad        = new LímiteDeVelocidad(2);
                ClaseDeRuta       claseDeRuta              = new ClaseDeRuta(3);
                string            parámetrosDeRuta         = "2,3,0,1,0,0,0,0,0,0,0,1";
                bool[]            otrosParámetrosEsperados = new bool[] { false, true, false, false, false, false, false, false, false, true };

                // Llama al constructor en prueba.
                CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parámetrosDeRuta);

                // Prueba Propiedades.
                Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
                Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
                Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
                Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetrosEsperados), "OtrosParámetros");
            }
            #endregion

            #region Caso 2: Parametros de Tuta con muy pocos elementos.
            {
                // Preparación.
                string            parametrosDeRutaInválidos = "2";
                bool              lanzóExcepción            = false;
                ArgumentException excepciónEsperada         = new ArgumentException(
                    "Los parámetros de rutas deben tener 12 elementos separados por coma, pero es: 2");

                // Llama al constructor en prueba.
                try
                {
                    CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
                }
                catch (Exception e)
                {
                    // Prueba las propiedades de la excepción.
                    Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
                    Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

                    lanzóExcepción = true;
                }

                Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
            }
            #endregion

            #region Caso 3: Otros Parámetros con valores diferente de 0 ó 1.
            {
                // Preparación.
                string            parametrosDeRutaInválidos = "2,3,0,5,0,0,0,0,0,0,0,1";
                bool              lanzóExcepción            = false;
                ArgumentException excepciónEsperada         = new ArgumentException(
                    "El números de los parámetros de ruta para el tercer elemento en adelante tiene que ser 0 ó 1:" +
                    " 2,3,0,5,0,0,0,0,0,0,0,1\r\nParameter name: elTextoDeParámetrosDeRuta");

                // Llama al constructor en prueba.
                try
                {
                    CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
                }
                catch (Exception e)
                {
                    // Prueba las propiedades de la excepción.
                    Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
                    Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

                    lanzóExcepción = true;
                }

                Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
            }
            #endregion
        }
        public void PruebaConstructorConLímiteDeVelocidadClaseDeRutaBoolArray()
        {
            #region Caso 1: Caso normal.
            {
                // Preparación.
                LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
                ClaseDeRuta       claseDeRuta       = new ClaseDeRuta(3);
                bool[]            otrosParámetros   = new bool[] { true, false, true, false, false, false, true, true, false, true };

                // Llama al constructor en prueba.
                CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);

                // Prueba Propiedades.
                Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
                Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
                Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
                Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetros), "OtrosParámetros");
            }
            #endregion

            #region Caso 2: Muy pocos elementos en Otros Parámetros.
            {
                // Preparación.
                LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
                ClaseDeRuta       claseDeRuta       = new ClaseDeRuta(3);
                bool[]            otrosParámetros   = new bool[] { true, true, false, false, false, true, true, false, true };
                bool lanzóExcepción = false;
                ArgumentException excepciónEsperada = new ArgumentException(
                    "El números de Otrós Parámetros debe ser 10 pero es 9\r\nParameter name: losOtrosParámetros");

                // Llama al constructor en prueba.
                try
                {
                    CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
                }
                catch (Exception e)
                {
                    // Prueba las propiedades de la excepción.
                    Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
                    Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

                    lanzóExcepción = true;
                }

                Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
            }
            #endregion

            #region Caso 3: Muchos elementos en Otros Parámetros.
            {
                // Preparación.
                LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
                ClaseDeRuta       claseDeRuta       = new ClaseDeRuta(3);
                bool[]            otrosParámetros   = new bool[] { true, true, false, true, false, false, false, true, true, false, true };
                bool lanzóExcepción = false;
                ArgumentException excepciónEsperada = new ArgumentException(
                    "El números de Otrós Parámetros debe ser 10 pero es 11\r\nParameter name: losOtrosParámetros");

                // Llama al constructor en prueba.
                try
                {
                    CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
                }
                catch (Exception e)
                {
                    // Prueba las propiedades de la excepción.
                    Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
                    Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

                    lanzóExcepción = true;
                }

                Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
            }
            #endregion
        }
        public void PruebaConstructor()
        {
            #region Caso 1: Indice en rango válido.
              {
            // Preparación.
            int índice = 3;

            // Llama al constructor en prueba.
            LímiteDeVelocidad objectoEnPrueba = new LímiteDeVelocidad(índice);

            // Prueba Propiedades.
            Assert.AreEqual(índice, objectoEnPrueba.Indice, "Indice");
              }
              #endregion

              #region Caso 2: Indice fuera de rango.
              {
            // Preparación.
            int índiceFueraDeRango = 40;
            bool lanzóExcepción = false;
            ArgumentOutOfRangeException excepciónEsperada = new ArgumentOutOfRangeException(
              "El índice del límite de velocidad debe estar entre 0 y menor o igual a 7, pero es: 40");

            // Llama al constructor en prueba.
            try
            {
              LímiteDeVelocidad objectoEnPrueba = new LímiteDeVelocidad(índiceFueraDeRango);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion
        }
        public void PruebaToString()
        {
            #region Caso 1: Indice en rango válido.
              {
            // Preparación.
            int índice = 3;
            LímiteDeVelocidad objectoEnPrueba = new LímiteDeVelocidad(índice);
            string resultadoEsperado = "(3) 60 km/h";

            // Llama al método en prueba.
            string resultado = objectoEnPrueba.ToString();

            // Prueba resultado.
            Assert.That(resultado, Is.EqualTo(resultadoEsperado), "Resultado");
              }
              #endregion
        }
        public void PruebaConstructorConLímiteDeVelocidadClaseDeRutaBoolArray()
        {
            #region Caso 1: Caso normal.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, false, true, false, false, false, true, true, false, true };

            // Llama al constructor en prueba.
            CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);

            // Prueba Propiedades.
            Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
            Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
            Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
            Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetros), "OtrosParámetros");
              }
              #endregion

              #region Caso 2: Muy pocos elementos en Otros Parámetros.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, true, false, false, false, true, true, false, true };
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de Otrós Parámetros debe ser 10 pero es 9\r\nParameter name: losOtrosParámetros");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion

              #region Caso 3: Muchos elementos en Otros Parámetros.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta(3);
            bool[] otrosParámetros = new bool[] { true, true, false, true, false, false, false, true, true, false, true };
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de Otrós Parámetros debe ser 10 pero es 11\r\nParameter name: losOtrosParámetros");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(límiteDeVelocidad, claseDeRuta, otrosParámetros);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion
        }
        public void PruebaConstructorConString()
        {
            #region Caso 1: Indice en rango válido.
              {
            // Preparación.
            LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad (2);
            ClaseDeRuta claseDeRuta = new ClaseDeRuta (3);
            string parámetrosDeRuta = "2,3,0,1,0,0,0,0,0,0,0,1";
            bool[] otrosParámetrosEsperados = new bool[] { false, true, false, false, false, false, false, false, false, true };

            // Llama al constructor en prueba.
            CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parámetrosDeRuta);

            // Prueba Propiedades.
            Assert.That(objectoEnPrueba.Identificador, Is.EqualTo(CampoParámetrosDeRuta.IdentificadorDeParámetrosDeRuta), "Identificador");
            Assert.That(objectoEnPrueba.ClaseDeRuta, Is.EqualTo(claseDeRuta), "ClaseDeRuta");
            Assert.That(objectoEnPrueba.LímiteDeVelocidad, Is.EqualTo(límiteDeVelocidad), "LímiteDeVelocidad");
            Assert.That(objectoEnPrueba.OtrosParámetros, Is.EqualTo(otrosParámetrosEsperados), "OtrosParámetros");
              }
              #endregion

              #region Caso 2: Parametros de Tuta con muy pocos elementos.
              {
            // Preparación.
            string parametrosDeRutaInválidos = "2";
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "Los parámetros de rutas deben tener 12 elementos separados por coma, pero es: 2");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion

              #region Caso 3: Otros Parámetros con valores diferente de 0 ó 1.
              {
            // Preparación.
            string parametrosDeRutaInválidos = "2,3,0,5,0,0,0,0,0,0,0,1";
            bool lanzóExcepción = false;
            ArgumentException excepciónEsperada = new ArgumentException(
              "El números de los parámetros de ruta para el tercer elemento en adelante tiene que ser 0 ó 1:" +
              " 2,3,0,5,0,0,0,0,0,0,0,1\r\nParameter name: elTextoDeParámetrosDeRuta");

            // Llama al constructor en prueba.
            try
            {
              CampoParámetrosDeRuta objectoEnPrueba = new CampoParámetrosDeRuta(parametrosDeRutaInválidos);
            }
            catch (Exception e)
            {
              // Prueba las propiedades de la excepción.
              Assert.That(e.GetType(), Is.EqualTo(excepciónEsperada.GetType()), "Tipo de Excepción");
              Assert.That(e.Message, Is.EqualTo(excepciónEsperada.Message), "Excepción.Message");

              lanzóExcepción = true;
            }

            Assert.That(lanzóExcepción, Is.True, "No se lanzó la excepción.");
              }
              #endregion
        }
            protected override void ProcesaLínea(string laLínea)
            {
                // Elimina espacios en blanco.
                string línea = laLínea.Trim();

                // Saltarse lineas en blanco y comentarios.
                bool laLíneaEstaEnBlanco = (línea == string.Empty);
                bool laLíneaEsComentario = línea.StartsWith("//");
                if (!laLíneaEstaEnBlanco & !laLíneaEsComentario)
                {
                  // Separa las letras.
                  string[] partes = línea.Split(',');

                  // Verifica que tenemos a menos 3 partes.
                  if (partes.Length < 3)
                  {
                throw new ArgumentException("No se encontraron 3 partes separadas por coma en la linea: " + línea);
                  }

                  // Lee las tres partes.
                  Tipo tipo = new Tipo(partes[0]);
                  LímiteDeVelocidad límiteDeVelocidad = new LímiteDeVelocidad(Convert.ToInt32(partes[1]));
                  ClaseDeRuta claseDeRuta = new ClaseDeRuta(Convert.ToInt32(partes[2]));

                  // Asegura que el tipo es válido.
                  if (!TiposDeVías.Tipos.Contains(tipo))
                  {
                throw new ArgumentException("El tipo de vía no es válido: " + tipo);
                  }

                  // Llena los diccionarios.
                  misLímitesDeVelocidad.Add(tipo, límiteDeVelocidad);
                  misClasesDeRuta.Add(tipo, claseDeRuta);
                }
            }