Exemple #1
0
        public async Task DeleteCourseByIdMarksTheCourseAsDeleted()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateCourse_Database2")
                          .Options;

            BaseServiceTests.Initialize();

            string courseId = "delete1";

            using (var context = new LMSAppContext(options))
            {
                context.Courses.Add(new Course()
                {
                    Id               = courseId,
                    Name             = "delete1",
                    Semester         = Semester.Summer,
                    Year             = "2010/2011",
                    Major            = Major.Mixed,
                    StudentsInCourse = new List <StudentCourse>()
                });

                context.SaveChanges();
            }

            using (var context = new LMSAppContext(options))
            {
                var repository = new DbRepository <Course>(context);
                var service    = new CourseService(repository);

                await service.DeleteCourseById(courseId);

                Assert.True(context.Courses.First().IsDeleted);
            }
        }
Exemple #2
0
        private void InitializeGroups()
        {
            this.dbContext.Groups.Add(new Group()
            {
                Id     = "1",
                Number = 1,
                Major  = Major.Mixed
            });

            this.dbContext.Groups.Add(new Group()
            {
                Id     = "2",
                Number = 2,
                Major  = Major.Biotechnologies
            });

            this.dbContext.Groups.Add(new Group()
            {
                Id     = "3",
                Number = 3,
                Major  = Major.MolecularBiology
            });

            dbContext.SaveChanges();
        }
        public async Task DeleteLectureciseByIdReturnsNullIfObjectAlreadyDeleted()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database3")
                          .Options;

            BaseServiceTests.Initialize();

            string lectureciseId = null;

            using (var context = new LMSAppContext(options))
            {
                context.Lecturecises.Add(new Lecturecise()
                {
                    CourseId  = "1",
                    Type      = LectureciseType.Excercise,
                    IsDeleted = true
                }
                                         );

                context.SaveChanges();

                lectureciseId = context.Lecturecises.Where(l => l.CourseId == "1").First().Id;
            }

            using (var context = new LMSAppContext(options))
            {
                var repository = new DbRepository <Lecturecise>(context);
                var service    = new LectureciseService(repository);

                var courseId = await service.DeleteLectureciseById(lectureciseId);

                Assert.Null(courseId);
            }
        }
Exemple #4
0
        public async Task EditCourseByIdChangesCourseAndStoresChanges()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateCourse_Database1")
                          .Options;

            BaseServiceTests.Initialize();

            string courseId = "edit2";

            using (var context = new LMSAppContext(options))
            {
                context.Courses.Add(new Course()
                {
                    Id               = courseId,
                    Name             = "edit2",
                    Semester         = Semester.Summer,
                    Year             = "2010/2011",
                    Major            = Major.Mixed,
                    StudentsInCourse = new List <StudentCourse>()
                });

                context.SaveChanges();
            }

            var newYear = "2011/2012";

            var courseModel = new CourseDetailsViewModel()
            {
                Id               = courseId,
                Name             = "edit2",
                Semester         = Semester.Summer,
                Year             = newYear,
                Major            = Major.Mixed,
                StudentsInCourse = new List <StudentCourse>()
            };

            using (var context = new LMSAppContext(options))
            {
                var repository = new DbRepository <Course>(context);
                var service    = new CourseService(repository);
                await service.EditCourseById(courseModel);

                Assert.Equal(newYear, context.Courses.First().Year);
            }
        }
        public async Task EditLectureciseChangesAndStoresChanges()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database2")
                          .Options;

            BaseServiceTests.Initialize();

            string lectureciseId = null;

            using (var context = new LMSAppContext(options))
            {
                context.Lecturecises.Add(new Lecturecise()
                {
                    CourseId = "1",
                    Type     = LectureciseType.Excercise
                }
                                         );

                context.SaveChanges();

                lectureciseId = context.Lecturecises.Where(l => l.CourseId == "1").First().Id;
            }

            var newCourseId = "2";

            var lectureciseModel = new LectureciseDetailsViewModel()
            {
                Id       = lectureciseId,
                CourseId = newCourseId,
                Type     = LectureciseType.Excercise
            };

            using (var context = new LMSAppContext(options))
            {
                var repository = new DbRepository <Lecturecise>(context);
                var service    = new LectureciseService(repository);
                await service.EditLecturecise(lectureciseModel);

                Assert.Equal(newCourseId, context.Lecturecises.First().CourseId);
            }
        }
        public async Task DeleteByIdMarksTheWeekTimeInstanceAsDeleted()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateWeekTime_Database1")
                          .Options;

            //BaseServiceTests.Initialize();

            int weekTimeId;

            using (var context = new LMSAppContext(options))
            {
                context.WeekTimes.Add(new WeekTime()
                {
                    DayOfWeek = DayOfWeek.Friday,
                    StartHour = "14h"
                }
                                      );

                context.SaveChanges();

                var weekTime = await context.WeekTimes.FirstAsync();

                weekTimeId = weekTime.Id;
            }

            using (var context = new LMSAppContext(options))
            {
                var repository = new DbRepository <WeekTime>(context);
                var service    = new WeekTimeService(repository);

                await service.DeleteById(weekTimeId);

                Assert.True(context.WeekTimes.First().IsDeleted);
            }
        }