Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public async Task CreateAsyncCreatesOneStudent()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Student>(dbFixture.dbContext);
            var service    = new UserService(null, repository);

            var student = this.dbFixture.dbContext.Students
                          .Where(s => s.User.FamilyName == "B")
                          .First();

            var userId = student.UserId;

            this.dbFixture.dbContext.Students.Remove(student);

            this.dbFixture.dbContext.SaveChanges();

            var studentCount = this.dbFixture.dbContext.Students.Count();

            await service.CreateAsync(new StudentBindingModel()
            {
                UserId       = userId,
                StudentUniId = 1,
                FacultyName  = FacultyOf.Biology,
                Major        = Major.Biotechnologies,
                GroupId      = "2"
            });

            Assert.Equal(studentCount + 1, dbFixture.dbContext.Students.Count());
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public async Task CreateAsyncCreatesOneEntity()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Assignment>(dbFixture.dbContext);
            var service    = new AssignmentService(repository);

            var assgnCount = this.dbFixture.dbContext.Assignments.Count();

            var lecturecise   = this.dbFixture.dbContext.Lecturecises.First();
            var lectureciseId = lecturecise.Id;

            var educator   = this.dbFixture.dbContext.Educator.First();
            var educatorId = educator.Id;

            await service.CreateAsync(new AssignmentCreateBindingModel()
            {
                Name          = "Assgn2",
                MaxGrade      = 10m,
                EducatorId    = educatorId,
                LectureciseId = lectureciseId
            });

            Assert.Equal(assgnCount + 1, dbFixture.dbContext.Assignments.Count());
        }
Exemplo n.º 5
0
        public void GetAllByStudentReturnsLecturecisesByStudentId()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Lecturecise>(this.dbFixture.dbContext);
            var service    = new LectureciseService(repository);

            Assert.Single(service.GetAllByStudent("student1"));
        }
Exemplo n.º 6
0
        public void GetAllGetsAllEducators()
        {
            BaseServiceTests.Initialize();

            var count = this.dbFixture.dbContext.Educator.Count();

            var repository = new DbRepository <Educator>(this.dbFixture.dbContext);
            var service    = new EducatorService(repository, null);

            Assert.Equal(count, service.GetAll().Count());
        }
Exemplo n.º 7
0
        public void GetAllGetsAllGroups()
        {
            BaseServiceTests.Initialize();

            var count = this.dbFixture.dbContext.Groups.Count();

            var repository = new DbRepository <Group>(this.dbFixture.dbContext);
            var service    = new GroupService(repository);

            Assert.Equal(count, service.GetAll().Count());
        }
Exemplo n.º 8
0
        public void GetAllGetsAllCourses()
        {
            BaseServiceTests.Initialize();

            var count = this.dbFixture.dbContext.Courses
                        .Where(l => l.IsDeleted == false).Count();

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            Assert.Equal(count, service.GetAll().Count());
        }
Exemplo n.º 9
0
        public void GetByIdOriginalReturnsNullIfIdNotFound()
        {
            BaseServiceTests.Initialize();

            var id = "NoSuchCourse";

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            var result = service.GetByIdOriginal(id);

            Assert.Null(result);
        }
Exemplo n.º 10
0
        public async Task CreateAsyncCreatesOneGroup()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Group>(dbFixture.dbContext);
            var service    = new GroupService(repository);

            var groupCount = this.dbFixture.dbContext.Groups.Count();

            await service.CreateAsync(new GroupViewModel());

            Assert.Equal(groupCount + 1, dbFixture.dbContext.Groups.Count());
        }
Exemplo n.º 11
0
        public void GetByIdOriginalGetsTheCourseWithTheGivenId()
        {
            BaseServiceTests.Initialize();

            var id = "test1";

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            var result = service.GetByIdOriginal(id);

            Assert.Equal(id, result.Id);
        }
Exemplo n.º 12
0
        public void GetByCourseIdGetsCourseWithTheGivenId()
        {
            var courseId = "test1";

            BaseServiceTests.Initialize();

            var countWithId = this.dbFixture.dbContext.Courses
                              .Where(c => c.Id == courseId && c.IsDeleted == false).Count();

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            Assert.Equal(countWithId, service.GetCourseById(courseId).Id);
        }
Exemplo n.º 13
0
        public void GetByIdGetsEducatorWithTheGivenUserId()
        {
            BaseServiceTests.Initialize();

            var userId = this.dbFixture.dbContext.Educator
                         .Where(l => l.IsDeleted == false).Select(l => l.UserId).First();

            var repository = new DbRepository <Educator>(this.dbFixture.dbContext);
            var service    = new EducatorService(repository, null);

            var result = service.GetByUserId(userId);

            Assert.Equal(userId, result.UserId);
        }
