Beispiel #1
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");
        }
        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);
            }
        }