コード例 #1
0
        public UpdateModuleResourceResponse Put(UpdateModuleResourceRequest request)
        {
            var coachingCourseRepository         = new CoachingCourseRepositoryDocumentDB();
            var coachingModuleResourceRepository = new ModuleResourceRepositoryDocumentDb();
            var coachingModuleRepository         = new CoachingModuleRepositoryDocumentDB();
            var exerciseRepository = new CoachnigModuleExerciseResourceRepositoryDocumentDB();
            var userRepository     = new UserRepositoryDocumentDB();

            var module   = coachingModuleRepository.GetModuleById(request.ModuleId);
            var resource = coachingModuleResourceRepository.GetResourceById(request.ResourceId);

            var coachingService = new CoachingCourseService(
                coachingCourseRepository,
                coachingModuleResourceRepository,
                coachingModuleRepository,
                exerciseRepository,
                userRepository);

            var newResource = new CoachingModuleResource()
            {
                RevisionHistory = resource.RevisionHistory,
                Content         = request.UpdatedContent
            };

            coachingService.UpdateModuleResurce(module, newResource);

            return(new UpdateModuleResourceResponse()
            {
                UpdatedResouceId = newResource.Id, UpdatedResouceVersion = newResource.Version, ParentResourceId = request.ResourceId
            });
        }
コード例 #2
0
 public static ModuleResourceDTO ConvertToDTO(CoachingModuleResource entity)
 {
     return(new ModuleResourceDTO
     {
         Id = entity.Id,
         Created = entity.Created,
         Version = entity.Version,
         Content = entity.Content
     });
 }
コード例 #3
0
        public void UpdateModuleName()
        {
            var courseName = "Course with modules";
            var courseRepo = new CoachingCourseRepositoryDocumentDB();
            var moduleRepo = new CoachingModuleRepositoryDocumentDB();
            var course     = new CoachingCourse(courseName);

            courseRepo.CreateCoachingCourse(course);

            var introduction = new CoachingModuleResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1>&lt;Overskrift her&gt;</h1> <p>&lt;Kort tekst her&gt;</p> <div data-oembed-url='https://vimeo.com/ricardonilsson/coachingwill'> <div style='left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;'><iframe allowfullscreen='true' frameborder='0' mozallowfullscreen='true' src='//player.vimeo.com/video/77308630?byline=0&amp;badge=0&amp;portrait=0&amp;title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2>&lt;Overskrift, start p&aring; udvidet intro&gt;</h2> <p>&lt;Intro her&gt;</p> <h2>&lt;Overskrift, eksterne henvisninger&gt;</h2> <p><a href='http://wikipedia.org'>&lt;Eksempel p&aring; link&gt;</a></p>"
            };
            var exercise = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her, efterfulgt af &gt;</p>  <SortableList/>")
                }
            };
            var reflection = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her&gt;</p>  <h2>&nbsp;</h2>")
                }
            };

            var module = new CoachingModule
                         (
                "Some module, that is gonna have its name changed",
                introduction,
                exercise,
                reflection
                         );

            course.AddCoachingModule(module);
            moduleRepo.CreateModule(module);
            courseRepo.SaveCoachingCourse(course);

            moduleRepo = new CoachingModuleRepositoryDocumentDB();
            var foundModule = moduleRepo.GetItems(m => m.Id == module.Id).Single();

            Assert.IsNotNull(foundModule);

            module.Name = "Some module with a new name";
            moduleRepo.SaveModule(module);

            moduleRepo = new CoachingModuleRepositoryDocumentDB();
            var newFoundModule = moduleRepo.GetItems(m => m.Id == module.Id).Single();

            Assert.AreEqual(newFoundModule.Name, "Some module with a new name");
        }
