Ejemplo n.º 1
0
        public void Client_HashPasswordAndCompareWithAttemptedPasswords()
        {
            var passSaltInDb = PasswordUtilities.CreateSalt(16);
            var passHashInDb = PasswordUtilities.GenerateSHA256Hash("TestingPassword", passSaltInDb);

            Assert.IsFalse(PasswordUtilities.Compare("TestingPa$$word", passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare("Testing Password", passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare(string.Empty, passHashInDb, passSaltInDb));
            Assert.IsFalse(PasswordUtilities.Compare(null, passHashInDb, passSaltInDb));
            Assert.IsTrue(PasswordUtilities.Compare("TestingPassword", passHashInDb, passSaltInDb));
        }
Ejemplo n.º 2
0
        private void saveButton_Click_1(object sender, EventArgs e)
        {
            feedbackLabel1.Text = "";
            //if 0 then every check is passed | 3 - name empty | 4 - surname empty
            //5 - password empty | 6 - password doesnt match | 7 - password invalid | 8 - something went wrong in database
            int okayToUpdate = 0;

            //take all input from fields
            if (nameTextBox.Text == "" || nameTextBox.Text == null)
            {
                okayToUpdate = 3;
            }
            else
            {
                Account.User.Name = nameTextBox.Text;
            }
            if (surnameTextBox.Text == "" || surnameTextBox.Text == null)
            {
                okayToUpdate = 4;
            }
            else
            {
                Account.User.Surname = surnameTextBox.Text;
            }
            if (telTexBox.Text == "" || telTexBox.Text == null)
            {
                Account.User.Tel = "";
            }
            else
            {
                Account.User.Tel = telTexBox.Text;
            }
            if (educationLevelCB.SelectedIndex != -1)
            {
                Account.User.EducationLevel.Name = educationLevelCB.GetItemText(educationLevelCB.SelectedItem);
                Account.User.EducationLevel.Id   = educationLevelCB.SelectedIndex + 1;
            }
            else
            {
                Account.User.EducationLevel.Name = "";
                Account.User.EducationLevel.Id   = -999;
            }

            if (roleCB.SelectedIndex != -1)
            {
                Account.User.Role.Name = roleCB.GetItemText(roleCB.SelectedItem);
                Account.User.Role.Id   = roleCB.SelectedIndex + 1;
            }
            else
            {
                Account.User.Role.Name = "";
                Account.User.Role.Id   = -999;
            }
            if (descriptionRTB.Text == null || descriptionRTB.Text == "")
            {
                Account.User.Description = "";
            }
            else
            {
                Account.User.Description = descriptionRTB.Text;
            }
            //check image
            if (imagePathTB.Text.Length != 0 && !imagePathTB.Text.Equals("keepTheSameImage"))
            {
                // update the image, the user chose a new one
                string fileName = imagePathTB.Text;

                FileStream   fs        = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                BinaryReader br        = new BinaryReader(fs);
                byte[]       imageData = br.ReadBytes((int)fs.Length);

                Account.User.Image = imageData;
            }
            else if (imagePathTB.Text.Length == 0)
            {
                // remove the image, the user didn't choose any image
                Account.User.Image = null;
            }
            // else, keep the same image, so don't change the Account.User.Image value at all


            if (genderMaleRB.Checked)
            {
                Account.User.Gender = 'M';
            }
            else if (genderFemaleRB.Checked)
            {
                Account.User.Gender = 'F';
            }
            Account.User.DateOfBirth = dateOfBirthDTP.Value;

            //check password

            string pass     = passwordTextBox.Text;
            string passConf = passwordConfirmTextBox.Text;

            if (pass.Equals("") || pass == null)
            {
                okayToUpdate = 5;
            }

            if (pass.Equals(passConf))
            {
                if (pass.Length < 8 || !pass.Any(char.IsNumber) || !pass.Any(char.IsLetter))
                {
                    //lathos password
                    okayToUpdate = 7;
                }
                else
                {
                    if (okayToUpdate == 0)
                    {
                        //try to update

                        //make password hash and create salt
                        string salt           = PasswordUtilities.CreateSalt(16);
                        string passwordHashed = PasswordUtilities.GenerateSHA256Hash(pass, salt);
                        Account.PasswordSalt       = salt;
                        Account.SaltedPasswordHash = passwordHashed;

                        // set up account username for interoperability purposes
                        Account.Username = usernameTextBox.Text;

                        int accountAffected = DBConnect.Update(Account);
                        int userAffected    = DBConnect.Update(Account.User);
                        if (accountAffected == 1 && userAffected == 1)
                        {
                            UpdatedSuccessfully = true;
                            // Account update succeded
                            MessageBox.Show("  Account updated successfully!\n");
                            feedbackLabel1.Text = "";
                            this.Close();
                        }
                        else
                        {
                            // Account update not successful
                            okayToUpdate = 8;
                        }
                    }
                }
            }
            else
            {
                okayToUpdate = 6;
            }

            feedbackLabel1.ForeColor = Color.Black;

            // fade out effect in feedbackLabel message
            Timer timer1 = new Timer();

            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start();

            updateFeedbackLabel(okayToUpdate);
        }
Ejemplo n.º 3
0
        protected override void Seed(GymContext context)
        {
            //test
            #region Clients
            var passwordSalt1  = PasswordUtilities.CreateSalt(16);
            var password1      = PasswordUtilities.GenerateSHA256Hash("12345", passwordSalt1);
            var passwordSalt2  = PasswordUtilities.CreateSalt(16);
            var password2      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt2);
            var passwordSalt3  = PasswordUtilities.CreateSalt(16);
            var password3      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt3);
            var passwordSalt4  = PasswordUtilities.CreateSalt(16);
            var password4      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt4);
            var passwordSalt5  = PasswordUtilities.CreateSalt(16);
            var password5      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt5);
            var passwordSalt6  = PasswordUtilities.CreateSalt(16);
            var password6      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt6);
            var passwordSalt7  = PasswordUtilities.CreateSalt(16);
            var password7      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt7);
            var passwordSalt8  = PasswordUtilities.CreateSalt(16);
            var password8      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt8);
            var passwordSalt9  = PasswordUtilities.CreateSalt(16);
            var password9      = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt9);
            var passwordSalt10 = PasswordUtilities.CreateSalt(16);
            var password10     = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt10);

            var clients = new List <Client>
            {
                new Client {
                    FirstName = "John", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom  = new DateTime(2008, 09, 01), Email = "*****@*****.**",
                    Password  = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    FirstName = "Cristian", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom  = new DateTime(2008, 09, 01), Email = "*****@*****.**",
                    Password  = password2, PasswordSalt = passwordSalt2, Role = Catalog.Roles.Admin, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    FirstName = "José", LastName = "Pérez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1982, 12, 31),
                    DateFrom  = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password  = password3, PasswordSalt = passwordSalt3, Role = Catalog.Roles.Instructor, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    FirstName = "Ray", LastName = "Allen", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1992, 12, 31),
                    DateFrom  = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password  = password4, PasswordSalt = passwordSalt4, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    FirstName = "Enzo", LastName = "Gutiérrez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1991, 12, 31),
                    DateFrom  = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password  = password5, PasswordSalt = passwordSalt5, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    FirstName = "Juana", LastName = "Pérez", DocType = "DNI", DocNumber = 33123654, BirthDate = new DateTime(1979, 08, 11),
                    DateFrom  = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password  = password6, PasswordSalt = passwordSalt6, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    FirstName = "Carolina", LastName = "García", DocType = "DNI", DocNumber = 12345678, BirthDate = new DateTime(1971, 11, 15),
                    DateFrom  = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password  = password7, PasswordSalt = passwordSalt7, Role = Catalog.Roles.Instructor, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    FirstName = "Martina", LastName = "Núñez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1981, 02, 01),
                    DateFrom  = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password  = password8, PasswordSalt = passwordSalt8, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    FirstName = "Sol", LastName = "Rodríguez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1991, 12, 31),
                    DateFrom  = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password  = password9, PasswordSalt = passwordSalt9, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    FirstName = "José", LastName = "García", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1986, 12, 31),
                    DateFrom  = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password  = password10, PasswordSalt = passwordSalt10, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                }
            };

            clients.ForEach(c => context.Clients.Add(c));
            context.SaveChanges();
            #endregion

            #region Routines
            var routines = new List <Routine>
            {
                new Routine {
                    ClientID = 1, NameFile = "CristianPique v1.0", Description = "Rutina personalizada", Files = new List <File>(), CreationDate = DateTime.Now, DaysInWeek = 5,
                    Level    = Catalog.LevelRoutine.Medium, Status = Catalog.Status.Active
                },
                new Routine {
                    ClientID = 1, NameFile = "RutinaBegginers", Description = "Rutina nivel princiante", Files = new List <File>(), CreationDate = DateTime.Now, DaysInWeek = 3,
                    Level    = Catalog.LevelRoutine.Begginer, Status = Catalog.Status.Active
                },
                new Routine {
                    ClientID = 1, NameFile = "Cardio rutina", Description = "Rutina intensiva cardio", Files = new List <File>(), CreationDate = DateTime.Now, DaysInWeek = 4,
                    Level    = Catalog.LevelRoutine.Medium, Status = Catalog.Status.Active
                },
                new Routine {
                    ClientID = 1, NameFile = "AbdominalesRutina", Description = "Rutina abdominales", Files = new List <File>(), CreationDate = DateTime.Now, DaysInWeek = 4,
                    Level    = Catalog.LevelRoutine.Expert, Status = Catalog.Status.Active
                }
            };

            routines.ForEach(r => context.Routines.Add(r));
            context.SaveChanges();
            #endregion

            #region MedicalRecords
            var medicalRecords = new List <MedicalRecord>
            {
                new MedicalRecord {
                    ClientID = 1, Age = 26, Gender = 'M', Heigth = 1.81, Weight = 75
                },
            };

            medicalRecords.ForEach(m => context.MedicalRecords.Add(m));
            context.SaveChanges();
            #endregion

            #region Activities
            var clientsForActivities = new List <Client>();
            clientsForActivities.Add(clients.Where(x => x.ClientID == 1).FirstOrDefault());
            clientsForActivities.Add(clients.Where(x => x.ClientID == 1).FirstOrDefault());

            var activities = new List <Activity>
            {
                new Activity {
                    Name = "Gimnasio", Description = "Gimnasio, pesas, bicicletas, máquinas para correr"
                },
                new Activity {
                    Name = "Pilates", Description = "Sistema de entrenamiento físico y mental"
                },
                new Activity {
                    Name = "Boxeo", Description = "Deporte de combate"
                }
            };

            activities.ForEach(a => context.Activities.Add(a));
            context.SaveChanges();
            #endregion

            #region ActivitySchedules
            var activitySchedules = new List <ActivitySchedule>
            {
                new ActivitySchedule {
                    ActivityID = 2, Day = "Lunes", HourFrom = 11, HourTo = 12
                },
                new ActivitySchedule {
                    ActivityID = 2, Day = "Lunes", HourFrom = 16, HourTo = 17
                },
                new ActivitySchedule {
                    ActivityID = 2, Day = "Miércoles", HourFrom = 19, HourTo = 21
                },
                new ActivitySchedule {
                    ActivityID = 3, Day = "Miércoles", HourFrom = 9, HourTo = 10
                },
                new ActivitySchedule {
                    ActivityID = 3, Day = "Miércoles", HourFrom = 20, HourTo = 21
                },
            };

            activitySchedules.ForEach(actS => context.ActivitySchedules.Add(actS));
            context.SaveChanges();
            #endregion

            #region Files
            var files = new List <File>
            {
                new File {
                    RoutineID = 1, ExerciseName = "Pecho inclinado", MuscleName = "Pecho", Peso = "20", Repetitions = "3x10", Day = "Lunes"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Pecho con mancuernas", MuscleName = "Pecho", Peso = "15", Repetitions = "3x12", Day = "Martes"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Pecho con mancuernas", MuscleName = "Pecho", Peso = "20", Repetitions = "3x8", Day = "Martes"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Bíceps con mancuernas", MuscleName = "Bíceps", Peso = "8", Repetitions = "3x12", Day = "Miércoles"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Bíceps con mancuernas", MuscleName = "Bíceps", Peso = "10", Repetitions = "3x12", Day = "Jueves"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Francés", MuscleName = "Tríceps", Peso = "8", Repetitions = "3x12", Day = "Jueves"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Tríceps con mancuernas", MuscleName = "Tríceps", Peso = "8", Repetitions = "3x12", Day = "Viernes"
                },
                new File {
                    RoutineID = 1, ExerciseName = "Press militar", MuscleName = "Hombros", Peso = "8", Repetitions = "3x12", Day = "Viernes"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Pecho inclinado", MuscleName = "Pecho", Peso = "20", Repetitions = "3x10", Day = "Lunes"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Pecho con mancuernas", MuscleName = "Pecho", Peso = "15", Repetitions = "3x12", Day = "Martes"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Pecho con mancuernas", MuscleName = "Pecho", Peso = "20", Repetitions = "3x8", Day = "Martes"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Bíceps con mancuernas", MuscleName = "Bíceps", Peso = "8", Repetitions = "3x12", Day = "Miércoles"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Bíceps con mancuernas", MuscleName = "Bíceps", Peso = "10", Repetitions = "3x12", Day = "Jueves"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Francés", MuscleName = "Tríceps", Peso = "8", Repetitions = "3x12", Day = "Jueves"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Tríceps con mancuernas", MuscleName = "Tríceps", Peso = "8", Repetitions = "3x12", Day = "Viernes"
                },
                new File {
                    RoutineID = 2, ExerciseName = "Press militar", MuscleName = "Hombros", Peso = "8", Repetitions = "3x12", Day = "Viernes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Biclicleta", MuscleName = "Piernas", Peso = "-", Repetitions = "20 min", Day = "Lunes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Cinta", MuscleName = "Piernas", Peso = "15", Repetitions = "3x12", Day = "Lunes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Pecho con mancuernas", MuscleName = "Pecho", Peso = "20", Repetitions = "3x8", Day = "Martes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Abdominales oblicuos", MuscleName = "Abdominales", Peso = "-", Repetitions = "3x20", Day = "Martes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Abdominales bajos", MuscleName = "Abdominales", Peso = "-", Repetitions = "3x30", Day = "Míércoles"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Saltar soga", MuscleName = "Piernas", Peso = "-", Repetitions = "15 min", Day = "Míércoles"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Tríceps con mancuernas", MuscleName = "Tríceps", Peso = "8", Repetitions = "3x12", Day = "Jueves"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Biclicleta", MuscleName = "Pecho", Peso = "-", Repetitions = "20 min", Day = "Lunes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Biclicleta", MuscleName = "Piernas", Peso = "-", Repetitions = "20 min", Day = "Lunes"
                },
                new File {
                    RoutineID = 3, ExerciseName = "Cinta", MuscleName = "Piernas", Peso = "15", Repetitions = "3x12", Day = "Lunes"
                },
            };

            files.ForEach(f => context.Files.Add(f));
            context.SaveChanges();
            #endregion

            #region PaymentType
            var paymentType = new List <PaymentType>
            {
                new PaymentType {
                    Description = "Gimnasio mensual", Status = Catalog.Status.Active, ActivityID = 1, DurationInMonths = 1
                },
                new PaymentType {
                    Description = "Gimnasio anual", Status = Catalog.Status.Active, ActivityID = 1, DurationInMonths = 12
                },
                new PaymentType {
                    Description = "Pilates mensual", Status = Catalog.Status.Active, ActivityID = 2, DurationInMonths = 1
                },
                new PaymentType {
                    Description = "Boxeo mensual", Status = Catalog.Status.Active, ActivityID = 3, DurationInMonths = 1
                },
            };

            paymentType.ForEach(p => context.PaymentTypes.Add(p));
            context.SaveChanges();
            #endregion

            #region Payment
            var payments = new List <Payment>
            {
                new Payment {
                    ClientID = 1, PaymentTypeID = 1, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },
                new Payment {
                    ClientID = 2, PaymentTypeID = 2, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },

                new Payment {
                    ClientID = 4, PaymentTypeID = 1, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },
                new Payment {
                    ClientID = 4, PaymentTypeID = 2, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },

                new Payment {
                    ClientID = 5, PaymentTypeID = 3, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },
                new Payment {
                    ClientID = 5, PaymentTypeID = 3, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },

                new Payment {
                    ClientID = 6, PaymentTypeID = 4, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                },
                new Payment {
                    ClientID = 6, PaymentTypeID = 4, Status = Catalog.Status.Active, ExpirationDate = new DateTime(2016, 12, 12), CreationDate = DateTime.Now
                }
            };

            payments.ForEach(p => context.Payments.Add(p));
            context.SaveChanges();
            #endregion

            #region PaymentTypePrices
            var paymentTypePrices = new List <PaymentTypePrice>
            {
                new PaymentTypePrice {
                    DateFrom = new DateTime(2016, 01, 01), PaymentTypeID = 1, Price = 200
                },
                new PaymentTypePrice {
                    DateFrom = new DateTime(2016, 05, 01), PaymentTypeID = 1, Price = 300
                },
                new PaymentTypePrice {
                    DateFrom = new DateTime(2016, 01, 01), PaymentTypeID = 1, Price = 2000
                }
            };

            paymentTypePrices.ForEach(ptp => context.PaymentTypePrices.Add(ptp));
            context.SaveChanges();
            #endregion

            #region Suppliers
            var suppliers = new List <Supplier>
            {
                new Supplier {
                    Address    = "Entre Rios 2456", BusinessName = "EuroGym", City = "Rosario", Country = "Argentina", Email = "*****@*****.**", PhoneNumber = "(341) 42145580",
                    PostalCode = 2000, WebSite = "http://www.eurogym.com.ar"
                },
                new Supplier {
                    Address    = "Santa Fé Av 1052", BusinessName = "Total Gym", City = "Buenos Aires", Country = "Argentina", Email = "*****@*****.**", PhoneNumber = "(011) 5445-7189",
                    PostalCode = 1059, WebSite = "http://www.totalgym.com.ar"
                },
                new Supplier {
                    Address    = "V. Cardoso 1401", BusinessName = "e-punto Fitness", City = "Ramos Mejia", Country = "Argentina", Email = "*****@*****.**", PhoneNumber = "(011) 4654-2160",
                    PostalCode = 1059, WebSite = "http://www.e-puntofitness.com.ar/"
                },
                new Supplier {
                    Address    = "La Paz 138", BusinessName = "Distribuidora Boom S.R.L", City = "Rosario", Country = "Argentina", Email = "*****@*****.**", PhoneNumber = "(341) 1564895212",
                    PostalCode = 2000, WebSite = "http://www.boomsrl.com.ar/"
                },
            };

            suppliers.ForEach(s => context.Suppliers.Add(s));
            context.SaveChanges();
            #endregion

            #region Products
            var products = new List <Product>
            {
                new Product {
                    Name   = "Cama de Pilates", Description = "Cama de pilates + tabla de salto + tabla de extensión + box Garantía 1 año", Price = 8000, PurchaseDate = new DateTime(2014, 05, 02),
                    Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 3
                },
                new Product {
                    Name   = "Sillón de cuadriceps", Description = "Sillon de cuadriceps c/75kgrs.Linea Exclusive", Price = 25560, PurchaseDate = new DateTime(2015, 08, 02),
                    Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 3
                },
                new Product {
                    Name  = "Bicicleta Indoor", Description = "Transmisión a cadena Volante de inercia de 20Kg. balanceado dinámicamente cromado y pintado en el centro. Asiento prostático. Manubrio regulable en altura.",
                    Price = 6099, PurchaseDate = new DateTime(2015, 07, 22), Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 3
                },
                new Product {
                    Name  = "Cinta Profesional", Description = "Motor 3hp corriente alterna uso industrial 24hs - Velocidad de 0,8 a 16 km/h programable hasta 20km/h- Banda de doble tela antideslizante y antiestática con carbono .",
                    Price = 37550, PurchaseDate = new DateTime(2014, 05, 02), Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 3
                },
                new Product {
                    Name  = "Complejo Multiestación", Description = "El complejo de cuatro estaciones de uso profesional esta compuesto por una Camilla femoral y sillon de cuadriceps con una carga de 50 Kg mas una polea simple alta y baja de 10 regulaciones y 50 Kg de carga mas una pectoralera con 50 Kg de carga y una Dorsalera con 75 kg de carga. ",
                    Price = 97500, PurchaseDate = new DateTime(2014, 05, 02), Status = Utils.Catalog.ProductStatus.Deteriorated, Type = Utils.Catalog.ProductType.Machine, SupplierID = 1
                },
                new Product {
                    Name  = "Polea simple regulable 12 niveles", Description = "Polea simple con lingotera de 75 kilos y 12 regulaciones línea profesional Exclusive.",
                    Price = 6512, PurchaseDate = new DateTime(2014, 05, 02), Status = Utils.Catalog.ProductStatus.Broken, Type = Utils.Catalog.ProductType.Machine, SupplierID = 1
                },
                new Product {
                    Name  = "Pectoralera c/75kgrs", Description = "Pectoralera mariposa con lingotera de 75 kilos línea profesional Exclusive",
                    Price = 5300, PurchaseDate = new DateTime(2014, 05, 02), Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 2
                },
                new Product {
                    Name  = "Remo Bajo", Description = "Press de pecho con lingotera de 100 kilos línea profesional Exclusive.",
                    Price = 6100, PurchaseDate = new DateTime(2014, 05, 02), Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 4
                },
                new Product {
                    Name   = "Agua Villavicencio 500ml", Description = "Botella de agua mineral Villavicencio", Price = 1050, PurchaseDate = new DateTime(2016, 09, 02),
                    Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Article, SupplierID = 4
                },
                new Product {
                    Name   = "Gatorade 750ml", Description = "Gatorade 750ml Naranja", Price = 20, PurchaseDate = new DateTime(2016, 09, 02),
                    Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Article, SupplierID = 4
                },
                new Product {
                    Name  = "Banco Pecho Modulo", Description = "Banco regulable que permite ejercicios con barra y camilla de cuadriceps y femoral a discos.",
                    Price = 2300, PurchaseDate = new DateTime(2016, 09, 02), Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 1
                },
                new Product {
                    Name   = "Banco Pecho Regulable", Description = "Banco de pecho regulable standard", Price = 3100, PurchaseDate = new DateTime(2016, 09, 02),
                    Status = Utils.Catalog.ProductStatus.Ok, Type = Utils.Catalog.ProductType.Machine, SupplierID = 2
                },
            };

            products.ForEach(p => context.Products.Add(p));
            context.SaveChanges();
            #endregion

            #region Assistances
            var assistances = new List <Assistance>
            {
                new Assistance {
                    assistanceDate = new DateTime(2016, 01, 01), ClientID = 1
                },
                new Assistance {
                    assistanceDate = new DateTime(2015, 01, 01), ClientID = 1
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 1
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 01, 01), ClientID = 2
                },
                new Assistance {
                    assistanceDate = new DateTime(2015, 01, 01), ClientID = 2
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 2
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 01, 01), ClientID = 3
                },
                new Assistance {
                    assistanceDate = new DateTime(2015, 01, 01), ClientID = 3
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 3
                },
                new Assistance {
                    assistanceDate = new DateTime(2015, 01, 01), ClientID = 4
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 4
                },
                new Assistance {
                    assistanceDate = new DateTime(2015, 01, 01), ClientID = 5
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 5
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 6
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 8
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                },
                new Assistance {
                    assistanceDate = new DateTime(2016, 02, 01), ClientID = 7
                }
            };

            assistances.ForEach(a => context.Assistances.Add(a));
            context.SaveChanges();
            #endregion
        }
        public void Init()
        {
            #region Dummy Lists
            var passwordSalt1 = PasswordUtilities.CreateSalt(16);
            var password1     = PasswordUtilities.GenerateSHA256Hash("12345", passwordSalt1);

            clients = new List <Client>
            {
                new Client {
                    ClientID = 1, FirstName = "John", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2008, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    ClientID = 2, FirstName = "Cristian", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2008, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Admin, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    ClientID = 3, FirstName = "José", LastName = "Pérez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1982, 12, 31),
                    DateFrom = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Instructor, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    ClientID = 4, FirstName = "Ray", LastName = "Allen", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1992, 12, 31),
                    DateFrom = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    ClientID = 5, FirstName = "Enzo", LastName = "Gutiérrez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1991, 12, 31),
                    DateFrom = new DateTime(2014, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                },

                new Client {
                    ClientID = 6, FirstName = "Juana", LastName = "Pérez", DocType = "DNI", DocNumber = 33123654, BirthDate = new DateTime(1979, 08, 11),
                    DateFrom = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    ClientID = 7, FirstName = "Carolina", LastName = "García", DocType = "DNI", DocNumber = 12345678, BirthDate = new DateTime(1971, 11, 15),
                    DateFrom = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Instructor, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    ClientID = 8, FirstName = "Martina", LastName = "Núñez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1981, 02, 01),
                    DateFrom = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    ClientID = 9, FirstName = "Sol", LastName = "Rodríguez", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1991, 12, 31),
                    DateFrom = new DateTime(2015, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Mujer
                },

                new Client {
                    ClientID = 10, FirstName = "José", LastName = "García", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1986, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1, Role = Catalog.Roles.Client, Sexo = Catalog.Genre.Hombre
                }
            };

            medicalRecords = new List <MedicalRecord>
            {
                new MedicalRecord {
                    ClientID = 1, Age = 26, Gender = 'M', Heigth = 1.81, Weight = 77
                },
                new MedicalRecord {
                    ClientID = 2, Age = 33, Gender = 'F', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 3, Age = 28, Gender = 'F', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 4, Age = 23, Gender = 'M', Heigth = 1.81, Weight = 79
                },
                new MedicalRecord {
                    ClientID = 5, Age = 26, Gender = 'M', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 6, Age = 26, Gender = 'F', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 7, Age = 25, Gender = 'M', Heigth = 1.81, Weight = 88
                },
                new MedicalRecord {
                    ClientID = 8, Age = 26, Gender = 'M', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 10, Age = 18, Gender = 'M', Heigth = 1.81, Weight = 75
                },
                new MedicalRecord {
                    ClientID = 4, Age = 26, Gender = 'M', Heigth = 1.81, Weight = 75
                },
            };
            #endregion

            #region Repositories
            clientRepository        = Mock.Create <IClientRepository>();
            medicalRecordRepository = Mock.Create <IMedicalRecordRepository>();
            context  = Mock.Create <HttpContextBase>();
            request  = Mock.Create <HttpRequestBase>();
            response = Mock.Create <HttpResponseBase>();
            session  = Mock.Create <HttpSessionStateBase>();
            server   = Mock.Create <HttpServerUtilityBase>();
            #endregion

            #region Controller
            controller = new DashBoardController(clientRepository, medicalRecordRepository);
            #endregion

            #region Fake Context
            Mock.Arrange(() => clientRepository
                         .GetClientByID(CLIENT_ID_TO_USE))
            .Returns(clients.Where(c => c.ClientID == CLIENT_ID_TO_USE)
                     .FirstOrDefault());

            Mock.Arrange(() => context.Request).Returns(request);
            Mock.Arrange(() => context.Response).Returns(response);
            Mock.Arrange(() => context.Session).Returns(session);
            Mock.Arrange(() => context.Server).Returns(server);
            Mock.Arrange(() => session["UserData"]).Returns(clients.Where(c => c.ClientID == CLIENT_ID_TO_USE));
            #endregion

            #region JustMock
            #endregion
        }