Exemplo n.º 14
0
        public async Task GetByCourseIdReturnsNullWhenNoCourseWithTheGivenIdExists()
        {
            var courseId = "NoSuchId";

            BaseServiceTests.Initialize();

            var countWithId = this.dbFixture.dbContext.Courses
                              .Where(c => c.Id == courseId && c.IsDeleted == false).Count();

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            Assert.Null(await service.GetCourseById(courseId));
        }
Exemplo n.º 15
0
        public void GetByIdOriginalGetsAssignmentWithTheGivenId()
        {
            BaseServiceTests.Initialize();

            var id = this.dbFixture.dbContext.Assignments
                     .Where(l => l.IsDeleted == false).Select(l => l.Id).First();

            var repository = new DbRepository <Assignment>(this.dbFixture.dbContext);
            var service    = new AssignmentService(repository);

            var result = service.GetByIdOriginal(id);

            Assert.Equal(id, result.Id);
        }
Exemplo n.º 16
0
        public void GetByCourseIdReturnsAllCoursesWithTheGivenId()
        {
            var courseId = "test";

            BaseServiceTests.Initialize();

            var countWithId = this.dbFixture.dbContext.Assignments
                              .Where(a => a.IsDeleted == false && a.Lecturecise.CourseId == courseId).Count();

            var repository = new DbRepository <Assignment>(this.dbFixture.dbContext);
            var service    = new AssignmentService(repository);

            Assert.Equal(countWithId, service.GetByCourseId(courseId).Count());
        }
Exemplo n.º 17
0
        public void GetByCourseIdGetsAllAndOnlyWithTheGivenId()
        {
            var courseId = "test";

            BaseServiceTests.Initialize();

            var countWithId = this.dbFixture.dbContext.Lecturecises
                              .Where(l => l.CourseId == courseId && l.IsDeleted == false).Count();

            var repository = new DbRepository <Lecturecise>(this.dbFixture.dbContext);
            var service    = new LectureciseService(repository);

            Assert.Equal(countWithId, service.GetByCourseId(courseId).Count());
            Assert.Equal(countWithId, service.GetByCourseId(courseId).Where(l => l.CourseId == courseId).Count());
        }
        public void GetStudentAssignmentsByStudentIdReturnsAllStudentAssignmentsWithTheGivenStudentId()
        {
            BaseServiceTests.Initialize();

            var studentId = "student2";

            var countAssgnWithId = this.dbFixture.dbContext.StudentAssignments
                                   .Where(sa => sa.StudentId == studentId)
                                   .Count();

            var repository = new DbRepository <StudentAssignment>(this.dbFixture.dbContext);
            var service    = new StudentAssignmentService(repository);

            Assert.Equal(countAssgnWithId, service.GetStudentAssignmentsByStudentId(studentId).Count());
        }
Exemplo n.º 19
0
        public async Task GetByIdGetsReturnsNullIfIdNotFound()
        {
            BaseServiceTests.Initialize();

            var ids = this.dbFixture.dbContext.Lecturecises
                      .Where(l => l.IsDeleted == false).Select(l => l.Id).ToList();

            var repository = new DbRepository <Lecturecise>(this.dbFixture.dbContext);
            var service    = new LectureciseService(repository);

            var testId = "notGuid";

            var result = await service.GetById(testId);

            Assert.Null(result);
        }
Exemplo n.º 20
0
        [Fact] void GetAllByEducatorReturnsAllCoursesOfTheEducatorWithTheGivenId()
        {
            var educatorId = this.dbFixture.dbContext.Educator
                             .Where(e => e.User.FamilyName == "V").First().Id;

            BaseServiceTests.Initialize();

            var countCoursesWithEducatorId = this.dbFixture.dbContext.Courses
                                             .Where(c => c.CourseEducators.Any(e => e.EducatorId == educatorId &&
                                                                               c.IsDeleted == false)).Count();

            var repository = new DbRepository <Course>(this.dbFixture.dbContext);
            var service    = new CourseService(repository);

            Assert.Equal(countCoursesWithEducatorId, service.GetAllByEducator(educatorId).Count());
        }
Exemplo n.º 21
0
        public async Task CreateAsyncCreatesOneEntity()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Lecturecise>(dbFixture.dbContext);
            var service    = new LectureciseService(repository);

            var lectureciseCount = this.dbFixture.dbContext.Lecturecises.Count();

            await service.CreateAsync(new LectureciseCreateBindingModel()
            {
                CourseId = Guid.NewGuid().ToString(),
                Type     = LectureciseType.Excercise
            });

            Assert.Equal(lectureciseCount + 1, dbFixture.dbContext.Lecturecises.Count());
        }