コード例 #4
0
        public void UpdateModuleResource()
        {
            var courseName = "Service test course with updated module";
            //Create the course
            var course         = _coachingCourseService.CreateNewCoachingCourse(courseName);
            var coachingModule = _coachingCourseService.CreateNewModuleInCourse(course, "Some module", 0);

            var newResource = new CoachingModuleResource()
            {
                Content         = "En meget kortere tekst",
                RevisionHistory = new ResourseRevisionHistoryReference()
                {
                    ReferenceId = coachingModule.Introduction.RevisionHistoryReferenceId
                }
            };

            _coachingCourseService.UpdateModuleResurce(coachingModule, newResource);

            var courseRepo   = new CoachingCourseRepositoryDocumentDB();
            var resourceRepo = new ModuleResourceRepositoryDocumentDb();
            var moduleRepo   = new CoachingModuleRepositoryDocumentDB();
            var foundCourse  = courseRepo.GetItems(i => i.Id == course.Id).Single();
            var foundModule  = moduleRepo.GetModuleById(foundCourse.Modules[0].ModuleReferenceId);
            var foundIntroductionResource = resourceRepo.GetResourceById(foundModule.Introduction.ResourceReferenceId);

            Assert.AreEqual(foundCourse.Modules.Count, 1);
            Assert.AreEqual(foundIntroductionResource.Content, "En meget kortere tekst");

            resourceRepo = new ModuleResourceRepositoryDocumentDb();
            var foundResources = resourceRepo.GetItems(i => i.RevisionHistory.ReferenceId == foundModule.Introduction.RevisionHistoryReferenceId);

            Assert.AreEqual(foundResources.OrderBy(v => v.Version).ToList()[0].Version, 1);
            Assert.AreEqual(foundResources.OrderBy(v => v.Version).ToList()[1].Version, 2);

            Assert.AreNotEqual(foundResources.OrderBy(v => v.Version).ToList()[0].Content, "En meget kortere tekst");
            Assert.AreEqual(foundResources.OrderBy(v => v.Version).ToList()[1].Content, "En meget kortere tekst");
        }
コード例 #5
0
        public CoachingModule CreateNewModuleInCourse(CoachingCourse coachingCourse, string moduleName, int index)
        {
            //Create resources with default content
            //TODO: Load the default content from somewhere
            var introduction = new CoachingModuleResource()
            {
                Content = "<h1>&lt;Overskrift her&gt;</h1> <p>&lt;Kort tekst her&gt;</p> <div data-oembed-url='https://vimeo.com/ricardonilsson/coachingwill'> <div style='left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;'><iframe allowfullscreen='true' frameborder='0' mozallowfullscreen='true' src='//player.vimeo.com/video/77308630?byline=0&amp;badge=0&amp;portrait=0&amp;title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2>&lt;Overskrift, start p&aring; udvidet intro&gt;</h2> <p>&lt;Intro her&gt;</p> <h2>&lt;Overskrift, eksterne henvisninger&gt;</h2> <p><a href='http://wikipedia.org'>&lt;Eksempel p&aring; link&gt;</a></p>"
            };
            var exercise = new CoachingModuleExerciseResource()
            {
                Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement(""),
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her, evt. efterfulgt af opgave: &gt;</p> ")
                }
            };
            var reflection = new CoachingModuleExerciseResource()
            {
                Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("")
                }
            };

            //Create revsions for new content
            var introRevision = Guid.NewGuid();

            PushResourceVersion(introduction, introRevision);
            var exerciseRevision = Guid.NewGuid();

            PushResourceVersion(exercise, exerciseRevision);
            var reflectionRevision = Guid.NewGuid();

            PushResourceVersion(reflection, reflectionRevision);

            //Create and add module
            var module = new CoachingModule(
                moduleName,
                introduction, exercise, reflection);

            module.ModuleIndex = index;

            exercise.Elements[0].Exercise   = new GoalExercise(new CoachingModuleReference(module.Id));
            reflection.Elements[0].Exercise = new PromiseExercise(new List <string>()
            {
                "Resultatet af øvelsen levede op til mine forventinger"
            }, new CoachingModuleReference(module.Id))
            {
            };

            //Save resources
            _resourceRepository.CreateModuleResource(introduction);
            _exerciseRepository.CreateModuleResource(exercise);
            _exerciseRepository.CreateModuleResource(reflection);

            _moduleRepository.SaveModule(module);

            coachingCourse.AddCoachingModule(module);
            _coachingCourseRepository.SaveCoachingCourse(coachingCourse);

            //Return new module
            return(module);
        }
