示例#1
0
        public void AddVotacion(Votacion votacion)
        {
            var votaciones = (List <Votacion>)HttpContext.Current.Cache["ips"];

            if (votaciones == null)
            {
                votaciones = new List <Votacion>();
                HttpContext.Current.Cache["ips"] = votaciones;
            }

            var fechaCampania  = new DateTime(2020, 02, 10);
            var votosFiltrados = votaciones.FindAll(f => f.Show == votacion.Show).FindAll(f => f.Fecha > fechaCampania).FindAll(f => f.Ip == votacion.Ip).ToList();

            if (votosFiltrados.Count < 3)
            {
                if (votosFiltrados.FindAll(f => f.Email == votacion.Email).Count == 0)
                {
                    Repository.AddVotacion(votacion);
                    votaciones.Add(votacion);
                    HttpContext.Current.Cache["ips"] = votaciones;
                }
                else
                {
                    throw new Exception("voto_ya_registrado_error");
                }
            }
            else
            {
                throw new Exception("voto_ya_registrado_error");
            }
        }
        public void Comprobar_Que_El_Evento_Se_Lanza_Por_Cada_Senador()
        {
            //ARRANGE
            Dictionary <string, Votacion.EVoto> diccionario;
            Votacion votacion;
            int      contador = 0;

            //INITIALIZE
            diccionario = new Dictionary <string, Votacion.EVoto>();
            diccionario.Add("s1", Votacion.EVoto.Afirmativo);
            diccionario.Add("s2", Votacion.EVoto.Negativo);
            diccionario.Add("s3", Votacion.EVoto.Abstencion);
            votacion = new Votacion("Ley123", diccionario);

            //ACT
            votacion.EventoVotoEfectuado += MiContador;
            votacion.Simular();

            void MiContador(string senador, EVoto voto)
            {
                contador++;
            }

            //ASSERT
            Assert.AreEqual(3, contador);
        }
        private void btnSimular_Click(object sender, EventArgs e)
        {
            if (this.flag || !this.hilo.IsAlive)
            {
                // Creo una nueva votación
                votacion = new Votacion(txtLeyNombre.Text, this.participantes);
                // Mostrar Quorum
                lblEsperando.Text = this.participantes.Count.ToString();

                // Reseteo de la votación
                foreach (PictureBox p in this.graficos)
                {
                    p.BackColor = Color.White;
                }
                lblAfirmativo.Text   = "0";
                lblNegativo.Text     = "0";
                lblAbstenciones.Text = "0";

                // EVENTO
                votacion.EventoVotoEfectuado += this.ManejadorVoto;
                // THREAD
                //Thread hiloAux = new Thread(votacion.Simular);
                this.hilo = new Thread(votacion.Simular);


                hilo.Start();
                if (this.flag)
                {
                    this.flag = false;
                }
            }
        }
示例#4
0
        public void TestMethod1()
        {
            Votacion votacion = new Votacion("Ley", new System.Collections.Generic.Dictionary <string, Votacion.EVoto>());
            SerializarXML <Votacion> serializarXML = new SerializarXML <Votacion>();

            serializarXML.Guardar("C:\\Windows\\Archivo.xml", votacion);
        }
示例#5
0
        public void TestErrorArchivoException()
        {
            Votacion votacion            = null;
            SerializarXml <Votacion> ser = new SerializarXml <Votacion>();

            ser.Guardar("Juancarlos.xml", votacion);
        }
示例#6
0
        public void TestSenadoresII()
        {
            //Arrange
            Dictionary <string, Votacion.EVoto> diccionarioPrueba = new Dictionary <string, Votacion.EVoto>();
            Votacion votacionPrueba;
            int      contador = 0;

            //Act
            diccionarioPrueba.Add("Senador1", Votacion.EVoto.Abstencion);
            diccionarioPrueba.Add("Senador2", Votacion.EVoto.Negativo);
            diccionarioPrueba.Add("Senador3", Votacion.EVoto.Afirmativo);
            diccionarioPrueba.Add("Senador4", Votacion.EVoto.Afirmativo);
            votacionPrueba = new Votacion("Ley 25.125", diccionarioPrueba);
            votacionPrueba.EventoVotoEfectuado += MetodoContador;

            votacionPrueba.Simular();

            void MetodoContador(string senador, Votacion.EVoto voto)
            {
                contador++;
            }

            //Assert
            Assert.AreEqual(4, contador);
        }
        private void btnSimular_Click(object sender, EventArgs e)
        {
            // Creo una nueva votación
            votacion = new Votacion(txtLeyNombre.Text, this.participantes);
            //Creo un Thread y le pongo el metodo como parametro
            Thread t = new Thread(votacion.Simular);

            // Mostrar Quorum
            lblEsperando.Text = this.participantes.Count.ToString();

            // Reseteo de la votación
            foreach (PictureBox p in this.graficos)
            {
                p.BackColor = Color.White;
            }
            lblAfirmativo.Text   = "0";
            lblNegativo.Text     = "0";
            lblAbstenciones.Text = "0";

            // EVENTO

            //Asocio el evento con el manejador
            votacion.EventoVotoEfectuado += ManejadorVoto;

            // THREAD
            t.Start();
        }
