Esempio n. 1
0
        public ActionResult Homework()
        {
            checkLogin();

            HomeworkViewModel HVM = new HomeworkViewModel();

            HVM.groupSelectList        = StudentGroupService.getGroupSelectList(CP.currentTerm.ID);
            HVM.typeSelectList         = HomeworkService.getTypeSelectList();
            Session["groupSelectList"] = HVM.groupSelectList;
            Session["typeSelectList"]  = HVM.typeSelectList;

            HVM.termFilList         = genSelectList(CP.termSelectList, 0);
            HVM.groupFilList        = genSelectList(HVM.groupSelectList, 0);
            HVM.typeFilList         = genSelectList(HVM.typeSelectList, 0);
            Session["termFilList"]  = HVM.termFilList;
            Session["groupFilList"] = HVM.groupFilList;
            Session["typeFilList"]  = HVM.typeFilList;

            HVM.viewList = new List <HomeworkView>();

            ModelState.Clear();
            TempData["showForm2"] = false;
            TempData["showForm"]  = false;
            return(View(HVM));
        }
        public void UnitTestCreateStudentGroup()
        {
            var serv = new StudentGroupService();
            var stg  = new StudentGroup()
            {
                StudentGroupID = 1,
                Name           = "Bo",
            };

            var newStudentGroup = serv.Create(stg);

            Assert.AreEqual(stg.Name, "Bo");
        }
Esempio n. 3
0
        private void Initialize()
        {
            var exams         = new List <ExamCore>();
            var questions     = new List <Question>();
            var answers       = new List <Answer>();
            var students      = new List <Student>();
            var studentGropus = new List <StudentGroup>();
            var results       = new List <Result>();

            var mockDbSetExamCore     = GetMockDbSet <ExamCore>(exams);
            var mockDbSetQuestion     = GetMockDbSet <Question>(questions);
            var mockDbSetAnswer       = GetMockDbSet <Answer>(answers);
            var mockDbSetStudent      = GetMockDbSet <Student>(students);
            var mockDbSetStudentGroup = GetMockDbSet <StudentGroup>(studentGropus);
            var mockDbSetResult       = GetMockDbSet <Result>(results);

            mockDbSetAnswer.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => answers.FirstOrDefault(d => d.Id == (int)ids[0]));
            mockDbSetQuestion.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => questions.FirstOrDefault(d => d.Id == (int)ids[0]));
            mockDbSetExamCore.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => exams.FirstOrDefault(d => d.Id == (int)ids[0]));
            mockDbSetStudent.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => students.FirstOrDefault(d => d.Id == (int)ids[0]));
            mockDbSetStudentGroup.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => studentGropus.FirstOrDefault(d => d.Id == (int)ids[0]));
            mockDbSetResult.Setup(m => m.Find(It.IsAny <object[]>()))
            .Returns <object[]>(ids => results.FirstOrDefault(d => d.Id == (int)ids[0]));

            ctx.Setup(c => c.Set <ExamCore>()).Returns(mockDbSetExamCore.Object);
            ctx.Setup(c => c.Set <Question>()).Returns(mockDbSetQuestion.Object);
            ctx.Setup(c => c.Set <Answer>()).Returns(mockDbSetAnswer.Object);
            ctx.Setup(c => c.Set <Student>()).Returns(mockDbSetStudent.Object);
            ctx.Setup(c => c.Set <StudentGroup>()).Returns(mockDbSetStudentGroup.Object);
            ctx.Setup(c => c.Set <Result>()).Returns(mockDbSetResult.Object);

            ctx.Setup(c => c.Exams).Returns(mockDbSetExamCore.Object);
            ctx.Setup(c => c.Questions).Returns(mockDbSetQuestion.Object);
            ctx.Setup(c => c.Answer).Returns(mockDbSetAnswer.Object);
            ctx.Setup(c => c.Students).Returns(mockDbSetStudent.Object);
            ctx.Setup(c => c.StudentGroups).Returns(mockDbSetStudentGroup.Object);
            ctx.Setup(c => c.Results).Returns(mockDbSetResult.Object);


            answerService       = new AnswerService(fakectx);
            questionService     = new QuestionService(fakectx);
            examCoreService     = new ExamCoreService(fakectx, answerService, questionService);
            studentService      = new StudentService(fakectx);
            studentGroupService = new StudentGroupService(fakectx);
            resultService       = new ResultService(fakectx, studentGroupService);
        }
