Exemple #1
0
        public ActionResult GetRandomLesson()
        {
            var service = new LessonService();
            var lesson  = service.GetRandomLessonFromList();

            return(View(lesson));
        }
            public async Task CreateLessonEdited_CreatedEdited(string id)
            {
                var repo = new Mock<IDocumentDBRepository<Lesson>>();

                var lessonExisting = lessonList.FirstOrDefault(L => L.Id == id).Description;
                repo.Setup(c => c.GetByIdAsync(
                    It.IsAny<string>(),
                    It.IsAny<Dictionary<string, string>>()
                )).ReturnsAsync(
                    (string id, Dictionary<string, string> pk) => lessonList.FirstOrDefault());

                repo.Setup(c => c.CreateAsync(
                    It.IsAny<Lesson>(),
                    It.IsAny<EventGridOptions>(),
                    It.IsAny<string>(),
                    It.IsAny<string>()
                    )).ReturnsAsync(
                    (Lesson L, EventGridOptions evg, string str1, string str2) => L);

                var svc = new LessonService(repo.Object);

                var act = await svc.CreateLessonEdited(id, null);
                Assert.Equal($"{lessonExisting}-Edited", act.Description);

            }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            courseId = Request.QueryString["csid"];
            lessonId = Request.QueryString["lsid"];

            if (!IsPostBack)
            {
                ScormRepeater.DataSource = ScormService.LoadAllScorms(SessionVariable.Current.Company.Id).OrderBy(x => x.Name);
                ScormRepeater.DataBind();

                QuizRepeater.DataSource = QuizService.LoadAllQuizzes(SessionVariable.Current.Company.Id).OrderBy(x => x.Title);
                QuizRepeater.DataBind();

                var lesson = LessonService.GetLessonById(SessionVariable.Current.Company.Id, courseId, lessonId);
                if (lesson != null)
                {
                    LessonName.Text  = lesson.Name;
                    Description.Text = lesson.Description;

                    if (lesson.Course.CourseType == CourseTypeEnum.External)
                    {
                        Panel1.Visible = false;
                    }
                    else
                    {
                        CurriculumType.SelectedValue = ((int)lesson.LessonType).ToString();
                        ScormId.Value = lesson.ScormId;
                        QuizId.Value  = lesson.QuizId;
                    }
                }
            }
        }
        public async Task Delete_All_Versions(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target)
        {
            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddRangeAsync(entities);

            var version = 0;

            for (var i = 0; i < 5; i++)
            {
                var newLesson = new Lesson();
                newLesson.CloneFrom(target);
                newLesson.Version = version;
                await context.Lessons.AddAsync(target);

                version += 1;
            }

            await context.SaveChangesAsync();

            var result = await service.Delete(target.Id);

            result.Should().BeTrue();
            context.Lessons.Any(x => x.Id == target.Id).Should().BeFalse();
            context.Lessons.Count().Should().Be(entities.Count);
        }
Exemple #5
0
 public VenuesController(IAuthorizationService authorizationService, ClassroomService classroomService, LessonService lessonService, VenueService venueService)
 {
     _authorizationService = authorizationService;
     _classroomService     = classroomService;
     _lessonService        = lessonService;
     _venueService         = venueService;
 }
        public async Task Get_Lesson_With_A_Valid_Exercise(Mock <IAuthorizationService> authorizationService, IStateService stateService, Lesson lesson, Lesson invalidLesson, User user)
        {
            authorizationService.Setup(x => x.HasWriteAccess(user, It.IsAny <Lesson>(), It.IsAny <CancellationToken>())).ReturnsAsync(false);

            lesson.Exercises.First().Questions.First().Answers.First().Valid = true;

            invalidLesson.Exercises.First().Questions.First().Answers.ForEach(x => x.Valid = false);

            var context     = TestSetup.SetupContext();
            var httpContext = TestSetup.SetupHttpContext().SetupSession(user);

            await context.Lessons.AddAsync(lesson);

            await context.Lessons.AddAsync(invalidLesson);

            await context.SaveChangesAsync();

            var service = new LessonService(context, httpContext, authorizationService.Object, stateService);
            var result  = await service.Get(lesson.Id);

            var invalidResult = await service.Get(invalidLesson.Id);

            result.Should().NotBeNull().And.BeEquivalentTo(lesson);
            invalidResult.Should().BeNull();
        }