示例#8
0
        public void ExcepcionGuardar()
        {
            Votacion v = new Votacion();
            SerializadorXML <Votacion> ser = new SerializadorXML <Votacion>();

            ser.Guardar("", v);
        }
示例#9
0
        public void TestSerializacionDeVotacion()
        {
            // arrange
            SerializarBinaria archivar = new SerializarBinaria();
            Votacion          votacion = new Votacion();

            //act
            archivar.Guardar("", votacion);
        }
示例#10
0
        public void ValidarEventos()
        {
            Dictionary <string, Votacion.EVoto> participantes = new Dictionary <string, Votacion.EVoto>();

            participantes.Add("1", Votacion.EVoto.Afirmativo);
            participantes.Add("2", Votacion.EVoto.Negativo);

            Votacion votos = new Votacion("Ley X", participantes);
        }
        public void Guardar_Archivo_XML_En_Directorio_Inexistente()
        {
            //Arrange
            Votacion votacion = new Votacion("Ley123", new Dictionary <string, Votacion.EVoto>());
            string   path     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\CarpetaFalsa\a.xml";

            //Act
            votacion.SerializarXml(path);
        }
示例#12
0
        public void TestExceptionErrorArchivoI()
        {
            //Arrange
            SerializarXML <Votacion> Xml = new SerializarXML <Votacion>();
            Votacion votacionPrueba      = null;

            //Act
            Xml.Guardar("c\\", votacionPrueba);
            //Assert Manejado por la Excepcion
        }
示例#13
0
        public void XmlGuardarTest()
        {
            //Arrange
            Votacion votacion            = new Votacion();
            XmlSerializar <Votacion> xml = new XmlSerializar <Votacion>();

            //Act
            xml.Guardar("\\testVotacion.xml", votacion);

            //Assert
        }
示例#14
0
        public SqlCommand SetInsertOpciones(SqlCommand command, Iniciativa iniciativa)
        {
            Votacion votacion = (Votacion)iniciativa;

            command.CommandText = "INSERT INTO opciones VALUES ";
            foreach (Opcion item in votacion.Opciones)
            {
                command.CommandText += $"('{item.Descripcion}',{votacion.ID}),";
            }
            command.CommandText = command.CommandText.Remove(command.CommandText.Length - 1);
            return(command);
        }
        public void ManejadorVoto(string senador, Votacion.EVoto voto)
        {
            if (this.groupBox2.InvokeRequired)
            {
                Votacion.Voto recall = new Votacion.Voto(this.ManejadorVoto);
                this.Invoke(recall, new object[] { senador, voto });
            }
            else
            {
                // Leo la banca del Senador actual
                PictureBox p = this.graficos.ElementAt(int.Parse(senador) - 1);
                switch (voto)
                {
                case Votacion.EVoto.Afirmativo:
                    // Sumo votantes al Label correspondiente
                    lblAfirmativo.Text = (int.Parse(lblAfirmativo.Text) + 1).ToString();
                    // Marco la banca con color Verde
                    p.BackColor = Color.Green;
                    break;

                case Votacion.EVoto.Negativo:
                    // Sumo votantes al Label correspondiente
                    lblNegativo.Text = (int.Parse(lblNegativo.Text) + 1).ToString();
                    // Marco la banca con color Rojo
                    p.BackColor = Color.Red;
                    break;

                case Votacion.EVoto.Abstencion:
                    // Sumo votantes al Label correspondiente
                    lblAbstenciones.Text = (int.Parse(lblAbstenciones.Text) + 1).ToString();
                    // Marco la banca con color Amarillo
                    p.BackColor = Color.Yellow;
                    break;
                }
                // Quito un Senador de los que un no votaron, para marcar cuando termina la votación
                int aux = int.Parse(lblEsperando.Text) - 1;
                lblEsperando.Text = aux.ToString();
                // Si finaliza la votación, muestro si Es Ley o No Es Ley
                if (aux == 0)
                {
                    MessageBox.Show((int.Parse(lblAfirmativo.Text) - int.Parse(lblNegativo.Text)) > 0 ? "Es Ley" : "No es Ley", txtLeyNombre.Text);
                    // Guardar resultados
                    this.votacion = new Votacion(this.txtLeyNombre.Text, this.participantes);
                    this.votacion.ContadorAfirmativo = short.Parse(lblAfirmativo.Text);
                    this.votacion.ContadorNegativo   = short.Parse(lblNegativo.Text);
                    this.votacion.ContadorAbstencion = short.Parse(lblAbstenciones.Text);

                    SerializarXML <Votacion> serializarXML = new SerializarXML <Votacion>();
                    serializarXML.Guardar("Resultado.xml", ((Votacion)this.votacion));
                }
            }
        }
