public async Task Map_MetadataLookup_ReturnsLookupItems() { var mappingService = new TopicMappingService(_topicRepository, new FakeViewModelLookupService()); var topic = TopicFactory.Create("Test", "MetadataLookup"); var target = (MetadataLookupTopicViewModel?)await mappingService.MapAsync(topic).ConfigureAwait(false); Assert.AreEqual<int>(5, target.Categories.Count); }
public async Task Map_TopicReferences_ReturnsMappedModel() { var mappingService = new TopicMappingService(_topicRepository, new FakeViewModelLookupService()); var topicReference = _topicRepository.Load(11111); var topic = TopicFactory.Create("Test", "TopicReference"); topic.Attributes.SetInteger("TopicReferenceId", topicReference.Id); var target = (TopicReferenceTopicViewModel?)await mappingService.MapAsync(topic).ConfigureAwait(false); Assert.IsNotNull(target.TopicReference); Assert.AreEqual<string>(topicReference.Key, target.TopicReference.Key); }
/*========================================================================================================================== | METHOD: INVOKE (ASYNC) \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Provides the pagel-level navigation menu for the current page, which exposes one tier of navigation from the nearest /// page group. /// </summary> public async Task<IViewComponentResult> InvokeAsync(bool moveNext) { /*------------------------------------------------------------------------------------------------------------------------ | Identify adjacent topic \-----------------------------------------------------------------------------------------------------------------------*/ var adjacentTopic = GetAdjacentTopic(CurrentTopic.Parent, CurrentTopic, moveNext); var label = moveNext? "Next Lesson" : "Previous Lesson"; /*------------------------------------------------------------------------------------------------------------------------ | Fallback to adjacent unit \-----------------------------------------------------------------------------------------------------------------------*/ if (adjacentTopic is null) { var adjacentUnit = GetAdjacentTopic(CurrentTopic.Parent.Parent, CurrentTopic.Parent, moveNext); if (adjacentUnit is not null) { adjacentTopic = moveNext? adjacentUnit.Children.FirstOrDefault() : adjacentUnit.Children.LastOrDefault(); label = moveNext? "Next Unit" : "Previous Unit"; } } /*------------------------------------------------------------------------------------------------------------------------ | Fallback to course \-----------------------------------------------------------------------------------------------------------------------*/ if (adjacentTopic is null) { adjacentTopic = CurrentTopic.Parent.Parent; label = moveNext? "Finish Course" : "Return to Syllabus"; } /*------------------------------------------------------------------------------------------------------------------------ | Map adjacent topic \-----------------------------------------------------------------------------------------------------------------------*/ var topicViewModel = new LessonPagingTopicViewModel { Label = label, MoveNext = moveNext }; topicViewModel = (LessonPagingTopicViewModel)await TopicMappingService.MapAsync(adjacentTopic, topicViewModel).ConfigureAwait(true); /*------------------------------------------------------------------------------------------------------------------------ | Return the corresponding view \-----------------------------------------------------------------------------------------------------------------------*/ return View(topicViewModel); }