Esempio n. 4
0
        public ActionResult Homework(int SelectedTerm, int SelectedGroup, int SelectedType, HomeworkViewModel HVM)
        {
            checkLogin();

            HVM.groupSelectList = SelectedTerm == CP.currentTerm.ID ?
                                  (IEnumerable <SelectListItem>)Session["groupSelectList"] :
                                  StudentGroupService.getGroupSelectList(HVM.SelectedTerm);
            Session["groupSelectList"] = HVM.groupSelectList;
            HVM.typeSelectList         = (IEnumerable <SelectListItem>)Session["typeSelectList"];
            HVM.SelectedTerm           = SelectedTerm;
            HVM.SelectedGroup          = SelectedGroup;
            HVM.SelectedType           = SelectedType;
            HVM.termFilList            = genSelectList(CP.termSelectList, HVM.SelectedTerm);
            HVM.groupFilList           = genSelectList(HVM.groupSelectList, HVM.SelectedGroup);
            HVM.typeFilList            = genSelectList(HVM.typeSelectList, HVM.SelectedType);
            Session["termFilList"]     = HVM.termFilList;
            Session["groupFilList"]    = HVM.groupFilList;
            Session["typeFilList"]     = HVM.typeFilList;

            List <HOMEWORK>     works    = HomeworkService.GetFilteredWorks(HVM.SelectedTerm, HVM.SelectedGroup, HVM.SelectedType); //homeworks
            List <HomeworkView> viewList = new List <HomeworkView>();                                                               //homework in display format

            if (works != null && works.Any())
            {
                for (int h = 0; h < works.Count; h++) //put homeworks into display format
                {
                    HomeworkView view = new HomeworkView();
                    view.ID               = works[h].ID;
                    view.name             = works[h].NAME;
                    view.date_assign      = works[h].ADD_DATE;
                    view.date_due         = works[h].DUE_DATE;
                    view.full_mark        = works[h].FULL_MARK;
                    view.group_id         = works[h].STUDENT_GROUP;
                    view.type_id          = works[h].HOMEWORK_TYPE;
                    view.submission_ratio = works[h].SUBMISSION_RATIO;
                    view.late_ratio       = works[h].LATE_RATIO;
                    view.group_name       = view.group_id > 0 ? DBS.findRecordByID <STUDENT_GROUP>(works[h].STUDENT_GROUP).NAME : string.Empty;
                    view.type_name        = view.type_id > 0 ? DBS.findRecordByID <HOMEWORK_TYPE>(works[h].HOMEWORK_TYPE).NAME : string.Empty;

                    viewList.Add(view);
                }
            }

            HVM.viewList = viewList;

            ModelState.Clear();
            TempData["showForm2"] = false;
            TempData["showForm"]  = false;
            return(View("Homework", HVM));
        }
        public void TestGetAllStudentGroups()
        {
            var serv = new StudentGroupService();
            var stg  = new StudentGroup()
            {
                StudentGroupID = 1,
                Name           = "Test1",
            }; var stg2 = new StudentGroup()

            {
                StudentGroupID = 2,
                Name           = "Test2",
            };

            var newStg  = serv.Create(stg);
            var newStg2 = serv.Create(stg2);

            Assert.AreEqual(serv.GetAll().Count, 2);
        }
        public void TestDeleteStudentGroup()
        {
            var serv = new StudentGroupService();
            var stg  = new StudentGroup()
            {
                StudentGroupID = 1,
                Name           = "C#",
            }; var stg2 = new StudentGroup()

            {
                StudentGroupID = 2,
                Name           = "C#",
            };

            serv.Create(stg);
            serv.Create(stg2);

            serv.Delete(2);


            Assert.AreEqual(1, serv.GetAll().Count);
        }
        public void TestStudentGroupGetByID()
        {
            var serv = new StudentGroupService();
            var stg  = new StudentGroup()
            {
                StudentGroupID = 1,
                Name           = "C#",
            };
            var stg2 = new StudentGroup()
            {
                StudentGroupID = 2,
                Name           = "C++",
            };

            var newStg  = serv.Create(stg);
            var newStg2 = serv.Create(stg2);

            var group = serv.GetById(2);



            Assert.AreEqual("C++", group.Name);
        }
Esempio n. 8
0
        public void Insert_ExamCore()
        {
            ServiceTestsHelper  helper = new ServiceTestsHelper();
            StudentGroupService studentGroupService = helper.studentGroupService;

            var studentGroup = new StudentGroup()
            {
                Id   = 1,
                Name = "StudentGroup"
            };
            var studentGroup2 = new StudentGroup()
            {
                Id   = 1,
                Name = "StudentGroup2"
            };

            studentGroupService.Insert(studentGroup);
            studentGroupService.Insert(studentGroup2);


            var tmp = studentGroupService.GetAll();

            Assert.Equal(tmp.Count, 1);
        }