示例#16
0
 public void ExceptionSerializacion()
 {
     try
     {
         Votacion      votacion = new Votacion();
         SerializarXML xml      = new SerializarXML();
         xml.Guardar("", votacion);
     }
     catch (Exception e)
     {
         Assert.IsInstanceOfType(e, typeof(ErrorArchivoException));
     }
 }
示例#17
0
        public void TestEventoVotacion_SeLanzaTantasVecesComoSenadores()
        {
            Dictionary<string, Votacion.EVoto> senadores = new Dictionary<string, Votacion.EVoto>();
            senadores.Add("1", Votacion.EVoto.Esperando);
            senadores.Add("2", Votacion.EVoto.Esperando);
            Votacion votacion = new Votacion("Ley", senadores);
            votacion.EventoVotoEfectuado += ManejadorContador;

            votacion.Simular();

            Assert.AreEqual(2, UnitTest1.contadorEvento);

        }
示例#18
0
        public void EventoVotacion()
        {
            System.Collections.Generic.Dictionary <string, Votacion.EVoto> senadores = new System.Collections.Generic.Dictionary <string, Votacion.EVoto>();
            senadores.Add("0", Votacion.EVoto.Abstencion);
            senadores.Add("1", Votacion.EVoto.Abstencion);
            senadores.Add("2", Votacion.EVoto.Abstencion);
            senadores.Add("3", Votacion.EVoto.Abstencion);
            Votacion v = new Votacion("Nombre", senadores);

            v.EventoVotoEfectuado += Manejador;
            v.Simular();
            Assert.IsTrue(v.ContadoAfirmativo + v.ContadorAbstencion + v.ContadorNegativo == 4);
        }
示例#19
0
        public void ValidarSerializacion()
        {
            Dictionary <string, Votacion.EVoto> participantes = new Dictionary <string, Votacion.EVoto>();

            participantes.Add("1", Votacion.EVoto.Afirmativo);
            participantes.Add("2", Votacion.EVoto.Negativo);
            participantes.Add("3", Votacion.EVoto.Abstencion);

            Votacion votos = new Votacion("Ley X", participantes);

            SerializaBinaria ser = new SerializaBinaria();

            ser.Guardar("unitTest.bin", votos);
        }
示例#20
0
        public void CantidadEventos()
        {
            Dictionary <string, Votacion.EVoto> senadores = new Dictionary <string, Votacion.EVoto>();

            senadores.Add("1", Votacion.EVoto.Abstencion);
            senadores.Add("2", Votacion.EVoto.Afirmativo);

            Votacion votacion = new Votacion("TestUnitario", senadores);

            votacion.EventoVotoEfectuado += new Voto(Contador);
            votacion.Simular();

            Assert.AreEqual(cont, senadores.Count);
        }
示例#21
0
        public void ErrorArchivo()
        {
            Votacion v = null;

            try
            {
                SerializarXML <Votacion> ser = new SerializarXML <Votacion>();
                ser.Guardar(null, v); //Le mando null al path para que rompa
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ErrorArchivoException));
            }
        }
示例#22
0
        public void escribirDB()
        {
            // arrange
            Dictionary <string, Votacion.EVoto> senadores = new Dictionary <string, Votacion.EVoto>();

            senadores.Add("Senador 1", Votacion.EVoto.Afirmativo);
            senadores.Add("Senador 2", Votacion.EVoto.Negativo);
            senadores.Add("Senador 3", Votacion.EVoto.Abstencion);
            senadores.Add("Senador 4", Votacion.EVoto.Afirmativo);
            Votacion votacion = new Votacion("Ley 1", senadores);
            // act
            Dao d = new Dao();

            d.Guardar("Votaciones", votacion);
        }
        public void TestCompruevaSenadoresLasVecesNecesarias()
        {
            Dictionary <string, Votacion.EVoto> senadores = new Dictionary <string, Votacion.EVoto>
            {
                { "1", Votacion.EVoto.Esperando },
                { "2", Votacion.EVoto.Esperando }
            };
            Votacion votacion = new Votacion("Ley", senadores);

            votacion.EventoVotoEfectuado += ManejadorContador;

            votacion.Simular();

            Assert.AreEqual(2, contadorEvento);
        }