Exemple #7
0
        public void UpdateLessonGrade_GetLessonReturnsNull()
        {
            //arrange
            Lesson nullLesson = null;
            Mock <ILessonRepository> mockLessonRepo = new Mock <ILessonRepository>();

            mockLessonRepo.Setup(x => x.GetLesson(It.IsAny <int>())).Returns(nullLesson);
            Mock <IModuleRepository> mockModuleRepo = new Mock <IModuleRepository>();

            mockModuleRepo.Setup(x => x.GetModule(It.IsAny <int>())).Returns(new Module
            {
                ModuleId            = 0,
                MinimumPassingGrade = 0,
                Lessons             = new List <Lesson>
                {
                    new Lesson
                    {
                        LessonId = 0,
                        Grade    = 0.0d,
                        IsPassed = true
                    }
                }
            });

            LessonService lessonService = new LessonService(mockLessonRepo.Object, mockModuleRepo.Object);

            //act
            lessonService.UpdateLessonGrade(0, 0.0d);

            //assert - test fails if no NullReferenceException is thrown
        }
Exemple #8
0
 public static CardModel GetCardModel(Card card, Set cardSet, Rarity cardRarity, CardType cardType, CardDetail cardDetail,
                                      Language language, LessonType lessonType, LessonType providesLesson,
                                      CardProvidesLesson cardProvidesLesson)
 {
     return(new CardModel()
     {
         CardId = card.CardId,
         CardSet = SetService.GetSetModel(cardSet),
         CardType = TypeService.GetCardTypeModel(cardType),
         Rarity = RarityService.GetRarityModel(cardRarity),
         Detail = CardDetailService.GetCardDetailModel(cardDetail, language),
         LessonType = lessonType == null ? null : LessonService.GetLessonTypeModel(lessonType),
         LessonCost = card.LessonCost,
         ActionCost = card.ActionCost,
         CardNumber = card.CardNumber,
         Orientation = card.Orientation,
         ProvidesLesson = providesLesson == null && cardProvidesLesson == null ? null :
                          CardProvidesLessonService.GetCardProvidesLessonModel(cardProvidesLesson, providesLesson),
         CardPageUrl = $"/Card/{cardSet.ShortName}/{card.CardNumber}/{cardDetail.Name.Replace(" ", "-")}",
         CreatedById = card.CreatedById,
         CreatedDate = card.CreatedDate,
         UpdatedById = card.UpdatedById,
         UpdatedDate = card.UpdatedDate,
         Deleted = card.Deleted,
     });
 }
