Example #1
0
        /// <summary>
        /// Checks if related to theme package has been already uploaded.
        /// In case it was not uploaded - upload package.
        /// Check attempt has been created and get attempt id.
        /// </summary>
        /// <param name="theme">Theme object represents specified theme.</param>
        /// <returns>Long integer value representing attempt id.</returns>
        public long GetAttemptId(Theme theme)
        {
            GetCurrentUserIdentifier();
            AttemptItemIdentifier attemptId = null;
            ActivityPackageItemIdentifier organizationId;
            var packageId = GetPackageIdentifier(theme.CourseRef.Value);

            // in case package has not been uploaded yet.
            if (packageId == null)
            {
                string zipPath = CourseService.Export(theme.CourseRef.Value);
                Package package = new ZipPackage(zipPath);
                package.CourseID = theme.CourseRef.Value;
                packageId = AddPackage(package);
                organizationId = GetOrganizationIdentifier(packageId);
                attemptId = CreateAttempt(organizationId.GetKey(), theme.Id);
            }
            // otherwise check if attempt was created
            else
            {
                organizationId = GetOrganizationIdentifier(packageId);

                AttemptItemIdentifier attId = GetAttemptIdentifier(organizationId, theme.Id);
                if (attId != null)
                {
                    attemptId = attId;
                }
                else
                {
                    attemptId = CreateAttempt(organizationId.GetKey(), theme.Id);
                }
            }

            return attemptId.GetKey();
        }
Example #2
0
        public void GetThemeResultScoreTest()
        {
            User usr = new User() { Username = "******" };
            Theme thm = new Theme() { Name = "Theme One" };
            IUDICO.Common.Models.Shared.Statistics.AttemptResult AR = new IUDICO.Common.Models.Shared.Statistics.AttemptResult(1,usr,thm, IUDICO.Common.Models.Shared.Statistics.CompletionStatus.Completed, IUDICO.Common.Models.Shared.Statistics.AttemptStatus.Completed,IUDICO.Common.Models.Shared.Statistics.SuccessStatus.Passed, DateTime.Now, 0.5f);
            
            ThemeResult target = new ThemeResult(usr, thm);
            List<IUDICO.Common.Models.Shared.Statistics.AttemptResult> ARL = new List<IUDICO.Common.Models.Shared.Statistics.AttemptResult>();
            ARL.Add(AR);
            target.AttemptResults = ARL;

            double? expected = 50.0;
            double? actual;
            actual = target.GetThemeResultScore();
            Assert.AreEqual(expected, actual);
        }
Example #3
0
 private void detach_Themes(Theme entity)
 {
     this.SendPropertyChanging();
     entity.ThemeType = null;
 }
Example #4
0
 private void attach_Themes(Theme entity)
 {
     this.SendPropertyChanging();
     entity.ThemeType = this;
 }
Example #5
0
 public void DeletingThemeWhenStageDeleted()
 {
     Curriculum cur = new Curriculum() { Name = "Curriculum" };
     _Storage.AddCurriculum(cur);
     CurriculumAssignment as1 = new CurriculumAssignment() { Curriculum = cur, UserGroupRef = 1 };
     _Storage.AddCurriculumAssignment(as1);
     Stage st = new Stage() { Name = "Stage", Curriculum = cur };
     var stageId = _Storage.AddStage(st);
     Theme theme = new Theme() { Name = "Theme", Stage = st, ThemeType = _Storage.GetThemeType(1) };
     int id = _Storage.AddTheme(theme);
     _Storage.DeleteStage(stageId);
     Assert.AreEqual(null, _Storage.GetTheme(id));
 }
