public void CalcularTiempo2() { var instancia = new tiempoJugado(); var segundos = instancia.calcularTiempo2("0", "0", "20"); Assert.AreEqual(segundos, "20"); var segundos2 = instancia.calcularTiempo2("0", "2", "20"); Assert.AreEqual(segundos2, "140"); }
// Consultar a la BBDD registres d'hores Jugades. /// <summary> /// Consultar timepoJugado! /// </summary> /// <param name="juego"></param> /// <returns></returns> public int tiempoJugado(tiempoJugado juego) { int temps = 0; try { String[] tot; conectar.Open(); MySqlCommand comandom = new MySqlCommand("Select tiempoJugado from tiempoJugado where idUsuario=" + '"' + juego.NombreUsuario + '"' + " and idJuego = " + '"' + juego.NombreJuego + '"', conectar); MySqlDataReader read = comandom.ExecuteReader(); string h = "", m = "", s = ""; while (read.Read()) { String total = (String.Format("{0}", read[0])); int i = 0; tot = total.Split(':'); foreach (String tota in tot) { Console.WriteLine("{0}:{1}", i, tota); switch (i) { case 0: h = tota; break; case 1: m = tota; break; case 2: s = tota; break; default: Console.WriteLine("Error"); break; } i++; } temps += Int32.Parse(tiempoJugados.calcularTiempo2(h, m, s)); } conectar.Close(); return(temps); } catch { conectar.Close(); logs.Save("Error al consultar tiempoJugado!", 80); return(temps); } }