Ejemplo n.º 5
0
        public void Init()
        {
            #region Dummy Clients List
            var passwordSalt1 = PasswordUtilities.CreateSalt(16);
            var password1     = PasswordUtilities.GenerateSHA256Hash("12345", passwordSalt1);
            var passwordSalt2 = PasswordUtilities.CreateSalt(16);
            var password2     = PasswordUtilities.GenerateSHA256Hash("335588", passwordSalt2);

            clients = new List <Client>
            {
                new Client {
                    ClientID = 1, FirstName = "John", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = password1, PasswordSalt = passwordSalt1
                },

                new Client {
                    ClientID = 2, FirstName = "Cristian", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = password2, PasswordSalt = passwordSalt2
                },

                new Client {
                    ClientID = 3, FirstName = "Ted", LastName = "Mosby", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1985, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = password2, PasswordSalt = passwordSalt2
                }
            };
            #endregion

            #region Dummy IsolatedClient
            var passwordSalt = PasswordUtilities.CreateSalt(16);
            newClient = new Client
            {
                ClientID     = 50,
                FirstName    = "John",
                LastName     = "Doe",
                DocType      = "DNI",
                DocNumber    = 34578800,
                BirthDate    = new DateTime(1990, 12, 31),
                DateFrom     = new DateTime(2016, 09, 01),
                Email        = "*****@*****.**",
                Password     = PasswordUtilities.GenerateSHA256Hash("test", passwordSalt),
                PasswordSalt = passwordSalt
            };
            #endregion

            #region Dummy MassiveClientsListForIndexTests List
            var passwordSalt0 = PasswordUtilities.CreateSalt(16);
            var password0     = PasswordUtilities.GenerateSHA256Hash("12345", passwordSalt0);

            massiveClients = new List <Client>
            {
                new Client {
                    ClientID = 1, FirstName = "Alejandra", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 2, FirstName = "Alberto", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 3, FirstName = "Antonio", LastName = "Mosby", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1985, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 1, FirstName = "Cristian", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 2, FirstName = "Carlos", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 3, FirstName = "Cecilia", LastName = "Mosby", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1985, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 1, FirstName = "John", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 2, FirstName = "Juan", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 3, FirstName = "Ted", LastName = "Mosby", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1985, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 1, FirstName = "Maria", LastName = "Doe", DocType = "DNI", DocNumber = 34578800, BirthDate = new DateTime(1990, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 2, FirstName = "Martina", LastName = "Piqué", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1989, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                },

                new Client {
                    ClientID = 3, FirstName = "Zurdo", LastName = "Mosby", DocType = "DNI", DocNumber = 34578644, BirthDate = new DateTime(1985, 12, 31),
                    DateFrom = new DateTime(2016, 09, 01), Email = "*****@*****.**",
                    Password = passwordSalt0, PasswordSalt = passwordSalt0
                }
            };
            #endregion

            #region Repositories
            clientRepository = Mock.Create <IClientRepository>();
            #endregion

            #region Controller creation
            controller = new ClientsController(clientRepository);
            #endregion

            #region JustMock Arranges
            Mock.Arrange(() => clientRepository.GetClients())
            .Returns(clients)
            .MustBeCalled();

            Mock.Arrange(() => clientRepository.GetClientByID(CLIENT_ID_TO_USE))
            .Returns(clients.Where(c => c.ClientID == CLIENT_ID_TO_USE).FirstOrDefault())
            .MustBeCalled();

            Mock.Arrange(() => clientRepository.InsertClient(newClient))
            .DoInstead(() => clients.Add(newClient));

            Mock.Arrange(() => clientRepository.Save()).DoNothing();

            Mock.Arrange(() => clientRepository.DeleteClient(CLIENT_ID_TO_USE))
            .DoInstead(() => clients.Remove(clients.Where(c => c.ClientID == CLIENT_ID_TO_USE).FirstOrDefault()));

            Mock.Arrange(() => clientRepository.UpdateClient(new Client())).DoNothing();

            Mock.Arrange(() => clientRepository.IsEmailAlreadyInUse(newClient))
            .Returns(() => this.IsEmailAlreadyInUse(newClient, false))
            .MustBeCalled();
            #endregion
        }
Ejemplo n.º 6
0
 public void HashPassword(Client client)
 {
     client.PasswordSalt = PasswordUtilities.CreateSalt(16);
     client.Password     = PasswordUtilities.GenerateSHA256Hash(client.Password, client.PasswordSalt);
 }