Exemplo n.º 22
0
        public async Task GetByIdGetsTheEntityWithTheGivenId()
        {
            BaseServiceTests.Initialize();

            var ids = this.dbFixture.dbContext.Lecturecises
                      .Where(l => l.IsDeleted == false).Select(l => l.Id).ToList();

            var repository = new DbRepository <Lecturecise>(this.dbFixture.dbContext);
            var service    = new LectureciseService(repository);

            foreach (var id in ids)
            {
                var result = await service.GetById(id);

                Assert.Equal(id, result.Id);
            }
        }
Exemplo n.º 23
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);
            }
        }
Exemplo n.º 24
0
        public async Task CreateAsyncCreatesOneCourse()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Course>(dbFixture.dbContext);
            var service    = new CourseService(repository);

            var courseCount = this.dbFixture.dbContext.Courses.Count();

            await service.CreateAsync(new CourseCreateBindingModel()
            {
                Name     = "course1",
                Semester = Semester.Summer,
                Year     = "2017/2018",
                Major    = Major.Mixed
            });

            Assert.Equal(courseCount + 1, dbFixture.dbContext.Courses.Count());
        }
Exemplo n.º 25
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);
            }
        }
Exemplo n.º 26
0
        public async Task CreateAsyncCreatesOneEducator()
        {
            BaseServiceTests.Initialize();

            var repository = new DbRepository <Educator>(dbFixture.dbContext);
            var service    = new EducatorService(repository, null);

            var educatorCount = this.dbFixture.dbContext.Educator.Count();

            var userId = this.dbFixture.dbContext.Users
                         .Where(u => u.FirstName == "V").First().Id;

            await service.CreateAsync(new EducatorBindingModel()
            {
                UserId      = userId,
                FacultyName = FacultyOf.Physics
            });

            Assert.Equal(educatorCount + 1, dbFixture.dbContext.Educator.Count());
        }
Exemplo n.º 27
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);
            }
        }
Exemplo n.º 28
0
        public void GetAllByStudentReturnsLecturecisesByEducatorId()
        {
            BaseServiceTests.Initialize();

            var lectureRepository = new Mock <IRepository <Lecturecise> >();

            lectureRepository.Setup(r => r.All())
            .Returns(
                new List <Lecturecise>()
            {
                new Lecturecise()
                {
                    Id       = "rand1",
                    CourseId = "rand",
                    Course   = new Course()
                    {
                        Name = "N", Year = "2017/2018", Semester = Semester.Summer, Major = Major.Biotechnologies
                    },
                    Type      = LectureciseType.Excercise,
                    IsDeleted = false,
                    WeekTimes = new List <WeekTime>()
                    {
                        new WeekTime()
                        {
                            DayOfWeek = DayOfWeek.Friday, StartHour = "12"
                        }
                    },
                    LectureciseStudents = new List <StudentLecturecise>()
                    {
                        new StudentLecturecise()
                        {
                            LectureciseId = "rand1", StudentId = "student1"
                        }
                    },
                    LectureciseEducators = new List <EducatorLecturecise>()
                    {
                        new EducatorLecturecise()
                        {
                            LectureciseId = "rand1",
                            EducatorId    = "edu1",
                            Educator      = new Educator()
                            {
                                UserId = "some1", FacultyName = FacultyOf.Biology
                                , User = new LMSAppUser()
                                {
                                    FamilyName = "V", FirstName = "V"
                                }
                            }
                        }
                    }
                },
                new Lecturecise()
                {
                    Id       = "rand2",
                    CourseId = "rand",
                    Course   = new Course()
                    {
                        Name = "N", Year = "2017/2018", Semester = Semester.Summer, Major = Major.Biotechnologies
                    },
                    Type      = LectureciseType.Excercise,
                    IsDeleted = false,
                    WeekTimes = new List <WeekTime>()
                    {
                        new WeekTime()
                        {
                            DayOfWeek = DayOfWeek.Friday, StartHour = "12"
                        }
                    },
                    LectureciseStudents = new List <StudentLecturecise>()
                    {
                        new StudentLecturecise()
                        {
                            LectureciseId = "rand2", StudentId = "student2"
                        }
                    },
                    LectureciseEducators = new List <EducatorLecturecise>()
                    {
                        new EducatorLecturecise()
                        {
                            LectureciseId = "rand2",
                            EducatorId    = "edu2",
                            Educator      = new Educator()
                            {
                                UserId = "some2", FacultyName = FacultyOf.Biology
                                , User = new LMSAppUser()
                                {
                                    FamilyName = "U", FirstName = "U"
                                }
                            }
                        }
                    }
                }
            }
                .AsQueryable());

            var service = new LectureciseService(lectureRepository.Object);

            Assert.Single(service.GetAllByEducator("edu1"));
        }