Esempio n. 1
0
        private static void LoadFile(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                var csv = new CsvReader(sr);
                while (csv.Read())
                {
                    //Import Customer(Account and Parent)
                    int accountId = ImportCustomer(csv);

                    //ClassInfo
                    ClassInfo classInfo = new ClassInfo();
                    classInfo.FromCsv(csv);

                    using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
                    {
                        ClassInfoRepo repo = new ClassInfoRepo(dbContext);

                        repo.Add(classInfo);

                        try
                        {
                            //Save to DB
                            dbContext.SaveChanges();
                        }
                        catch (DbEntityValidationException)
                        {
                            throw;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void ClassInfoIntegationTests_AddClass()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ClassInfoRepo repo = new ClassInfoRepo(dbContext);
                repo.Add(new ClassInfo {
                    ClassCategoryId = 1, ClassName = "TestClass", Location = "Trails", ProductCode = "C12345", DateStart = DateTime.Now, DateEnd = DateTime.Now
                });
                try
                {
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    Assert.Fail(exc.EntityValidationErrors.ToString());
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.FindOne(c => c.ClassName == "TestClass");
                Assert.IsNotNull(res);
            }
        }
Esempio n. 3
0
        private static int ImportCustomer(CsvReader csv)
        {
            int accointId = 0;

            //Import Parent
            ParentInfo p = new ParentInfo();

            p.FromCsv(csv);

            //
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParticipantRepo repo = new ParticipantRepo(dbContext);

                //If participant exist
                var existingParent = repo.GetAllParents().FirstOrDefault(x => x.LastName.ToLower() == p.LastName.ToLower() && x.Email == p.Email);
                if (existingParent != null)
                {
                    accointId = existingParent.AccountInfoId;
                    //TODO-1
                    //Update changes
                }
                else
                {
                    //repo.AddAccount(new AccountInfo { LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now});
                    p.AccountInfo = new AccountInfo {
                        LastName = p.LastName, Email = p.Email, DateApplied = DateTime.Now
                    };
                    repo.AddParent(p);
                }

                try
                {
                    //Save to DB
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    throw new DbEntityValidationException(String.Join("; ", validationErrorMessages));
                }
            }

            return(accointId);
        }
        public void ParticipantIntegationTests_AddParent()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <ParentInfo> validParents = new List <ParentInfo>()
                {
                    new ParentInfo()
                    {
                        LastName = "Skop", FirstName = "Serge", AccountInfoId = 1
                    },
                    new ParentInfo()
                    {
                        LastName = "Skop", FirstName = "Lily", AccountInfoId = 1
                    },
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var p in validParents)
                    {
                        repo.AddParent(p);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllParents().SingleOrDefault(p => p.LastName == "Skop" && p.FirstName == "Serge");
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <AccountInfo> validAccounts = new List <AccountInfo>()
                {
                    new AccountInfo()
                    {
                        LastName = "Skop", Email = "*****@*****.**", DateApplied = DateTime.Now
                    },
                    new AccountInfo()
                    {
                        LastName = "Skop", Email = "*****@*****.**", DateApplied = DateTime.Now
                    }
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var a in validAccounts)
                    {
                        repo.AddAccount(a);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllAccounts().SingleOrDefault(a => a.Email == validAccounts[0].Email);
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddStudent()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                List <StudentInfo> validStudents = new List <StudentInfo>()
                {
                    new StudentInfo()
                    {
                        LastName = "Skop", FirstName = "Abby", AccountInfoId = 1, Gender = "f", DateOfBirth = new DateTime(2010, 10, 12)
                    },
                    new StudentInfo()
                    {
                        LastName = "Skop", FirstName = "Max", AccountInfoId = 1, Gender = "m", DateOfBirth = new DateTime(2006, 7, 1)
                    },
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    foreach (var s in validStudents)
                    {
                        repo.AddStudent(s);
                    }
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var res = repo.GetAllStudents().SingleOrDefault(s => s.LastName == "Skop" && s.FirstName == "Abby");
                Assert.IsNotNull(res);
            }
        }
        public void ParticipantIntegationTests_AddParentWithAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParentInfo parent_1 = new ParentInfo()
                {
                    LastName = "Doe", FirstName = "John", Email = "*****@*****.**"
                };
                AccountInfo a = new AccountInfo {
                    LastName = parent_1.LastName, Email = parent_1.Email
                };
                parent_1.AccountInfo = a;

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    repo.AddParent(parent_1);
                    dbContext.SaveChanges();
                }
                catch (DbEntityValidationException exc)
                {
                    string[] validationErrorMessages = exc.EntityValidationErrors.Select(x => x.ValidationErrors.ToList()[0].ErrorMessage).ToArray();
                    Assert.Fail(String.Join("; ", validationErrorMessages));
                }
                catch (Exception exc)
                {
                    Assert.Fail(exc.ToString());
                }

                var parentRes_1 = repo.GetAllParents().SingleOrDefault(p => p.LastName == parent_1.LastName && p.FirstName == parent_1.FirstName);
                Assert.IsNotNull(parentRes_1, "Parent 1");

                Assert.IsNotNull(parentRes_1.AccountInfo, "AccountInfo is NULL");
                Assert.IsTrue(parentRes_1.AccountInfoId > 0, "AccountId");
            }
        }