Example #6
0
        public void ThemeDown()
        {
            List<Curriculum> cur = CreateDefaultData();
            cur.ForEach(item => _Storage.AddCurriculum(item));

            List<Stage> stages = cur.Select(item => new Stage() { Name = "Stage", Curriculum = item })
                .ToList();
            stages.ForEach(item => _Storage.AddStage(item));

            List<Theme> themes = stages.Select(item => new Theme() { Name = "Theme", Stage = item, ThemeType = _Storage.GetThemeType(1) })
                .ToList();
            Theme theme = new Theme() { Name = "Theme1", Stage = stages[0], ThemeType = _Storage.GetThemeType(1) };
            var ids = themes.Select(item => _Storage.AddTheme(item))
                .ToList();
            var id = _Storage.AddTheme(theme);

            _Storage.ThemeUp(id);
            theme = _Storage.GetThemesByStageId(theme.Stage.Id).ToList()[0];

            _Storage.ThemeDown(id);
            AdvAssert.AreEqual(theme, _Storage.GetThemesByStageId(theme.Stage.Id).ToList()[1]);
            try
            {
                _Storage.ThemeDown(0);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #7
0
        public void DeleteThemes()
        {
            List<Curriculum> cur = CreateDefaultData();
            cur.ForEach(item => _Storage.AddCurriculum(item));

            List<Stage> stages = cur.Select(item => new Stage() { Name = "Stage", Curriculum = item })
                .ToList();
            stages.ForEach(item => _Storage.AddStage(item));

            List<Theme> themes = stages.Select(item => new Theme() { Name = "Theme", Stage = item, ThemeType = _Storage.GetThemeType(1) })
                .ToList();
            var ids = themes.Select(item => _Storage.AddTheme(item));

            Theme last = new Theme() { Name = "LastTheme", Stage = stages[0], ThemeType = _Storage.GetThemeType(1) };
            var id = _Storage.AddTheme(last);

            _Storage.DeleteThemes(ids);
            AdvAssert.AreEqual(last, _Storage.GetTheme(id));
            try
            {
                _Storage.GetThemes(ids);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #8
0
 public void DeleteTheme()
 {
     Curriculum cur = new Curriculum() { Name = "Curriculum" };
     _Storage.AddCurriculum(cur);
     CurriculumAssignment as1 = new CurriculumAssignment() { Curriculum = cur, UserGroupRef = 1 };
     _Storage.AddCurriculumAssignment(as1);
     Stage st = new Stage() { Name = "Stage", Curriculum = cur };
     _Storage.AddStage(st);
     Theme theme = new Theme() { Name = "Theme", Stage = st, ThemeType = _Storage.GetThemeType(1) };
     int id = _Storage.AddTheme(theme);
     _Storage.DeleteTheme(id);
     Assert.AreEqual(null, _Storage.GetTheme(id));
     Assert.AreEqual(0, _Storage.GetThemeAssignmentsByThemeId(id).Count());
     try
     {
         _Storage.DeleteTheme(0);
         Assert.Fail();
     }
     catch (Exception)
     {
         Assert.True(true);
     }
 }
Example #9
0
        public void UpdateTheme()
        {
            Curriculum cur = new Curriculum() { Name = "Curriculum" };
            _Storage.AddCurriculum(cur);

            CurriculumAssignment as1 = new CurriculumAssignment() { Curriculum = cur, UserGroupRef = 1 };
            _Storage.AddCurriculumAssignment(as1);

            Stage st = new Stage() { Name = "Stage", Curriculum = cur };
            _Storage.AddStage(st);

            Theme theme = new Theme() { Name = "Theme", Stage = st, ThemeType = _Storage.GetThemeType(1) };
            int id = _Storage.AddTheme(theme);
            theme.Name = "UpdatedName";
            _Storage.UpdateTheme(theme);
            AdvAssert.AreEqual(theme, _Storage.GetTheme(id));            
            
            try
            {
                _Storage.UpdateTheme(null);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #10
0
        public void GetThemesAvailableForUser()
        {
            Curriculum curr = new Curriculum() { Name = "Curriculum" };
            Curriculum curr1 = new Curriculum() { Name = "Curriculum1" };
            _Storage.AddCurriculum(curr);
            _Storage.AddCurriculum(curr1);

            DateTime dtStart = new DateTime(2011, 11, 11, 0, 0, 0);
            DateTime dtIn = new DateTime(2040, 11, 11, 0, 0, 0);
            DateTime dtOf = new DateTime(2011, 11, 12, 0, 0, 0);
            CurriculumAssignment as1 = new CurriculumAssignment() { Curriculum = curr, UserGroupRef = 1 };
            CurriculumAssignment as2 = new CurriculumAssignment() { Curriculum = curr1, UserGroupRef = 1 };
            _Storage.AddCurriculumAssignment(as1);
            _Storage.AddCurriculumAssignment(as2);

            Timeline tml = new Timeline() { CurriculumAssignment = as1, StartDate = dtStart, EndDate = dtIn };
            Timeline tml1 = new Timeline() { CurriculumAssignment = as2, StartDate = dtStart, EndDate = dtOf };
            _Storage.AddTimeline(tml);
            _Storage.AddTimeline(tml1);

            Stage st = new Stage() { Name = "Stage1", Curriculum = curr };
            Stage st1 = new Stage() { Name = "Stage2", Curriculum = curr1 };
            _Storage.AddStage(st);
            _Storage.AddStage(st1);

            Theme th1 = new Theme() { Name = "Theme1", Stage = st, ThemeType = _Storage.GetThemeType(1) };
            Theme th2 = new Theme() { Name = "Theme2", Stage = st1, ThemeType = _Storage.GetThemeType(1) };
            _Storage.AddTheme(th1);
            _Storage.AddTheme(th2);

            List<ThemeDescription> result = new List<ThemeDescription> { new ThemeDescription() { Theme = th1, Stage = st, Curriculum = curr,
                Timelines = new List<Timeline>() { tml } } };
            IUserService serv = _Tests.LmsService.FindService<IUserService>();
            User us = serv.GetUsers().First();
            AdvAssert.AreEqual(result, _Storage.GetThemesAvailableForUser(us));

            Timeline tml2 = new Timeline() { StageRef = st.Id, CurriculumAssignment = as1, StartDate = dtStart, EndDate = new DateTime(2011, 12, 9, 0, 0, 0) };
            _Storage.AddTimeline(tml2);
            result.Clear();
            AdvAssert.AreEqual(result, _Storage.GetThemesAvailableForUser(us));
            try
            {
                User notExistedUser = new User() { Id = Guid.NewGuid(), Username = "******", Email = "*****@*****.**", Password = "" };
                _Storage.GetThemesAvailableForUser(notExistedUser);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #11
0
        public void GetGroupsAssignedToTheme()
        {
            Curriculum cur = new Curriculum() { Name = "Curriculum" };
            Curriculum cur1 = new Curriculum() { Name = "Curriculum1" };

            IUserService userService = _Tests.LmsService.FindService<IUserService>();
            Group gr1 = userService.GetGroup(2);
            Group gr2 = userService.GetGroup(1);

            _Storage.AddCurriculum(cur);
            _Storage.AddCurriculum(cur1);

            CurriculumAssignment ass = new CurriculumAssignment() { Curriculum = cur, UserGroupRef = gr1.Id, Id = 1 };
            CurriculumAssignment ass1 = new CurriculumAssignment() { Curriculum = cur1, UserGroupRef = gr2.Id, Id = 2 };
            _Storage.AddCurriculumAssignment(ass);
            _Storage.AddCurriculumAssignment(ass1);

            Stage stage = new Stage() { Name = "Stage", Curriculum = cur };
            Stage stage1 = new Stage() { Name = "Stage1", Curriculum = cur1 };
            _Storage.AddStage(stage);
            _Storage.AddStage(stage1);

            Theme theme = new Theme() { Name = "Theme", Stage = stage, ThemeType = _Storage.GetThemeType(1) };
            Theme theme1 = new Theme() { Name = "Theme1", Stage = stage1, ThemeType = _Storage.GetThemeType(1) };
            var id = _Storage.AddTheme(theme);
            var id1 = _Storage.AddTheme(theme1);

            Assert.AreEqual(gr1.Id, _Storage.GetGroupsAssignedToTheme(id).First().Id);
            Assert.AreEqual(gr2.Id, _Storage.GetGroupsAssignedToTheme(id1).First().Id);
            _Storage.DeleteTheme(id1);
            try
            {
                _Storage.GetGroupsAssignedToTheme(id1);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
            try
            {
                _Storage.DeleteCurriculumAssignment(1);
                _Storage.GetGroupsAssignedToTheme(id);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #12
0
        public void GetThemesByCourseId()
        {
            Curriculum cur = new Curriculum() { Name = "Curriculum", Id = 1 };
            _Storage.AddCurriculum(cur);

            Stage stage = new Stage() { Name = "Stage", Curriculum = cur, Id = 1 };
            _Storage.AddStage(stage);

            Course course = new Course() { Name = "Course", Id = 1 };
            Theme theme = new Theme() { Name = "Theme", Stage = stage, ThemeType = _Storage.GetThemeType(1), Id = 1, CourseRef = course.Id };
            Theme theme1 = new Theme() { Name = "Theme1", Stage = stage, ThemeType = _Storage.GetThemeType(1), Id = 2, CourseRef = course.Id };
            _Storage.AddTheme(theme);
            AdvAssert.AreEqual(theme, _Storage.GetThemesByCourseId(course.Id).First());
            _Storage.AddTheme(theme1);
            List<Theme> expected = new List<Theme>() { theme, theme1 };
            AdvAssert.AreEqual(expected, _Storage.GetThemesByCourseId(course.Id).ToList());
            try
            {
                _Storage.DeleteTheme(theme.Id);
                _Storage.DeleteTheme(theme1.Id);
                _Storage.GetThemesByCourseId(course.Id);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #13
0
        public void GetTheme()
        {
            IUserService userService = _Tests.LmsService.FindService<IUserService>();
            Group group = userService.GetGroup(1);

            var curriculums = CreateDefaultData();

            var stages = curriculums.Select(item => new Stage { Name = "Stage", Curriculum = item }).ToList();
            var themes = stages.Select(item => new Theme { Name = "Theme", Stage = item, ThemeType = _Storage.GetThemeType(1) }).ToList();
            var ids = themes.Select(item => _Storage.AddTheme(item)).ToList();
            themes.Select((item, i) => i).
                ToList().ForEach(item => AdvAssert.AreEqual(themes[item], _Storage.GetTheme(ids[item])));
            try
            {
                Theme existed = new Theme { Name = "Theme", Stage = stages[0], ThemeType = _Storage.GetThemeType(1), Id = ids[0] };
                _Storage.AddTheme(existed);
                _Storage.GetTheme(ids[0]);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
            try
            {
                _Storage.GetTheme(0);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.True(true);
            }
        }
Example #14
0
 public void MakeCurriculumInvalid()
 {
     Curriculum curriculum = new Curriculum() { Name = "Curriculum1" };
     var id = _Storage.AddCurriculum(curriculum);
     Stage stage = new Stage() { Curriculum = curriculum, Name = "Stage1" };
     _Storage.AddStage(stage);
     Theme theme = new Theme() { Name = "Theme1", Stage = stage, ThemeType = _Storage.GetThemeType(1), CourseRef = 1 };
     _Storage.AddTheme(theme);
     _Storage.MakeCurriculumInvalid(id);
     Assert.AreEqual(false, _Storage.GetCurriculum(id).IsValid);
 }
Example #15
0
 public void DeleteCourse()
 {
     Course course = _Tests.CourseStorage.GetCourse(1);
     Curriculum cur = new Curriculum() { Name = "Curriculum" };
     var currId= _Storage.AddCurriculum(cur);
     CurriculumAssignment as1 = new CurriculumAssignment() { Curriculum = cur, UserGroupRef = 1 };
     _Storage.AddCurriculumAssignment(as1);
     Stage st = new Stage() { Name = "Stage", Curriculum = cur };
     var stageId = _Storage.AddStage(st);
     Theme theme = new Theme() { Name = "Theme", Stage = st, ThemeType = _Storage.GetThemeType(1), CourseRef=course.Id };
     _Storage.AddTheme(theme);
     _Tests.CourseStorage.DeleteCourse(course.Id);
     Assert.AreEqual(false, _Storage.GetCurriculum(currId).IsValid);
 }
Example #16
0
        public IEnumerable<AttemptResult> GetResults(User user, Theme theme)
        {
            List<AttemptResult> result = new List<AttemptResult>();
            LearningStoreJob job = LStore.CreateJob();
            RequestAttemptsByThemeAndUser(job, user.Id.ToString(), theme.Id);
            DataTable dataTable = job.Execute<DataTable>();
            foreach (DataRow dataRow in dataTable.AsEnumerable())
            {
                AttemptItemIdentifier attemptItemId;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptId], out attemptItemId);
                long attemptId = attemptItemId.GetKey();

                Microsoft.LearningComponents.CompletionStatus completionStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.CompletionStatus], out completionStatus);
                IUDICO.Common.Models.Shared.Statistics.CompletionStatus iudicoCompletionStatus = (IUDICO.Common.Models.Shared.Statistics.CompletionStatus)completionStatus;

                Microsoft.LearningComponents.AttemptStatus attemptStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.AttemptStatus], out attemptStatus);
                IUDICO.Common.Models.Shared.Statistics.AttemptStatus iudicoAttemptStatus = (IUDICO.Common.Models.Shared.Statistics.AttemptStatus)attemptStatus;

                Microsoft.LearningComponents.SuccessStatus successStatus;
                LStoreHelper.CastNonNull(dataRow[Schema.AttemptsResultsByThemeAndUser.SuccessStatus], out successStatus);
                IUDICO.Common.Models.Shared.Statistics.SuccessStatus iudicoSuccessStatus = (IUDICO.Common.Models.Shared.Statistics.SuccessStatus)successStatus;

                DateTime? startTime;
                LStoreHelper.Cast(dataRow[Schema.AttemptsResultsByThemeAndUser.StartedTimestamp], out startTime);

                float? score;
                LStoreHelper.Cast<float>(dataRow[Schema.AttemptsResultsByThemeAndUser.Score], out score);
                float? scaledScore = null;
                if (score != null)
                {
                    scaledScore = score / 100;
                }

                // Create AttemptResult object
                AttemptResult attemptResult = new AttemptResult(attemptId, user, theme, iudicoCompletionStatus, iudicoAttemptStatus, iudicoSuccessStatus, startTime, scaledScore);
                result.Add(attemptResult);
            }

            return result;
        }