Esempio n. 9
0
 public GroupController(GroupContext context)
 {
     _service = new StudentGroupService(context);
 }
Esempio n. 10
0
        public async Task CreateStudentGroup()
        {
            //Arrange

            var newStudentGroup = new CreateStudentGroupDto()
            {
                Name       = "New_test_name",
                CourseId   = 2,
                StartDate  = DateTime.Now.Date,
                FinishDate = DateTime.Now.AddMonths(3).Date,
                StudentIds = new List <long>()
                {
                    1, 2, 3, 4
                },
                MentorIds = new List <long>()
                {
                    8, 9
                }
            };

            var existingStudentGroup = new CreateStudentGroupDto()
            {
                Name       = "Exists_test_name",
                CourseId   = 3,
                StartDate  = DateTime.Now.AddMonths(3).Date,
                FinishDate = DateTime.Now.AddMonths(6).Date,
                StudentIds = new List <long>()
                {
                    5, 6, 7, 8
                },
                MentorIds = new List <long>()
                {
                    10, 11
                }
            };

            var withoutMentorsAndStudentsStudentGroup = new CreateStudentGroupDto()
            {
                Name       = "Unique_test_name",
                CourseId   = 3,
                StartDate  = DateTime.Now.AddMonths(3).Date,
                FinishDate = DateTime.Now.AddMonths(6).Date,
                StudentIds = new List <long>(),
                MentorIds  = new List <long>()
            };

            var studentGroupRepositoryMock = new Mock <IStudentGroupRepository>();
            var studentsRepositoryMock     = new Mock <IStudentRepository>();
            var mentorsRepositoryMock      = new Mock <IMentorRepository>();

            studentGroupRepositoryMock.Setup(x => x.Add(It.IsAny <StudentGroup>()));

            studentsRepositoryMock.Setup(x => x.GetStudentsByIdsAsync(newStudentGroup.StudentIds))
            .ReturnsAsync(new List <Student>()
            {
                new Student {
                    Id = 1
                },
                new Student {
                    Id = 2
                },
                new Student {
                    Id = 3
                },
                new Student {
                    Id = 4
                }
            });

            mentorsRepositoryMock.Setup(x => x.GetMentorsByIdsAsync(newStudentGroup.MentorIds))
            .ReturnsAsync(new List <Mentor>()
            {
                new Mentor {
                    Id = 18
                },
                new Mentor {
                    Id = 19
                }
            });

            studentsRepositoryMock.Setup(x => x.GetStudentsByIdsAsync(withoutMentorsAndStudentsStudentGroup.StudentIds))
            .ReturnsAsync(new List <Student>());

            mentorsRepositoryMock.Setup(x => x.GetMentorsByIdsAsync(withoutMentorsAndStudentsStudentGroup.MentorIds))
            .ReturnsAsync(new List <Mentor>());

            studentGroupRepositoryMock.Setup(x => x.IsGroupNameExistAsync(newStudentGroup.Name))
            .ReturnsAsync(false);

            studentGroupRepositoryMock.Setup(x => x.IsGroupNameExistAsync(existingStudentGroup.Name))
            .ReturnsAsync(true);

            _unitOfWorkMock.Setup(x => x.StudentGroupRepository).Returns(studentGroupRepositoryMock.Object);
            _unitOfWorkMock.Setup(x => x.StudentRepository).Returns(studentsRepositoryMock.Object);
            _unitOfWorkMock.Setup(x => x.MentorRepository).Returns(mentorsRepositoryMock.Object);


            var studentGroupService = new StudentGroupService(
                _unitOfWorkMock.Object,
                _mapper,
                _loggerMock.Object
                );

            //Act

            var successResult = await studentGroupService.CreateStudentGroupAsync(newStudentGroup);

            var groupNameExistResult = await studentGroupService.CreateStudentGroupAsync(existingStudentGroup);

            var nullGroupResult = await studentGroupService.CreateStudentGroupAsync(null);

            var withoutMentorsAndStudentsGroupResult = await studentGroupService.CreateStudentGroupAsync(withoutMentorsAndStudentsStudentGroup);

            //Assert

            Assert.NotNull(successResult.Data);
            Assert.Equal(newStudentGroup.Name, successResult.Data.Name);

            Assert.Equal(ErrorCode.UnprocessableEntity, groupNameExistResult.Error.Code);

            Assert.Equal(ErrorCode.ValidationError, nullGroupResult.Error.Code);

            Assert.True(withoutMentorsAndStudentsGroupResult.Data.StudentIds.Count == 0);
            Assert.True(withoutMentorsAndStudentsGroupResult.Data.MentorIds.Count == 0);
        }