示例#24
0
        public void TestMethod1()
        {
            try
            {
                Votacion vot = new Votacion();

                SerializarXML <Votacion> ser = new SerializarXML <Votacion>();

                ser.Guardar(null, vot); //null para que entre al catch
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ErrorArchivoException));
            }
        }
示例#25
0
        public void TestMethod2()
        {
            System.Collections.Generic.Dictionary <string, Votacion.EVoto> senadores = new System.Collections.Generic.Dictionary <string, Votacion.EVoto>()
            {
                { "1", Votacion.EVoto.Abstencion },
                { "2", Votacion.EVoto.Afirmativo }
            };

            Votacion votacion = new Votacion("Ley", senadores);

            votacion.EventoVotoEfectuado += UnitTest1_evento;
            votacion.Simular();

            Assert.AreEqual(2, contador);
        }
示例#26
0
 private void FrmSenadores_Load(object sender, EventArgs e)
 {
     //TODO mejorar
     if (File.Exists(nombreArchivoBinario))
     {
         try
         {
             SerializarBinaria serializa = new SerializarBinaria();
             this.votacion = serializa.Leer(nombreArchivoBinario);
         }
         catch (Exception ex)
         {
             MessageBox.Show("Ocurrio un error al recuperar la votacion previa " + ex.Message);
         }
     }
 }
示例#27
0
        public void escribirArchivo()
        {
            // arrange
            Dictionary <string, Votacion.EVoto> senadores = new Dictionary <string, Votacion.EVoto>();

            senadores.Add("Senador 1", Votacion.EVoto.Afirmativo);
            senadores.Add("Senador 2", Votacion.EVoto.Negativo);
            senadores.Add("Senador 3", Votacion.EVoto.Abstencion);
            senadores.Add("Senador 4", Votacion.EVoto.Afirmativo);
            Votacion votacion = new Votacion("Ley 1", senadores);
            // act
            string            folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string            nombreArchivoBinario = folder + "\\votacionesTest.dat";
            SerializarBinaria ser = new SerializarBinaria();

            ser.Guardar(nombreArchivoBinario, votacion);
        }
示例#28
0
        public void cantidadDeEventos()
        {
            // arrange
            Dictionary <string, Votacion.EVoto> senadores = new Dictionary <string, Votacion.EVoto>();

            senadores.Add("Senador 1", Votacion.EVoto.Afirmativo);
            senadores.Add("Senador 2", Votacion.EVoto.Negativo);
            Votacion votacion = new Votacion("Ley 1", senadores);

            this.cantidadInvocaciones = 2;
            short expected = 0;

            votacion.EventoVotoEfectuado += TestEvento;
            // act
            votacion.Simular();
            // assert es manejado en el ExpectedException
            Assert.AreEqual(expected, this.cantidadInvocaciones);
        }
示例#29
0
        public void TestMethod2()
        {
            System.Collections.Generic.Dictionary <string, Votacion.EVoto> senadores;
            senadores = new System.Collections.Generic.Dictionary <string, Votacion.EVoto>();

            senadores.Add("NICOLAS", Votacion.EVoto.Negativo);
            senadores.Add("NICOLAO", Votacion.EVoto.Negativo);
            senadores.Add("Giuliano", Votacion.EVoto.Afirmativo);
            Votacion v = new Votacion("nombre", senadores);

            //agrego al evento el contador para ver cuantas veces
            v.EventoVotoEfectuado += Contador;

            v.Simular();

            //si la cantidad de veces que usa el evento es igual a los senadores
            Assert.AreEqual(senadores.Count, contador);
        }
示例#30
0
        public void TestExcepcion()
        {
            Exception aux = new Exception();
            Dictionary <string, Votacion.EVoto> participantes = new Dictionary <string, Votacion.EVoto>();
            Votacion          vot = new Votacion("Campo", participantes);
            SerializarBinaria b   = new SerializarBinaria();

            try
            {
                b.Guardar("campo", vot);
            }
            catch (ErrorArchivoExpcepcion e)
            {
                aux = e;
            }

            Assert.IsInstanceOfType(aux, typeof(ErrorArchivoExpcepcion));
        }