public void TestAddUser() { service.AddUser("TestUser 1", "John Doe", "John Does' address", 46010, "XX01010101010101", new DateTime(1985, 6, 5), false); User user = service.FindUserById("TestUser 1"); Assert.IsNotNull(user); Assert.AreEqual(user.Address, "John Does' address"); Assert.AreEqual(user.BirthDate, new DateTime(1985, 6, 5)); Assert.AreEqual(0, user.Enrollments.Count); Assert.AreEqual("XX01010101010101", user.IBAN); Assert.AreEqual("John Doe", user.Name); Assert.AreEqual(46010, user.ZipCode); Assert.IsFalse(user.Retired); }
private void BotonAddUser(object sender, EventArgs e) { Boolean ok = true; if (string.IsNullOrEmpty(nombre.Text)) { DialogResult answer = MessageBox.Show(this, // Owner "No ha introducido el nombre.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } if (string.IsNullOrEmpty(dni.Text)) { DialogResult answer = MessageBox.Show(this, // Owner "No ha introducido el DNI.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } if (string.IsNullOrEmpty(direccion.Text)) { DialogResult answer = MessageBox.Show(this, // Owner "No ha introducido la dirección.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } int codigopostal = 0; try { codigopostal = Convert.ToInt32(cp.Text); } catch (Exception) { DialogResult answer = MessageBox.Show(this, // Owner "Código postal incorrecto.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); ok = false; return; } if (string.IsNullOrEmpty(iban.Text)) { DialogResult answer = MessageBox.Show(this, // Owner "No ha introducido el número de cuenta.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } DateTime fecha = new DateTime(0); try { fecha = new DateTime(Convert.ToInt32(año.Text), Convert.ToInt32(mes.Text), Convert.ToInt32(dia.Text)); } catch (Exception) { DialogResult answer = MessageBox.Show(this, // Owner "Fecha de nacimiento incorrecta.", // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } bool jubilado = false; if (jubsi.Checked) { jubilado = true; } User nuevoUsuario = new User(direccion.Text, iban.Text, dni.Text, nombre.Text, codigopostal, fecha, jubilado); try { city.AddPerson(nuevoUsuario); service.AddUser(nuevoUsuario); } catch (Exception ex) { DialogResult answer = MessageBox.Show(this, // Owner ex.Message, // Message "Error", // Title MessageBoxButtons.AbortRetryIgnore, // Buttons included MessageBoxIcon.Exclamation); // Icon ok = false; return; } if (ok) { DialogResult answer = MessageBox.Show(this, // Owner "Usuario añadido correctamente.", // Message "Información", // Title MessageBoxButtons.OK, // Buttons included MessageBoxIcon.Information); // Icon nombre.Text = ""; dni.Text = ""; direccion.Text = ""; cp.Text = ""; iban.Text = ""; año.Text = ""; mes.Text = ""; dia.Text = ""; } }
void AddUsers() { Console.WriteLine(); Console.WriteLine("ADDING USERS..."); try { CityHall c = service.FindCityHallByName("Valencia"); Gym g = c.FindGymByName("Gym1"); Activity a = g.FindActivityByName("Yoga 101"); // User(String address, String IBAN, String id, String name, int zipCode, DateTime birthDate, bool retired) User u = new User("Cansado Perpetuo's address", "ES891234121234567890", "123456789B", "Cansado Perpetuo", 46002, new DateTime(1990, 6, 5), false); c.AddPerson(u); service.AddUser(u); double priceForUser = a.GetPriceForUser(g, u); // Payment(DateTime date, string description, double quantity) Payment p = new Payment(DateTime.Today, "First quota", priceForUser); c.AddPayment(p); // Enrollment(DateTime enrollmentDate, Activity activity, Payment payment, User user) Enrollment e = new Enrollment(new DateTime(2020, 09, 16), a, p, u); service.AddEnrollment(e); u = new User("Faemino Saavedra's address", "ES891234121234567891", "123456780W", "Faemino Saavedra", 46002, new DateTime(1979, 4, 12), false); c.AddPerson(u); service.AddUser(u); priceForUser = a.GetPriceForUser(g, u); p = new Payment(DateTime.Today, "First quota", priceForUser); c.AddPayment(p); e = new Enrollment(new DateTime(2020, 10, 08), a, p, u); service.AddEnrollment(e); u = new User("Rubén Doblas Gundersen's address", "ES891234121234567892", "123456782W", "Rubén Doblas Gundersen", 46003, new DateTime(1990, 2, 13), false); c.AddPerson(u); service.AddUser(u); priceForUser = a.GetPriceForUser(g, u); p = new Payment(DateTime.Today, "First quota", priceForUser); c.AddPayment(p); e = new Enrollment(new DateTime(2020, 09, 28), a, p, u); service.AddEnrollment(e); u = new User("Rigoberto's address", "ES891234121234567893", "123456783M", "Rigoberto", 46122, new DateTime(1995, 2, 28), false); c.AddPerson(u); service.AddUser(u); priceForUser = a.GetPriceForUser(g, u); p = new Payment(DateTime.Today, "First quota", priceForUser); c.AddPayment(p); e = new Enrollment(new DateTime(2020, 10, 02), a, p, u); service.AddEnrollment(e); u = new User("Lazaro's address", "ES891234121234567894", "567890123K", "Lazaro", 46122, new DateTime(1900, 1, 1), true); c.AddPerson(u); service.AddUser(u); priceForUser = a.GetPriceForUser(g, u); p = new Payment(DateTime.Today, "First quota", priceForUser); c.AddPayment(p); e = new Enrollment(new DateTime(2017, 09, 29), a, p, u); service.AddEnrollment(e); // Checking Users enrolled Console.WriteLine(" Users enrolled in the activity " + a.Description + " with instructor " + a.Instructor.Name); foreach (Enrollment en in a.Enrollments) { Console.WriteLine(" " + en.User.Name + " enrolled"); } } catch (Exception e) { printError(e); } }