Exemplo n.º 1
0
 public DataController(ISecurityService securityService,
                       IBinaryService binaryService,
                       IQuestionService questionService,
                       IVersionService versionService,
                       ITagService tagService,
                       ICourseService courseService,
                       ICommentsService commentsService,
                       IUserProfileService userProfileService,
                       ICourseInstanceService courseInstanceService,
                       ITextService textService,
                       IExportService exportService,
                       INotificationService notificationService,
                       IFavoriteService favoriteService)
 {
     _securityService       = securityService;
     _binaryService         = binaryService;
     _questionService       = questionService;
     _tagService            = tagService;
     _courseService         = courseService;
     _commentsService       = commentsService;
     _userProfileService    = userProfileService;
     _courseInstanceService = courseInstanceService;
     _textService           = textService;
     _exportService         = exportService;
     _versionService        = versionService;
     _notificationService   = notificationService;
     _favoriteService       = favoriteService;
 }
Exemplo n.º 2
0
        public async Task TestNotEnoughQuestion()
        {
            //Prepare
            TestingContext context = new TestingContext();

            context.AddPrincipalMock();
            context.AddBinaryServiceMock();
            context.AddInMemoryDb();
            context.AddMockLogService();
            context.AddGermanCultureServiceMock();
            context.AddQuestionService();
            CourseService courseService = context.GetService <CourseService>();

            context.DependencyMap[typeof(ICourseService)] = courseService;

            ApplicationDbContext dbContext = context.GetSimple <ApplicationDbContext>();
            Course course = dbContext.Courses.First();

            course.NumQuestionsToAsk = 100;

            ICourseInstanceService courseInstanceService = context.GetService <CourseInstanceService>();

            //Act
            var courseInstance = await courseInstanceService.StartCourseAsync(course.Id);

            //Assert
            Assert.Equal(10, courseInstance.NumQuestionsTotal);
        }
Exemplo n.º 3
0
        public async Task TestNotEnoughQuestion()
        {
            //Prepare
            TestingContext testingContext = new TestingContext();

            InitTestingContext(testingContext);

            CourseService courseService = testingContext.GetService <CourseService>();

            testingContext.DependencyMap[typeof(ICourseService)] = courseService;

            ApplicationDbContext dbContext = testingContext.GetSimple <ApplicationDbContext>();
            Course course = dbContext.Courses.First();

            course.NumQuestionsToAsk = 100;

            ICourseInstanceService courseInstanceService = testingContext.GetService <CourseInstanceService>();

            //Act
            var courseInstance = await courseInstanceService.StartCourseAsync(course.Id);

            //Assert
            Assert.Equal(10, courseInstance.NumQuestionsTotal);
        }
Exemplo n.º 4
0
        public async Task TestStartTest()
        {
            TestingContext testingContext = new TestingContext();

            InitTestingContext(testingContext);

            ICourseService courseService = testingContext.GetService <CourseService>();

            testingContext.DependencyMap[typeof(ICourseService)] = courseService;

            ICourseInstanceService courseInstanceService = testingContext.GetService <CourseInstanceService>();


            var courses = await courseService.GetCoursesAsync(0);

            int courseId = courses.Data.Select(x => x.Id).First();

            //Act
            CourseInstanceDto result = await courseInstanceService.StartCourseAsync(courseId);

            Assert.True(result.IdCourseInstance > 0);
            Assert.True(result.IdCourse == courseId);
            Assert.True(result.IdCourseInstanceQuestion > 0);
            Assert.True(result.NumQuestionsAlreadyAsked == 0);
            Assert.True(result.NumQuestionsTotal > 0);

            CourseInstanceDto result2 = await courseInstanceService.NextQuestion(result.IdCourseInstance);

            Assert.True(result2.IdCourse == courseId);
            Assert.True(result2.IdCourseInstanceQuestion > 0);
            Assert.True(result2.NumQuestionsAlreadyAsked == 1);
            Assert.True(result2.NumQuestionsTotal > 0);

            CourseInstanceDto result3 = await courseInstanceService.NextQuestion(result.IdCourseInstance);

            Assert.True(result3.IdCourse == courseId);
            Assert.True(result3.IdCourseInstanceQuestion > 0);
            Assert.True(result3.NumQuestionsAlreadyAsked == 2);
            Assert.True(result3.NumQuestionsTotal > 0);

            QuestionToAskDto result4 = await courseInstanceService.GetQuestionToAskAsync(result.IdCourseInstanceQuestion);

            Assert.Equal(QuestionType.MultipleChoice, result4.QuestionType);

            QuestionAnswerDto answer = new QuestionAnswerDto();

            answer.IdCourseInstanceQuestion = result.IdCourseInstanceQuestion;
            answer.Answers.Add(false);
            answer.Answers.Add(true);
            answer.Answers.Add(false);
            answer.Answers.Add(true);

            QuestionDto result5 = await courseInstanceService.AnswerQuestionAndGetSolutionAsync(answer);

            Assert.True(result5.Explanation != null);
            Assert.Equal(4, result5.Options.Count);
            Assert.True(result5.Options[1].IsTrue);
            Assert.True(result5.Options[3].IsTrue);


            CourseInstanceDto result6 = await courseInstanceService.AnswerQuestionAndGetNextQuestionAsync(answer);

            Assert.True(result6.AnsweredCorrectly);
            Assert.True(result6.Done);
            Assert.Equal(3, result6.NumQuestionsAlreadyAsked);
            Assert.Equal(3, result6.NumQuestionsTotal);
        }