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); }
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")); }
public void CheckLecturePermission(decimal lectureId) { if (LectureService.GetValues(lectureId, x => x.Group.Teacher_TC) != User.Employee_TC) { throw new PermissionException("lecture file"); } }
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); }
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()); }
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); }
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)); }
public IHttpActionResult GetLecture(int id) { var lecture = LectureService.GetLectureById(id); if (lecture == null) { return(NotFound()); } return(Ok(lecture)); }
public IHttpActionResult DeleteLecture(int id) { var result = LectureService.DeleteLecture(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
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; }
public IHttpActionResult PutLecture(int id, UpdateLectureDTO lecture) { var updateResult = LectureService.UpdateLecture(lecture); if (updateResult.Updated) { return(Ok(updateResult)); } return(StatusCode(HttpStatusCode.NoContent)); }
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")); }
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)); }
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); } }
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); }
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); }
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; }
public IEnumerable <GetLectureDTO> GetLecturesAvailableForEnroll() { var userId = HttpContext.Current.User.Identity.GetUserId <int>(); return(LectureService.GetLecturesAvailableForEnroll(userId)); }
public LecturesController(LectureService lectService) { _lectureService = lectService; }
public TimetableController(IUserDB userDB, LectureService lectureService, TokenDecoderService tokenDecoderService) { this.userDB = userDB; this.lectureService = lectureService; this.tokenDecoderService = tokenDecoderService; }
public async Task UpdateAsync_ValidCall() { await LectureService.UpdateAsync(_lectureDTO); Mock.Verify(m => m.Update(It.IsAny <Lecture>())); }
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); }
public async Task DeleteAsync_ValidCall() { await LectureService.DeleteAsync(It.IsAny <int>()); Mock.Verify(m => m.Delete(It.IsAny <Lecture>())); }