11namespace DigitalLearningSolutions . Web . Tests . Controllers . LearningMenu
22{
3+ using DigitalLearningSolutions . Data . Models . Progress ;
34 using DigitalLearningSolutions . Web . Tests . TestHelpers ;
45 using DigitalLearningSolutions . Web . ViewModels . LearningMenu ;
56 using FakeItEasy ;
67 using FluentAssertions ;
78 using FluentAssertions . AspNetCore . Mvc ;
89 using Microsoft . AspNetCore . Http ;
910 using NUnit . Framework ;
11+ using System . Collections . Generic ;
1012
1113 public partial class LearningMenuControllerTests
1214 {
@@ -15,6 +17,11 @@ public void Index_should_render_view()
1517 {
1618 // Given
1719 var expectedCourseContent = CourseContentHelper . CreateDefaultCourseContent ( CustomisationId ) ;
20+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
21+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
22+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
23+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
24+ ) ;
1825 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) )
1926 . Returns ( expectedCourseContent ) ;
2027 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) ) . Returns ( 10 ) ;
@@ -38,7 +45,13 @@ public void Index_should_redirect_to_section_page_if_one_section_in_course()
3845 var section = CourseContentHelper . CreateDefaultCourseSection ( id : sectionId ) ;
3946 var expectedCourseContent = CourseContentHelper . CreateDefaultCourseContent ( customisationId ) ;
4047 expectedCourseContent . Sections . Add ( section ) ;
48+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
49+ course . CustomisationId = customisationId ;
4150
51+ A . CallTo ( ( ) => courseService . GetCourse ( customisationId ) ) . Returns ( course ) ;
52+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , customisationId ) ) . Returns (
53+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
54+ ) ;
4255 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , customisationId ) )
4356 . Returns ( expectedCourseContent ) ;
4457 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , customisationId , CentreId ) ) . Returns ( 10 ) ;
@@ -67,6 +80,13 @@ public void Index_should_not_redirect_to_section_page_if_more_than_one_section_i
6780
6881 var expectedCourseContent = CourseContentHelper . CreateDefaultCourseContent ( customisationId ) ;
6982 expectedCourseContent . Sections . AddRange ( new [ ] { section1 , section2 , section3 } ) ;
83+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
84+ course . CustomisationId = customisationId ;
85+
86+ A . CallTo ( ( ) => courseService . GetCourse ( customisationId ) ) . Returns ( course ) ;
87+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , customisationId ) ) . Returns (
88+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
89+ ) ;
7090
7191 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , customisationId ) )
7292 . Returns ( expectedCourseContent ) ;
@@ -86,6 +106,12 @@ public void Index_should_not_redirect_to_section_page_if_more_than_one_section_i
86106 public void Index_should_return_404_if_unknown_course ( )
87107 {
88108 // Given
109+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
110+
111+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
112+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
113+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
114+ ) ;
89115 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) ) . Returns ( null ) ;
90116 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) )
91117 . Returns ( 3 ) ;
@@ -106,6 +132,12 @@ public void Index_should_return_404_if_unable_to_enrol()
106132 {
107133 // Given
108134 var defaultCourseContent = CourseContentHelper . CreateDefaultCourseContent ( CustomisationId ) ;
135+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
136+
137+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
138+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
139+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
140+ ) ;
109141 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) )
110142 . Returns ( defaultCourseContent ) ;
111143 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) )
@@ -127,6 +159,13 @@ public void Index_always_calls_get_course_content()
127159 {
128160 // Given
129161 const int customisationId = 1 ;
162+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
163+
164+ A . CallTo ( ( ) => courseService . GetCourse ( customisationId ) ) . Returns ( course ) ;
165+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , customisationId ) ) . Returns (
166+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
167+ ) ;
168+
130169
131170 // When
132171 controller . Index ( 1 , 2 ) ;
@@ -141,6 +180,12 @@ public void Index_valid_customisation_id_should_update_login_and_duration()
141180 // Given
142181 const int progressId = 13 ;
143182 var defaultCourseContent = CourseContentHelper . CreateDefaultCourseContent ( CustomisationId ) ;
183+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
184+
185+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
186+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
187+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
188+ ) ;
144189 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) )
145190 . Returns ( defaultCourseContent ) ;
146191 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) ) . Returns ( progressId ) ;
@@ -197,6 +242,12 @@ public void Index_valid_customisationId_should_StartOrUpdate_course_sessions()
197242 {
198243 // Given
199244 var defaultCourseContent = CourseContentHelper . CreateDefaultCourseContent ( CustomisationId ) ;
245+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
246+
247+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
248+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
249+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
250+ ) ;
200251 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) )
201252 . Returns ( defaultCourseContent ) ;
202253 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) ) . Returns ( 1 ) ;
@@ -291,6 +342,13 @@ public void Index_not_detects_id_manipulation_self_register_true()
291342 {
292343 // Given
293344 var expectedCourseContent = CourseContentHelper . CreateDefaultCourseContent ( CustomisationId ) ;
345+
346+ var course = CourseContentHelper . CreateDefaultCourse ( ) ;
347+
348+ A . CallTo ( ( ) => courseService . GetCourse ( CustomisationId ) ) . Returns ( course ) ;
349+ A . CallTo ( ( ) => progressService . GetDelegateProgressForCourse ( CandidateId , CustomisationId ) ) . Returns (
350+ new List < Progress > { new Progress { ProgressId = 1 , Completed = null , RemovedDate = null } }
351+ ) ;
294352 A . CallTo ( ( ) => courseContentService . GetCourseContent ( CandidateId , CustomisationId ) )
295353 . Returns ( expectedCourseContent ) ;
296354 A . CallTo ( ( ) => courseContentService . GetOrCreateProgressId ( CandidateId , CustomisationId , CentreId ) ) . Returns ( 10 ) ;
0 commit comments