Exemple #1
0
        void GivenBrendanHasActivities()
        {
            DropDatabase.DropDb();
            using (var context = new DemoContextFactory().Create())
            {
                var brendan = context.Students.FirstOrDefault(s => s.FirstName == "Brendan");

                Assert.NotNull(brendan);

                brendan.Activities.Add(new InSchoolActivity()
                {
                    Name      = "Computer Club",
                    ClassRoom = "1A"
                });
                brendan.Activities.Add(new InSchoolActivity()
                {
                    Name      = "Music Lessons",
                    ClassRoom = "C#"
                });
                brendan.Activities.Add(new OutsideSchoolActivity()
                {
                    Name = "Rowing Club",
                    ResponsiblePerson = "Mr Cox"
                });

                context.SaveChanges();
            }
        }
Exemple #2
0
        public void DoManyToManyTest()
        {
            DropDatabase.DropDb();

            using (var context = new DemoContextFactory().Create())
            {
                var brendan = context.Students.FirstOrDefault(s => s.FirstName == "Brendan");
                var adam    = context.Students.FirstOrDefault(s => s.FirstName == "Adam");

                var course = context.Courses.FirstOrDefault(c => c.Title == "How To Win");

                Assert.NotNull(brendan);
                Assert.NotNull(adam);
                Assert.NotNull(course);

                course.Students.Add(brendan);
                course.Students.Add(adam);

                context.SaveChanges();
            }


            using (var context2 = new DemoContextFactory().Create())
            {
                var course = context2.Courses.FirstOrDefault(c => c.Title == "How To Win");

                Assert.Equal(2, course.Students.Count());
            }
        }
Exemple #3
0
        public void DoOneToManyTest()
        {
            DropDatabase.DropDb();

            using (var context = new DemoContextFactory().Create())
            {
                var student = context.Students.FirstOrDefault(s => s.FirstName == "Brendan");

                Assert.NotNull(student);

                student.Enrolments.Add(new Enrolment()
                {
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddYears(1),
                    School    = context.Schools.FirstOrDefault(s => s.Name == "School Of Rock")
                });

                context.SaveChanges();
            }
        }
Exemple #4
0
        void GivenBrendanHasEnrolments()
        {
            DropDatabase.DropDb();
            using (var context = new DemoContextFactory().Create())
            {
                var brendan = context.Students.FirstOrDefault(s => s.FirstName == "Brendan");

                Assert.NotNull(brendan);

                brendan.Enrolments.Add(new Enrolment()
                {
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddYears(1)
                });

                brendan.Enrolments.Add(new Enrolment()
                {
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddYears(1)
                });

                context.SaveChanges();
            }
        }