public void Setup()
        {
            Repository         = new Mock <ILectureRepository>();
            CourseRepository   = new Mock <ICourseRepository>();
            StudentRepository  = new Mock <IStudentRepository>();
            HomeworkRepository = new Mock <IHomeworkRepository>();
            LecturerRepository = new Mock <ILecturerRepository>();

            UnitOfWork = new Mock <IUnitOfWork>();

            Logger = new Mock <ILogger <LectureService> >();

            UnitOfWork.SetupGet(x => x.Lectures)
            .Returns(Repository.Object);

            UnitOfWork.SetupGet(x => x.Students)
            .Returns(StudentRepository.Object);

            UnitOfWork.SetupGet(x => x.Courses)
            .Returns(CourseRepository.Object);

            UnitOfWork.SetupGet(x => x.Homeworks)
            .Returns(HomeworkRepository.Object);

            UnitOfWork.SetupGet(x => x.Lecturers)
            .Returns(LecturerRepository.Object);

            Service = new LectureService(UnitOfWork.Object, Logger.Object);
        }
Exemple #2
0
        public ActionResult Calendar(decimal groupId)
        {
            var group = GroupService.GetByPK(groupId);

            if (group == null)
            {
                return(null);
            }
            var lectures = LectureService.GetAll(x => x.Group_ID == groupId).ToList();

            if (!lectures.Any())
            {
                lectures.Add(new Lecture {
                    LectureDateBeg = group.DateBeg.Value,
                    LectureDateEnd = group.DateEnd.Value
                });
            }
            var result = EntityUtils.GetCalendar(lectures.Select(x =>
                                                                 new CalData(x.LectureDateBeg, x.LectureDateEnd,
                                                                             group.Complex.GetOrDefault(z => z.Address), group.Title)).ToList());
            var encoding = new System.Text.UTF8Encoding();

            return(File(encoding.GetBytes(result), "text/calendar",
                        "group" + groupId + ".ics"));
        }
Exemple #3
0
 public void CheckLecturePermission(decimal lectureId)
 {
     if (LectureService.GetValues(lectureId, x => x.Group.Teacher_TC) != User.Employee_TC)
     {
         throw new PermissionException("lecture file");
     }
 }
Exemple #4
0
        public void UpdateAsync_ThrowsValidationException()
        {
            Mock.Setup(repo => repo.GetAsync(It.IsAny <int>()))
            .Returns(GetExceptionTest());

            Assert.ThrowsAsync <ValidationException>(async() => await LectureService
                                                     .UpdateAsync(_lectureDTO));
        }
        public void Initialize()
        {
            string connectionString = "Server=den1.mssql7.gear.host; Database=dotnottests;User Id=dotnottests;Password=Ky4DwF?7-YQY;";
            var    builder          = new DbContextOptionsBuilder <ScheduleContext>().UseSqlServer(connectionString);

            context        = new ScheduleContext(builder.Options);
            lectureService = new LectureService(context, context);
        }
Exemple #6
0
        public void SetUp()
        {
            Mock = new Mock <IRepository <Lecture> >();
            Mock.Setup(repo => repo.GetAllAsync()).Returns(GetAllTest());
            Mock.Setup(repo => repo.GetAsync(It.IsAny <int>()))
            .Returns(GetTest());

            LectureService = new LectureService(Mock.Object, new MapperBll(), new NullLoggerFactory());
        }
Exemple #7
0
        public void GetAsync_ValidCall()
        {
            const int id      = 1;
            var       lecture = LectureService.GetAsync(id).Result;

            Mock.Verify(m => m.GetAsync(id));
            Assert.AreEqual(GetTest().Result.Id, lecture.Id);
            Assert.AreEqual(GetTest().Result.Name, lecture.Name);
            Assert.AreEqual(GetTest().Result.ProfessorId, lecture.ProfessorId);
        }
Exemple #8
0
        public IEnumerable <GetLectureDTO> GetLectures()
        {
            var userId = HttpContext.Current.User.Identity.GetUserId <int>();

            var role = ((ClaimsIdentity)User.Identity).Claims
                       .Where(c => c.Type == ClaimTypes.Role)
                       .Select(c => c.Value).FirstOrDefault();

            return(LectureService.GetLectures(userId, role));
        }
Exemple #9
0
        public IHttpActionResult GetLecture(int id)
        {
            var lecture = LectureService.GetLectureById(id);

            if (lecture == null)
            {
                return(NotFound());
            }

            return(Ok(lecture));
        }