コード例 #6
0
        public void GetMultipleModulesWithSpecificIds()
        {
            var courseName = "Course with multiple modules";
            var courseRepo = new CoachingCourseRepositoryDocumentDB();
            var moduleRepo = new CoachingModuleRepositoryDocumentDB();
            var course     = new CoachingCourse(courseName);

            courseRepo.CreateCoachingCourse(course);

            var introduction1 = new CoachingModuleResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1>&lt;Overskrift her&gt;</h1> <p>&lt;Kort tekst her&gt;</p> <div data-oembed-url='https://vimeo.com/ricardonilsson/coachingwill'> <div style='left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;'><iframe allowfullscreen='true' frameborder='0' mozallowfullscreen='true' src='//player.vimeo.com/video/77308630?byline=0&amp;badge=0&amp;portrait=0&amp;title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2>&lt;Overskrift, start p&aring; udvidet intro&gt;</h2> <p>&lt;Intro her&gt;</p> <h2>&lt;Overskrift, eksterne henvisninger&gt;</h2> <p><a href='http://wikipedia.org'>&lt;Eksempel p&aring; link&gt;</a></p>"
            };
            var exercise1 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her, efterfulgt af &gt;</p>  <SortableList/>")
                }
            };
            var reflection1 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her&gt;</p>  <h2>&nbsp;</h2>")
                }
            };

            var module1 = new CoachingModule
                          (
                "My coaching module 1",
                introduction1,
                exercise1,
                reflection1
                          );

            var introduction2 = new CoachingModuleResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1>&lt;Overskrift her&gt;</h1> <p>&lt;Kort tekst her&gt;</p> <div data-oembed-url='https://vimeo.com/ricardonilsson/coachingwill'> <div style='left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;'><iframe allowfullscreen='true' frameborder='0' mozallowfullscreen='true' src='//player.vimeo.com/video/77308630?byline=0&amp;badge=0&amp;portrait=0&amp;title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2>&lt;Overskrift, start p&aring; udvidet intro&gt;</h2> <p>&lt;Intro her&gt;</p> <h2>&lt;Overskrift, eksterne henvisninger&gt;</h2> <p><a href='http://wikipedia.org'>&lt;Eksempel p&aring; link&gt;</a></p>"
            };
            var exercise2 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her, efterfulgt af &gt;</p>  <SortableList/>")
                }
            };
            var reflection2 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her&gt;</p>  <h2>&nbsp;</h2>")
                }
            };

            var module2 = new CoachingModule
                          (
                "My coaching module 2",
                introduction2,
                exercise2,
                reflection2
                          );

            var introduction3 = new CoachingModuleResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1>&lt;Overskrift her&gt;</h1> <p>&lt;Kort tekst her&gt;</p> <div data-oembed-url='https://vimeo.com/ricardonilsson/coachingwill'> <div style='left: 0px; width: 100%; height: 0px; position: relative; padding-bottom: 56.2493%;'><iframe allowfullscreen='true' frameborder='0' mozallowfullscreen='true' src='//player.vimeo.com/video/77308630?byline=0&amp;badge=0&amp;portrait=0&amp;title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2>&lt;Overskrift, start p&aring; udvidet intro&gt;</h2> <p>&lt;Intro her&gt;</p> <h2>&lt;Overskrift, eksterne henvisninger&gt;</h2> <p><a href='http://wikipedia.org'>&lt;Eksempel p&aring; link&gt;</a></p>"
            };
            var exercise3 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her, efterfulgt af &gt;</p>  <SortableList/>")
                }
            };
            var reflection3 = new CoachingModuleExerciseResource()
            {
                RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>()
                {
                    new ResourceExerciseElement("<h1>&lt;Overskrift her&gt;</h1>  <p>&lt;Kort tekst her&gt;</p>  <h2>&nbsp;</h2>")
                }
            };

            var module3 = new CoachingModule
                          (
                "My coaching module 2",
                introduction3,
                exercise3,
                reflection3
                          );

            course.AddCoachingModule(module1);
            course.AddCoachingModule(module2);
            course.AddCoachingModule(module3);
            courseRepo.SaveCoachingCourse(course);

            moduleRepo.SaveModule(module1);
            moduleRepo.SaveModule(module2);
            moduleRepo.SaveModule(module3);

            courseRepo = new CoachingCourseRepositoryDocumentDB();
            moduleRepo = new CoachingModuleRepositoryDocumentDB();
            var foundCourses = courseRepo.GetItems(c => c.Name == courseName).Single();

            var foundModules = moduleRepo.GetItemsWithIds(foundCourses.Modules.Select(m => m.ModuleReferenceId)).ToList();

            Assert.AreEqual(foundModules.Count(), 3);

            Assert.IsNotNull(foundCourses);
        }