Esempio n. 1
0
        public async void TestExport()
        {
            //Prepare
            TestingContext testingContext = new TestingContext();

            testingContext.AddAdminPrincipalMock();
            testingContext.AddBinaryServiceMock();
            testingContext.AddInMemoryDb();
            testingContext.AddUserService();
            testingContext.AddBusinessSecurityService();
            testingContext.AddLogServiceMock();
            testingContext.AddGermanCultureServiceMock();
            testingContext.AddQuestionService();

            IExportService exportService = testingContext.GetService <ExportService>();

            //Act
            Stream stream = await exportService.Export();

            //Assert
            ZipArchive      arch           = new ZipArchive(stream);
            ZipArchiveEntry entry          = arch.GetEntry("questions.json");
            Stream          zipEntryStream = entry.Open();

            using (var reader = new StreamReader(zipEntryStream, Encoding.UTF8))
            {
                string value = reader.ReadToEnd();
                IList <QuestionDto> questions = JsonConvert.DeserializeObject <IList <QuestionDto> >(value);
                Assert.True(questions.Count > 0);
            }
            Assert.True(arch.Entries.Count > 0);
        }
Esempio 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);
        }
Esempio n. 3
0
 private void SetUpTestingContext(TestingContext testingContext)
 {
     testingContext.AddPrincipalMock();
     testingContext.AddBinaryServiceMock();
     testingContext.AddMockLogService();
     testingContext.AddInMemoryDb();
 }
Esempio n. 4
0
 private void SetupContext(TestingContext context)
 {
     context.AddPrincipalMock();
     context.AddBinaryServiceMock();
     context.AddInMemoryDb();
     context.AddLogServiceMock();
     context.AddCacheService();
 }
Esempio n. 5
0
 private void SetUpTestingContext(TestingContext testingContext)
 {
     testingContext.AddPrincipalMock();
     testingContext.AddBinaryServiceMock();
     testingContext.AddLogServiceMock();
     testingContext.AddInMemoryDb();
     testingContext.AddUserService();
     testingContext.AddBusinessSecurityService();
 }
Esempio n. 6
0
 private void InitContext(TestingContext context)
 {
     context.AddPrincipalMock();
     context.AddInMemoryDb();
     context.AddMockLogService();
     context.AddGermanCultureServiceMock();
     context.AddBinaryServiceMock();
     context.AddQuestionService();
     context.DependencyMap[typeof(IBinaryService)] = context.GetService <BinaryService>();
 }
Esempio n. 7
0
 private void InitTestingContext(TestingContext testingContext)
 {
     testingContext.AddPrincipalMock();
     testingContext.AddBinaryServiceMock();
     testingContext.AddInMemoryDb();
     testingContext.AddUserService();
     testingContext.AddBusinessSecurityService();
     testingContext.AddLogServiceMock();
     testingContext.AddGermanCultureServiceMock();
     testingContext.AddQuestionService();
 }
Esempio n. 8
0
 private void InitContext(TestingContext testingContext)
 {
     testingContext.AddPrincipalMock();
     testingContext.AddInMemoryDb();
     testingContext.AddUserService();
     testingContext.AddBusinessSecurityService();
     testingContext.AddLogServiceMock();
     testingContext.AddGermanCultureServiceMock();
     testingContext.AddBinaryServiceMock();
     testingContext.AddQuestionService();
     testingContext.DependencyMap[typeof(IBinaryService)] = testingContext.GetService <BinaryService>();
 }
Esempio n. 9
0
        private void SetUpTestingContext(TestingContext testingContext)
        {
            testingContext.AddPrincipalMock();
            testingContext.AddBinaryServiceMock();
            testingContext.AddLogServiceMock();
            testingContext.AddCranAppSettings();
            testingContext.AddInfoTextServiceMock();
            testingContext.AddInMemoryDb();
            testingContext.AddUserService();

            Mock <IWebPushClient> webPushClientMock = new Mock <IWebPushClient>(MockBehavior.Loose);

            webPushClientMock.Setup(x => x.SendNotificationAsync(It.IsAny <PushSubscription>(),
                                                                 It.IsAny <string>(), It.IsAny <VapidDetails>()))
            .Returns(Task.CompletedTask);

            testingContext.DependencyMap[typeof(IWebPushClient)] = webPushClientMock.Object;
        }
Esempio n. 10
0
        private void SetUpTestingContext(TestingContext testingContext)
        {
            testingContext.AddPrincipalMock();
            testingContext.AddInMemoryDb();
            testingContext.AddUserService();
            testingContext.AddBusinessSecurityService();
            testingContext.AddLogServiceMock();
            testingContext.AddGermanCultureServiceMock();
            testingContext.AddBinaryServiceMock();
            testingContext.AddInfoTextServiceMock();
            testingContext.AddCacheService();
            testingContext.DependencyMap[typeof(ICommentsService)] = testingContext.GetService <CommentsService>();
            testingContext.DependencyMap[typeof(ITagService)]      = testingContext.GetService <TagService>();



            Mock <INotificationService> notificationMock = new Mock <INotificationService>(MockBehavior.Loose);

            notificationMock.Setup(x => x.SendNotificationAboutQuestionAsync(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.CompletedTask);

            testingContext.DependencyMap[typeof(INotificationService)] = notificationMock.Object;
        }
Esempio n. 11
0
        public async Task TestStartTest()
        {
            TestingContext context = new TestingContext();

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

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

            ICourseInstanceService courseInstanceService = context.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);
        }