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 }); }
public static ModuleResourceDTO ConvertToDTO(CoachingModuleResource entity) { return(new ModuleResourceDTO { Id = entity.Id, Created = entity.Created, Version = entity.Version, Content = entity.Content }); }
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><Overskrift her></h1> <p><Kort tekst her></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&badge=0&portrait=0&title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2><Overskrift, start på udvidet intro></h2> <p><Intro her></p> <h2><Overskrift, eksterne henvisninger></h2> <p><a href='http://wikipedia.org'><Eksempel på link></a></p>" }; var exercise = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her, efterfulgt af ></p> <SortableList/>") } }; var reflection = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her></p> <h2> </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"); }
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"); }
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><Overskrift her></h1> <p><Kort tekst her></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&badge=0&portrait=0&title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2><Overskrift, start på udvidet intro></h2> <p><Intro her></p> <h2><Overskrift, eksterne henvisninger></h2> <p><a href='http://wikipedia.org'><Eksempel på link></a></p>" }; var exercise = new CoachingModuleExerciseResource() { Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement(""), new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her, evt. efterfulgt af opgave: ></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); }
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><Overskrift her></h1> <p><Kort tekst her></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&badge=0&portrait=0&title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2><Overskrift, start på udvidet intro></h2> <p><Intro her></p> <h2><Overskrift, eksterne henvisninger></h2> <p><a href='http://wikipedia.org'><Eksempel på link></a></p>" }; var exercise1 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her, efterfulgt af ></p> <SortableList/>") } }; var reflection1 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her></p> <h2> </h2>") } }; var module1 = new CoachingModule ( "My coaching module 1", introduction1, exercise1, reflection1 ); var introduction2 = new CoachingModuleResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1><Overskrift her></h1> <p><Kort tekst her></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&badge=0&portrait=0&title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2><Overskrift, start på udvidet intro></h2> <p><Intro her></p> <h2><Overskrift, eksterne henvisninger></h2> <p><a href='http://wikipedia.org'><Eksempel på link></a></p>" }; var exercise2 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her, efterfulgt af ></p> <SortableList/>") } }; var reflection2 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her></p> <h2> </h2>") } }; var module2 = new CoachingModule ( "My coaching module 2", introduction2, exercise2, reflection2 ); var introduction3 = new CoachingModuleResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Content = "<h1><Overskrift her></h1> <p><Kort tekst her></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&badge=0&portrait=0&title=0' style='top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;' webkitallowfullscreen='true'></iframe></div> </div> <h2><Overskrift, start på udvidet intro></h2> <p><Intro her></p> <h2><Overskrift, eksterne henvisninger></h2> <p><a href='http://wikipedia.org'><Eksempel på link></a></p>" }; var exercise3 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her, efterfulgt af ></p> <SortableList/>") } }; var reflection3 = new CoachingModuleExerciseResource() { RevisionHistory = new ResourseRevisionHistoryReference(), Elements = new List <ResourceExerciseElement>() { new ResourceExerciseElement("<h1><Overskrift her></h1> <p><Kort tekst her></p> <h2> </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); }