Exemplo n.º 1
0
        public void ParticipantTests_GetAccount_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };

            Assert.IsTrue(repo.PrivateClassesDBContext.AccountInfoes.ToList().FirstOrDefault(x => x.LastName == "Skop") != null);
        }
Exemplo n.º 2
0
        public void ParticipantIntegationTests_GetAllAccounts()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParticipantRepo repo = new ParticipantRepo(dbContext);

                var res = repo.GetAllAccounts();
                Assert.IsTrue(res != null && res.Count > 0);
            }
        }
Exemplo n.º 3
0
        public void ParticipantTests_GetStudentParents_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };
            StudentInfo s   = repo.GetStudentById(1);
            var         res = repo.GetParentsByStudent(s);

            Assert.IsTrue(res != null && res.Count == 2);
        }
Exemplo n.º 4
0
        public void ParticipantTests_GetAllStudents_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };

            var res = repo.GetAllStudents();

            Assert.IsTrue(res != null && res.Count > 0);
            Assert.AreEqual(res[0].AccountInfoId, 1, "Account Info invalid");
        }
Exemplo n.º 5
0
        public string GetDebtsSummary(SettlementPlan plan)
        {
            StringBuilder builder = new StringBuilder();
            var           list    = plan.CalculateDebts();

            foreach (var d in list)
            {
                var p1 = ParticipantRepo.GetParticipant(d.PersonWhoOwes);
                var p2 = ParticipantRepo.GetParticipant(d.PersonWhoGetPayed);
                builder.AppendFormat("{0} needs to pay {1} {2} dollars\n", p1.DisplayName, p2.DisplayName, d.DebtAmount);
            }
            return(builder.ToString());
        }
Exemplo n.º 6
0
 public void ParticipantIntegationTests_GetAccountByStudent()
 {
     using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
     {
         ParticipantRepo repo    = new ParticipantRepo(dbContext);
         StudentInfo     student = new StudentInfo()
         {
             LastName = "Skop", FirstName = "Abby", AccountInfoId = 1, Gender = "f"
         };
         var res = repo.GetAllAccounts();
         Assert.IsTrue(res != null && res.Count > 0);
     }
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void ParticipantTests_AddStudent_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };
            //Mock Student
            StudentInfo s = new StudentInfo()
            {
                Id = 3, LastName = "Baravik", FirstName = "Ron", AccountInfoId = 2
            };
            int count1 = repo.PrivateClassesDBContext.StudentInfoes.Count();

            repo.AddStudent(s);

            int count2 = repo.PrivateClassesDBContext.StudentInfoes.Count();

            Assert.IsTrue(count2 == count1 + 1);
        }
Exemplo n.º 9
0
        public void ParticipantTests_AddParent_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };
            //Mock Parent
            ParentInfo p = new ParentInfo()
            {
                Id = 2, LastName = "Baravik", FirstName = "Mark", AccountInfoId = 2
            };
            int count1 = repo.PrivateClassesDBContext.ParentInfoes.Count();

            Assert.IsTrue(count1 == 2);

            repo.AddParent(p);

            int count2 = repo.PrivateClassesDBContext.ParentInfoes.Count();

            Assert.IsTrue(count2 == 3);
        }
Exemplo n.º 10
0
        public void ParticipantTests_AddAccount_Mock()
        {
            ParticipantRepo repo = new ParticipantRepo(GetMockContext().Object)
            {
                IncludeNavigationProperties = false
            };
            //Mock Account
            AccountInfo a = new AccountInfo()
            {
                Id = 2, LastName = "Baravik", DateApplied = DateTime.Now
            };
            int count1 = repo.PrivateClassesDBContext.AccountInfoes.Count();

            Assert.IsTrue(count1 == 1);

            repo.AddAccount(a);

            int count2 = repo.PrivateClassesDBContext.AccountInfoes.Count();

            Assert.IsTrue(count2 == 2);
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        public void ParticipantIntegationTests_AddSecondParentWithExistingAccount()
        {
            using (PrivateClassesDBContext dbContext = new PrivateClassesDBContext())
            {
                ParentInfo parent_2 = new ParentInfo()
                {
                    LastName = "Doe", FirstName = "Jane", Email = "*****@*****.**"
                };

                ParticipantRepo repo = new ParticipantRepo(dbContext);
                try
                {
                    //Get Account
                    var allAccounts = repo.GetAllAccounts();
                    var a           = allAccounts.SingleOrDefault(x => x.LastName == parent_2.LastName && x.Email.Trim() == parent_2.Email);
                    Assert.IsNotNull(a, "Account not found");
                    parent_2.AccountInfo = a;
                    //repo.AddParent(parent_2);
                    //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_2 = repo.GetAllParents().SingleOrDefault(p => p.LastName.Trim() == parent_2.LastName && p.FirstName.Trim() == parent_2.FirstName);
                Assert.IsNotNull(parentRes_2, "Parent 2");

                Assert.IsNotNull(parentRes_2.AccountInfo, "AccountInfo is NULL");
                Assert.IsTrue(parentRes_2.AccountInfoId > 0, "AccountId");
            }
        }
Exemplo n.º 15
0
        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");
            }
        }