예제 #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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
 public RoleSeeder(
     LMSAppContext context,
     UserManager <LMSAppUser> userManager,
     RoleManager <IdentityRole> roleManager)
 {
     this.context      = context;
     this.userManager  = userManager;
     this.rolesManager = roleManager;
 }
예제 #4
0
        public DatabaseGroupFixture()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CommonGroup_Database")
                          .Options;

            this.dbContext = new LMSAppContext(options);

            InitializeGroups().GetAwaiter().GetResult();
        }
예제 #5
0
        public DatabaseCourseFixture()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CommonCourse_Database")
                          .Options;

            this.dbContext = new LMSAppContext(options);

            InitializeEducators().GetAwaiter().GetResult();

            InitializeLecturecises().GetAwaiter().GetResult();
        }
예제 #6
0
        public DatabaseEducatorFixture()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CommonEducator_Database")
                          .Options;

            this.dbContext = new LMSAppContext(options);

            InitializeEducators().GetAwaiter().GetResult();

            ClearOneEducatorToHaveOneUser();
        }
예제 #7
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);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        public async Task CreateAsyncCreatesEntityWithTheGivenValues()
        {
            var options = new DbContextOptionsBuilder <LMSAppContext>()
                          .UseInMemoryDatabase(databaseName: "CreateLecturecise_Database1")
                          .Options;

            BaseServiceTests.Initialize();

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

                await service.CreateAsync(new LectureciseCreateBindingModel()
                {
                    CourseId = "1",
                    Type     = LectureciseType.Excercise
                }
                                          );

                Assert.Equal("1", dbContext.Lecturecises.FirstOrDefault().CourseId);
                Assert.Equal(LectureciseType.Excercise, dbContext.Lecturecises.FirstOrDefault().Type);
            }
        }
예제 #10
0
        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);
            }
        }