Exemple #10
0
        public IHttpActionResult DeleteLecture(int id)
        {
            var result = LectureService.DeleteLecture(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Exemple #11
0
 public LectureController(ApplicationDbContext context, CourseService courseService, IWebHostEnvironment environment, LectureService lectureService, UserManager <ApplicationUser> userManager, AccessService access, EmailService email, SmsService sms)
 {
     _context        = context;
     _courseService  = courseService;
     _environment    = environment;
     _lectureService = lectureService;
     _userManager    = userManager;
     _access         = access;
     _email          = email;
     _sms            = sms;
 }
Exemple #12
0
        public IHttpActionResult PutLecture(int id, UpdateLectureDTO lecture)
        {
            var updateResult = LectureService.UpdateLecture(lecture);

            if (updateResult.Updated)
            {
                return(Ok(updateResult));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #13
0
        public ActionResult TimeSheetCalendar(string tc)
        {
            var dateBegin = DateUtils.FirstMonthDay(DateTime.Today);
            var dateEnd   = DateUtils.LastMonthDay(dateBegin.AddMonths(1));
            var lectures  = LectureService.GetLmsLectures(dateBegin, dateEnd, tc.ToUpper());
            var data      = lectures.Select(x => new CalData(x.LectureDateBeg, x.LectureDateEnd,
                                                             x.ClassRoom_TC, x.Course_TC)).ToList();
            var result = EntityUtils.GetCalendar(data);

            return(Content(result, "text/calendar"));
        }
Exemple #14
0
        public ActionResult GroupFiles(decimal?groupId)
        {
            var lectures   = LectureService.GetAll(x => x.Group_ID == groupId.GetValueOrDefault()).ToList();
            var lectureIds = lectures.Select(x => x.Lecture_ID).ToList();
            var model      = new LectureFilesVM {
                Lectures = lectures,
                GroupId  = groupId,
                Files    = LectureFileService.GetAll(x => lectureIds.Contains(x.Lecture_ID)).ToList()
            };

            return(BaseViewWithModel(new LectureFilesView(), model));
        }
Exemple #15
0
        public void GetAllAsync_ValidCall()
        {
            var lectures = LectureService.GetAllAsync().Result.ToList();

            Mock.Verify(m => m.GetAllAsync());

            for (var i = 1; i < GetAllTest().Result.Count(); ++i)
            {
                Assert.AreEqual(GetAllTest().Result.ToList()[i].Id, lectures[i].Id);
                Assert.AreEqual(GetAllTest().Result.ToList()[i].Name, lectures[i].Name);
                Assert.AreEqual(GetAllTest().Result.ToList()[i].ProfessorId, lectures[i].ProfessorId);
            }
        }
Exemple #16
0
        public XDocument Get(UrlHelper urlHelper)
        {
            _url          = urlHelper;
            _directions   = CourseDirectionService.GetAll().ToDictionary(x => x.CourseDirectionA_TC, x => x.DirectionAName);
            _lectureCount = LectureService.GetAll(x =>
                                                  x.Group.DateBeg >= DateTime.Today &&
                                                  Colors.ForSite.Contains(x.Group.Color_TC) &&
                                                  x.Group.LectureType_TC == LectureTypes.Planned)
                            .GroupBy(x => x.Group_ID).Select(x => new { x.Key, Count = x.Count() }).ToList().ToDictionary(x => x.Key, x => x.Count);
            var yaml =
                new XDocument(Programs());

            return(yaml);
        }
Exemple #17
0
        public IHttpActionResult PostLecture(NewLectureDTO lecture)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = LectureService.AddLecture(lecture);

            if (!result.Created)
            {
                return(BadRequest("Adding lecture error. Try again."));
            }

            return(CreatedAtRoute("GetLecture", new { id = result.Lecture.LectureId }, result.Lecture));
        }
        public void CallDAtabaseContext_SaveMethod()
        {
            // Arrange
            var mockDbContext = new Mock <IDatabaseContext>();

            mockDbContext.Setup(c => c.Save()).Returns(1).Verifiable();

            var lectureService = new LectureService(mockDbContext.Object);

            // Act
            var result = lectureService.Save();

            // Assert
            Assert.AreEqual(1, result);
            mockDbContext.Verify(c => c.Save(), Times.Once);
        }
Exemple #19
0
        public async Task AddLectureTest(LectureDto lectureDto, Lecture expected)
        {
            // Arrange
            Mock <ICrudRepository <Lecture> > repositoryMock = new();
            var loggerMock = new Mock <ILogger <LectureService> >();
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(mapper => mapper.Map <Lecture>(lectureDto)).Returns(expected);
            var service = new LectureService(repositoryMock.Object, mapperMock.Object, loggerMock.Object);

            // Act
            int id = await service.AddLecture(lectureDto);

            // Assert
            Assert.That(id, Is.EqualTo(expected.Id));
            repositoryMock.Verify(repository => repository.SaveAsync(expected, It.IsAny <CancellationToken>()));
            repositoryMock.VerifyNoOtherCalls();
        }
        public void ReturnNull_IfLectureNotFound()
        {
            // Arrange
            var lectures      = this.GetLectures();
            var mockDbContext = new Mock <IDatabaseContext>();
            var mockSet       = new Mock <IDbSet <Lecture> >();

            mockSet.As <IQueryable <Lecture> >().Setup(m => m.Provider).Returns(lectures.Provider);
            mockSet.As <IQueryable <Lecture> >().Setup(m => m.Expression).Returns(lectures.Expression);
            mockSet.As <IQueryable <Lecture> >().Setup(m => m.ElementType).Returns(lectures.ElementType);

            mockDbContext.Setup(c => c.Lectures).Returns(mockSet.Object);

            var lectureId      = Guid.NewGuid().ToString();
            var lectureService = new LectureService(mockDbContext.Object);

            // Act
            var lecture = lectureService.FindById(lectureId);

            // Assert
            Assert.IsNull(lecture);
        }
        public void ReturnRightLecture()
        {
            // Arrange
            var lectures      = this.GetLectures();
            var mockDbContext = new Mock <IDatabaseContext>();
            var mockSet       = new Mock <IDbSet <Lecture> >();

            mockSet.As <IQueryable <Lecture> >().Setup(m => m.Provider).Returns(lectures.Provider);
            mockSet.As <IQueryable <Lecture> >().Setup(m => m.Expression).Returns(lectures.Expression);
            mockSet.As <IQueryable <Lecture> >().Setup(m => m.ElementType).Returns(lectures.ElementType);

            mockDbContext.Setup(c => c.Lectures).Returns(mockSet.Object);

            var lectureService = new LectureService(mockDbContext.Object);

            // Act
            var lecture = lectureService.FindById(this.searchedLectureId);

            // Assert
            Assert.AreEqual(this.lecturesTitle, lecture.Title);
            Assert.AreEqual(this.searchedLectureId, lecture.Id);
        }
 public LecturesController(LectureService serviceLecture, ProfessorService professorService, DepartmentService departmentService)
 {
     _serviceLecture    = serviceLecture;
     _professorService  = professorService;
     _departmentService = departmentService;
 }
Exemple #23
0
        public IEnumerable <GetLectureDTO> GetLecturesAvailableForEnroll()
        {
            var userId = HttpContext.Current.User.Identity.GetUserId <int>();

            return(LectureService.GetLecturesAvailableForEnroll(userId));
        }
Exemple #24
0
 public LecturesController(LectureService lectService)
 {
     _lectureService = lectService;
 }
Exemple #25
0
 public TimetableController(IUserDB userDB, LectureService lectureService, TokenDecoderService tokenDecoderService)
 {
     this.userDB              = userDB;
     this.lectureService      = lectureService;
     this.tokenDecoderService = tokenDecoderService;
 }
Exemple #26
0
        public async Task UpdateAsync_ValidCall()
        {
            await LectureService.UpdateAsync(_lectureDTO);

            Mock.Verify(m => m.Update(It.IsAny <Lecture>()));
        }
Exemple #27
0
        public void GetAllAsync_ThrowsValidationException()
        {
            Mock.Setup(repo => repo.GetAllAsync()).Returns(GetAllExceptionTest());

            Assert.ThrowsAsync <ValidationException>(async() => await LectureService.GetAllAsync());
        }
 public StudentsController()
 {
     _unitOfWork     = new UnitOfWork();
     _studentService = new StudentService(_unitOfWork);
     _lectureService = new LectureService(_unitOfWork);
 }
Exemple #29
0
        public async Task DeleteAsync_ValidCall()
        {
            await LectureService.DeleteAsync(It.IsAny <int>());

            Mock.Verify(m => m.Delete(It.IsAny <Lecture>()));
        }