Esempio n. 11
0
        public async Task UpdateStudentGroup()
        {
            //Arrange

            long notExistingGroupId = -10;

            var updateStudentGroupDto = new UpdateStudentGroupDto()
            {
                Name       = "new_test_name",
                CourseId   = 2,
                StartDate  = DateTime.Now,
                FinishDate = DateTime.Now.AddMonths(3),
                StudentIds = new List <long>(),
                MentorIds  = new List <long>()
            };

            var existingNameStudentGroupDto = new UpdateStudentGroupDto()
            {
                Name       = "Test_name",
                CourseId   = 4,
                StartDate  = DateTime.Now,
                FinishDate = DateTime.Now.AddMonths(3),
                StudentIds = new List <long>(),
                MentorIds  = new List <long>()
            };

            var existingStudentGroup = new StudentGroup()
            {
                Id         = 10,
                Name       = "Test_name",
                CourseId   = 3,
                StartDate  = DateTime.Now.AddMonths(3),
                FinishDate = DateTime.Now.AddMonths(6),
                StudentsOfStudentGroups = new List <StudentOfStudentGroup>(),
                MentorsOfStudentGroups  = new List <MentorOfStudentGroup>()
            };

            var existingCourse = new Course()
            {
                Id   = 2,
                Name = "AAA"
            };

            var studentGroupRepositoryMock = new Mock <IStudentGroupRepository>();
            var studentsRepositoryMock     = new Mock <IStudentRepository>();
            var mentorsRepositoryMock      = new Mock <IMentorRepository>();
            var courseRepositoryMock       = new Mock <ICourseRepository>();

            studentGroupRepositoryMock.Setup(x => x.GetByIdAsync(existingStudentGroup.Id))
            .ReturnsAsync(existingStudentGroup);

            studentGroupRepositoryMock.Setup(x => x.GetByIdAsync(notExistingGroupId))
            .ReturnsAsync((StudentGroup)null);

            studentGroupRepositoryMock.Setup(x => x.IsGroupNameExistAsync(updateStudentGroupDto.Name))
            .ReturnsAsync(false);

            studentGroupRepositoryMock.Setup(x => x.IsGroupNameExistAsync(existingNameStudentGroupDto.Name))
            .ReturnsAsync(true);

            courseRepositoryMock.Setup(x => x.GetByIdAsync(updateStudentGroupDto.CourseId))
            .ReturnsAsync(existingCourse);

            studentGroupRepositoryMock.Setup(x => x.UpdateManyToMany(It.IsAny <IList <StudentOfStudentGroup> >(),
                                                                     It.IsAny <IList <StudentOfStudentGroup> >()));

            mentorsRepositoryMock.Setup(x => x.UpdateMentorGroups(It.IsAny <IList <MentorOfStudentGroup> >(),
                                                                  It.IsAny <IList <MentorOfStudentGroup> >()));

            _unitOfWorkMock.Setup(x => x.StudentGroupRepository).Returns(studentGroupRepositoryMock.Object);
            _unitOfWorkMock.Setup(x => x.StudentRepository).Returns(studentsRepositoryMock.Object);
            _unitOfWorkMock.Setup(x => x.MentorRepository).Returns(mentorsRepositoryMock.Object);
            _unitOfWorkMock.Setup(x => x.CourseRepository).Returns(courseRepositoryMock.Object);

            var studentGroupService = new StudentGroupService(
                _unitOfWorkMock.Object,
                _mapper,
                _loggerMock.Object
                );

            //Act

            var successResult = await studentGroupService.UpdateStudentGroupAsync(existingStudentGroup.Id, updateStudentGroupDto);

            var groupNameExistResult = await studentGroupService.UpdateStudentGroupAsync(existingStudentGroup.Id, existingNameStudentGroupDto);

            var groupNotExistResult = await studentGroupService.UpdateStudentGroupAsync(notExistingGroupId, updateStudentGroupDto);

            var nullGroupResult = await studentGroupService.UpdateStudentGroupAsync(existingStudentGroup.Id, null);

            //Assert

            Assert.NotNull(successResult.Data);
            Assert.Equal(successResult.Data.Name, successResult.Data.Name);

            Assert.Equal(ErrorCode.UnprocessableEntity, groupNameExistResult.Error.Code);

            Assert.Equal(ErrorCode.NotFound, groupNotExistResult.Error.Code);

            Assert.Equal(ErrorCode.ValidationError, nullGroupResult.Error.Code);
        }