Exemple #9
0
            public void IfGradeIsLessThanMinimumPassingGrade_IsPassedShouldBeFalse()
            {
                // Arrange
                var lessonRepository = A.Fake <ILessonRepository>();
                var moduleRepository = A.Fake <IModuleRepository>();

                var lesson = new Lesson {
                    Grade = 1, IsPassed = false, LessonId = LessonId
                };
                var module = new Module {
                    ModuleId = 1, MinimumPassingGrade = 2, Lessons = new List <Lesson> {
                        lesson
                    }
                };

                A.CallTo(() => lessonRepository.GetLesson(A <int> .Ignored)).Returns(lesson);
                A.CallTo(() => moduleRepository.GetModule(A <int> .Ignored)).Returns(module);

                var lessonService = new LessonService(lessonRepository, moduleRepository);

                // Act
                lessonService.UpdateLessonGrade(LessonId, Grade);

                // Assert
                Assert.Equal(Grade, lesson.Grade);
                Assert.False(lesson.IsPassed);
            }
        public void UpdateLessonGrade_Test()
        {
            var lesson = new Lesson
            {
                LessonId = 12,
                Grade    = 95.4,
                IsPassed = true
            };

            var module = new Module
            {
                ModuleId            = 1,
                MinimumPassingGrade = 93,
                Lessons             = new List <Lesson>
                {
                    new Lesson
                    {
                        LessonId = 12,
                        Grade    = 9.4,
                        IsPassed = false
                    }
                }
            };
            var mockLessonRepo = new DynamicMock(typeof(ILessonRepository));
            var mockModuleRepo = new DynamicMock(typeof(IModuleRepository));

            mockLessonRepo.ExpectAndReturn("GetLesson", lesson);
            mockModuleRepo.GetModule("GetModule", module);

            var testLessonService = new LessonService();
            var retLesson         = testLessonService.UpdateLessonGrade(12, 100);

            Assert.AreEqual(100, retLesson.Grade);
            Assert.AreEqual(true, retLesson.IsPassed);
        }
        public void UpdateLessonGrade_IsPassedTrue_Test()
        {
            // Create a LessonService class object referance
            var lessonSvc = new LessonService();

            // Create parametters for true test case scnerio
            var lessonId = 12;
            var grade    = 98.2d; // examaple grade to update the IsPassed value to true and pass the test case

            //var grade = 60.3d;  // example grade to update the IsPassed value to false and fail the test case

            //Execute a "UpdateLessonGrade" method call with above parametters
            // The positive test case shoulld update the boolean value IsPassed to "true" for the lesson no 12 if the grade parametter is gretter than MinimumPassingGrade i.e 80
            lessonSvc.UpdateLessonGrade(lessonId, grade);

            // Create a LessonRepository class referance to get the object with "lessonId" 12 to check for the updated "IsPassed" variable value
            var lessonRepo = new LessonRepository();
            var lesson     = lessonRepo.GetLesson(lessonId);

            //Verify the condition with the return type as true to pass the test case
            //As the lessons and Module repository returns data froo a hardcoded list the object variable value might not get updated but the test case can be tested by updating
            //the hardcoded values of Lessons Objects in the LessonsRepositiry class
            Assert.IsTrue(lesson.IsPassed);

            //The above test case passes if the parametters passes are satisfing the conditions of MinimumPassingGrade and the record is updated as passed (i.e IsPassed=true)
        }
        private LessonService CreateLessonService()
        {
            var userId        = Guid.Parse(User.Identity.GetUserId());
            var lessonService = new LessonService(userId);

            return(lessonService);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            enrollmentId = Request.QueryString["enid"];
            lessonId     = Request.QueryString["lsid"];

            var lesson = LessonService.GetLessonById(lessonId, enrollmentId);

            logger.Debug(lesson.Scorm.ManifestXml);
            var        xmlDoc = XDocument.Parse(lesson.Scorm.ManifestXml);
            XNamespace ns     = xmlDoc.Root.GetDefaultNamespace();

            foreach (XElement element in xmlDoc.Descendants(ns + "resource"))
            {
                var href = element.Attribute("href");
                logger.Debug("element: {0}, attribute: {1}, ns: {2}", element.Name, href, ns);

                if (href != null)
                {
                    scormUrl = string.Format("/{0}/{1}", lesson.Scorm.WebPath, href.Value);
                    break;
                }
            }

            logger.Info(scormUrl);
        }
        public IHttpActionResult DeleteLesson(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new LessonService();

                bool isSuccess = service.Delete(id);
                if (!isSuccess)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not deleted."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
        public async Task <IActionResult> UpdateLesson([FromServices] LessonService lessonService, [FromServices] DisciplineService disciplineService, ResultModel <LessonVO> request)
        {
            string token = User.FindFirst("Token").Value;

            request.Object.CourseId = Guid.Parse(User.FindFirst("CourseId").Value);

            ResultModel <LessonVO> response = await lessonService.UpdateLessonTaskAsync(request.Object, token);

            if (response.StatusCode != HttpStatusCode.Created)
            {
                return(View("/Views/Coordinator/Lessons/Update.cshtml", new ResultModel <LessonVO>
                {
                    Object = request.Object,
                    Message = response.Message,
                    StatusCode = response.StatusCode
                }));
            }

            ResultModel <List <DisciplineVO> > disciplines = await disciplineService.GetDisciplinesByCoordIdTaskAsync(token);

            ResultModel <List <LessonDisciplineVO> > lessonsResponse = await lessonService.GetAllLessonsByDisciplineIDsTaskAsync(token, disciplines.Object.Select(x => x.DisciplineId).ToList());

            if (lessonsResponse.StatusCode == HttpStatusCode.OK)
            {
                lessonsResponse.Message    = response.Message;
                lessonsResponse.StatusCode = response.StatusCode;
            }

            return(View("/Views/Coordinator/Lessons/Index.cshtml", lessonsResponse));
        }
        public IHttpActionResult AddLesson(LessonModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new LessonService();

                int id = service.Add(BindingManager.ToLessonEntity(model));
                if (id == 0)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not created."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
Exemple #17
0
        public void UpdateLessonGrade_GetLessonReturnsDefaultObject_ModuleRepositoryIsCalled()
        {
            //arrange
            Mock <ILessonRepository> mockLessonRepo = new Mock <ILessonRepository>();

            mockLessonRepo.Setup(x => x.GetLesson(It.IsAny <int>())).Returns(new Lesson());
            Mock <IModuleRepository> mockModuleRepo = new Mock <IModuleRepository>();

            mockModuleRepo.Setup(x => x.GetModule(It.IsAny <int>())).Returns(new Module
            {
                ModuleId            = 0,
                MinimumPassingGrade = 0,
                Lessons             = new List <Lesson>
                {
                    new Lesson
                    {
                        LessonId = 0,
                        Grade    = 0.0d,
                        IsPassed = true
                    }
                }
            });

            LessonService lessonService = new LessonService(mockLessonRepo.Object, mockModuleRepo.Object);

            //act
            lessonService.UpdateLessonGrade(0, 0.0d);

            //assert
            mockLessonRepo.Verify(x => x.GetLesson(It.IsAny <int>()), Times.Once);
            mockModuleRepo.Verify(x => x.GetModule(It.IsAny <int>()), Times.Once);
        }
Exemple #18
0
 public TrainingController()
 {
     ts  = new TrainingService();
     ls  = new LessonService();
     qs  = new QuestionService();
     ans = new AnswerService();
 }
Exemple #19
0
 public AddNewLessonScreen()
 {
     InitializeComponent();
     addLessonView  = new AddLessonViewModel();
     lessonService  = new LessonService();
     BindingContext = addLessonView;
 }
Exemple #20
0
        public ActionResult Details(int id)
        {
            var service = new LessonService();
            var model   = service.GetLessonById(id);

            return(View(model));
        }
Exemple #21
0
        public ActionResult Index()
        {
            // Fetch the lesson from the Typsy API
            Lesson lesson = LessonService.Get(100);

            string timestamp            = DateTime.UtcNow.ToString("O");
            string encryptedKeyTemplate = $"{TYPSY_KEY}:{timestamp}";
            string encryptedKey         = EncryptionHelper.CreateHmacSha256(encryptedKeyTemplate, TYPSY_KEY);

            // INSERT LOGIC TO LOOKUP THE EMAIL ADDRESS OF THE USER ACCESSING THE PAGE
            string email     = "*****@*****.**";
            string firstname = "Bob";
            string lastname  = "Smith";

            var referrer = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.Path}{this.Request.QueryString}";

            PlayerViewModel viewModel = new PlayerViewModel();

            viewModel.ApiEndpoint  = "https://api.typsy.com";
            viewModel.Lesson       = lesson;
            viewModel.AccountId    = TYPSY_ACCOUNT_ID;
            viewModel.EncryptedKey = encryptedKey;
            viewModel.Source       = TYPSY_SOURCE;
            viewModel.Referrer     = referrer;
            viewModel.Timestamp    = timestamp;
            viewModel.Email        = email;
            viewModel.Firstname    = firstname;
            viewModel.Lastname     = lastname;

            return(View(viewModel));
        }
        public void UpdateLessonGradeShouldThrowNullExceptionWithInvalidLessonId()
        {
            var          lessonService = new LessonService();
            const int    LESSON_ID     = 5; // Invalid lesson ID
            const double LESSON_GRADE  = 80.0;

            Assert.Throws <NullReferenceException>(() => lessonService.UpdateLessonGrade(LESSON_ID, LESSON_GRADE));
        }
        public async Task <IActionResult> Update([FromServices] LessonService lessonService, [Required] Guid lessonId)
        {
            string token = User.FindFirst("Token").Value;

            ResultModel <LessonVO> response = await lessonService.GetLessonByIdTaskAsync(lessonId, token);

            return(View("/Views/Coordinator/Lessons/Update.cshtml", response));
        }
Exemple #24
0
        protected void DelBtn_Command(object sender, CommandEventArgs e)
        {
            string lessonId = e.CommandArgument as string;

            LessonService.DeleteLesson(SessionVariable.Current.Company.Id, SessionVariable.Current.User.Id, course.Id, lessonId);

            Response.Redirect(Request.RawUrl);
        }
 public LessonsController(ApplicationDbContext context)
 {
     _context = context;
     qS       = new LessonService(context);
     ts       = new TestService(context);
     uS       = new UserService(context);
     upS      = new UserProgressService(context);
 }
Exemple #26
0
 public LessonsController(LessonService lessonService, ClassService classService,
                          IMapper mapper, ILogger <LessonsController> logger)
 {
     _lessonService = lessonService;
     _classService  = classService;
     _mapper        = mapper;
     _logger        = logger;
 }
Exemple #27
0
        public ChooseLessonWindow(user user)
        {
            _user          = user;
            _lessonService = new LessonService();

            InitializeComponent();
            PrepareLessonsButtons();
        }
 public AssignmentsController(AssignmentService assignmentService, ClassroomService classroomService, LessonService lessonService, IAuthorizationService authorizationService, ApplicationDbContext dbContext)
 {
     _assignmentService    = assignmentService;
     _classroomService     = classroomService;
     _lessonService        = lessonService;
     _authorizationService = authorizationService;
     _dbContext            = dbContext;
 }
 public QuizzAPIController(ApplicationDbContext context)
 {
     _context = context;
     qS       = new LessonService(context);
     ts       = new TestService(context);
     rS       = new ResultService(context);
     uS       = new UserService(context);
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string        studReg     = "";
            string        studLessons = "";
            List <object> studUserIds = gvStudents.GetSelectedFieldValues("UserId");
            string        regState    = new InstanceConfigServices().GetConfig("lessonsRegistration");

            if (studUserIds.Count > 0)
            {
                if (cmbProgram.Value != null)
                {
                    List <Lesson> allLessons = new LessonService().GetAllLessonsByClassID(int.Parse(cmbProgram.GridView.GetRowValues(cmbProgram.GridView.FocusedRowIndex, "ID").ToString()), new SessionManager().GetUserId(Session));

                    if (allLessons.Count > 0)
                    {
                        foreach (object studUserId in studUserIds)
                        {
                            studReg += "('" + cmbProgram.GridView.GetRowValues(cmbProgram.GridView.FocusedRowIndex, "ID").ToString() + "','" + cmbProgram.GridView.GetRowValues(cmbProgram.GridView.FocusedRowIndex, "Bgroup").ToString() + "','" + studUserId + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'),";
                            if (regState == "Administration")
                            {
                                foreach (Lesson allLesson in allLessons)
                                {
                                    studLessons += "('" + studUserId + "','" + cmbProgram.GridView.GetRowValues(cmbProgram.GridView.FocusedRowIndex, "ID").ToString() + "','" + cmbProgram.GridView.GetRowValues(cmbProgram.GridView.FocusedRowIndex, "Bgroup").ToString() + "','" + allLesson.ID + "','" + allLesson.ClassID + "','" + allLesson.ModuleID + "','" + 0 + "','" + 0 + "','" + " " + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'),";
                                }
                            }
                        }

                        if (new StudentRegistrationService().AddStudentRegistrationList(studReg.TrimEnd(','), new SessionManager().GetUserId(Session)))
                        {
                            if (regState == "Administration")
                            {
                                new StudentLessonsRegistrationService().AddStudentLessonsRegistrationList(studLessons.TrimEnd(','), new SessionManager().GetUserId(Session));
                            }
                            ScriptManager.RegisterStartupScript(this, GetType(), ",toastr", "toastr.success('Saved Successfully','Message')", true);
                            clearfields();
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), ",toastr", "toastr.error('Saving Failed','Message')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), ",toastr", "toastr.info('There are no lessons/courses associated with this batch. ','Message')", true);
                    }
                }
                else
                {
                    cmbProgram.IsValid = false;
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), ",toastr", "toastr.info('Select at least a student','Message')", true);
            }
            loadRegStudents();
            uPanel.Update();
        }