public async Task TakeExamAndAssertResult(
            HttpCallHelper httpCallHelper,
            int userExamId, bool fail, bool skipSomeQuestions = false)
        {
            var testResult = await TakeExam(userExamId, fail, skipSomeQuestions);

            var userExamDto = await httpCallHelper.EndUserExam(userExamId);

            var userExamResult = await httpCallHelper.PostUserExamResult(userExamId);

            Assert.True(userExamResult.IsPassed == !fail);
            Assert.True(userExamResult.RightAnswerCount == testResult.Item1);
            Assert.True(userExamResult.AnsweredQuestionCount == testResult.Item2);
            var passed = ((float)userExamResult.RightAnswerCount / (float)userExamResult.QuestionCount * 100) >= userExamDto.Exam.PassPercentage;

            Assert.True(passed == userExamResult.IsPassed);
            Assert.True(userExamResult.AnsweredQuestionCount == userExamResult.WrongAnswerCount + userExamResult.RightAnswerCount);
            Assert.True(userExamResult.QuestionCount >= userExamResult.AnsweredQuestionCount);
            Assert.True(userExamResult.QuestionCount == userExamResult.AnsweredQuestionCount + userExamResult.NotAnsweredQuestionCount);
        }
Пример #2
0
        public async void UserExamListTests()
        {
            var client         = httpClientFactory.CreateClient();
            var httpCallHelper = new HttpCallHelper(client);
            var user1          = (await httpCallHelper.CreateUserExam()).Item1;
            var user2          = (await httpCallHelper.CreateUserExam()).Item1;

            for (int i = 0; i < 3; i++)
            {
                await httpCallHelper.CreateUserExam(loggedUser : user1);

                await httpCallHelper.CreateUserExam(loggedUser : user2);

                await httpCallHelper.CreateUserExam(loggedUser : user1, isPrivate : true);

                await httpCallHelper.CreateUserExam(loggedUser : user2, isPrivate : true);

                //ended
                var userExamId = (await httpCallHelper.CreateUserExam(loggedUser: user1)).Item3.Id;
                client.Authorize(user1.Token);
                await httpCallHelper.EndUserExam(userExamId);

                userExamId = (await httpCallHelper.CreateUserExam(loggedUser: user1, isPrivate: true)).Item3.Id;
                client.Authorize(user1.Token);
                await httpCallHelper.EndUserExam(userExamId);

                userExamId = (await httpCallHelper.CreateUserExam(loggedUser: user2)).Item3.Id;
                client.Authorize(user2.Token);
                await httpCallHelper.EndUserExam(userExamId);

                userExamId = (await httpCallHelper.CreateUserExam(loggedUser: user2, isPrivate: true)).Item3.Id;
                client.Authorize(user2.Token);
                await httpCallHelper.EndUserExam(userExamId);
            }

            client.Unauthorize();

            var link             = "/userexams";
            var linkIncludeExams = "/userexams?includeExams=true";
            await client.GetUnauthorized(link);

            client.Authorize(user1.Token);

            var envelope = await client.GetUserExamsEnvelopeSuccesfully(link);

            Assert.Equal(envelope.UserExamCount, envelope.UserExams.Count());
            Assert.Equal(13, envelope.UserExamCount);
            foreach (var userExam in envelope.UserExams)
            {
                Assert.Null(userExam.Exam);
                Assert.Equal(userExam.UserId, user1.Id);
            }

            client.Authorize(user2.Token);

            envelope = await client.GetUserExamsEnvelopeSuccesfully(link);

            Assert.Equal(envelope.UserExamCount, envelope.UserExams.Count());
            Assert.Equal(13, envelope.UserExamCount);
            foreach (var userExam in envelope.UserExams)
            {
                Assert.Null(userExam.Exam);
                Assert.Equal(userExam.UserId, user2.Id);
            }
            envelope = await client.GetUserExamsEnvelopeSuccesfully(linkIncludeExams);

            Assert.Equal(envelope.UserExamCount, envelope.UserExams.Count());
            Assert.Equal(13, envelope.UserExamCount);
            foreach (var userExam in envelope.UserExams)
            {
                Assert.NotNull(userExam.Exam);
                Assert.Equal(userExam.UserId, user2.Id);
            }
            var limitOffsetTester = new LimitOffsetTester(client, link);
            await limitOffsetTester.DoTest(GetUserExams);
        }
        public async void QuestionAnswerCreateOrUpdateTests()
        {
            var client = httpClientFactory.CreateClient();

            var data            = new QuestionAnswerTestData(client);
            var httpCallHelper  = new HttpCallHelper(client);
            var dbContextHelper = new DbContextHelper(this.dbContextFactory);

            client.Unauthorize();

            var request = data.User1.CreateRadioQuestion1AnswerRequest();
            await client.PostUnauthorized(link, request);

            client.Authorize(data.User1.User.Token);

            //UserExamNotFoundException 1 non existing
            request = data.NonExistingRequest;
            var problem = await client.PostNotFound(link, request);

            //UserExamNotFoundException different user
            request = data.User2.CreateRadioQuestion1AnswerRequest();
            problem = await client.PostNotFound(link, request);

            //UserExamAlreadyEndedException 1 really ended
            client.Authorize(data.User3.User.Token);
            await httpCallHelper.EndUserExam(data.User3.UserExam.Id);

            request = data.User3.CreateRadioQuestion1AnswerRequest();
            problem = await client.PostBadRequest(link, request);

            //UserExamAlreadyEndedException 2 time is too late
            client.Authorize(data.User4.User.Token);
            await dbContextHelper.UpdateUserExamStartDate(data.User4.UserExam.Id, data.User4.Exam.TimeInMinutes * -1);

            request = data.User4.CreateRadioQuestion1AnswerRequest();
            problem = await client.PostBadRequest(link, request);

            var userExam = await dbContextHelper.SelectUserExamAsync(data.User4.UserExam.Id);

            Assert.NotNull(userExam.EndedAt);

            //QuestionNotFoundException 1 none existing question
            client.Authorize(data.User1.User.Token);
            request = data.User1.CreateRadioQuestion1AnswerRequest();
            request.UserExamQuestionAnswer.QuestionId = int.MaxValue;
            problem = await client.PostNotFound(link, request);

            //QuestionNotFoundException question of another exam
            request = data.User1.CreateRadioQuestion1AnswerRequest();
            var userExamDTO = (await httpCallHelper.CreateUserExam(loggedUser: data.User1.User)).Item3;

            client.Authorize(data.User1.User.Token);
            request.UserExamQuestionAnswer.UserExamId = userExamDTO.Id;
            problem = await client.PostNotFound(link, request);

            //AnswerToRadioQuestionFormatException send multiple answerss to radio
            request = data.User1.CreateRadioQuestion1AnswerRequest();
            var answerOptionIds = new List <int>(request.UserExamQuestionAnswer.AnswerOptionIds);

            answerOptionIds.Add(data.User1.RadioQuestion1AnswerIds[0]);
            answerOptionIds.Add(data.User1.RadioQuestion1AnswerIds[1]);
            request.UserExamQuestionAnswer.AnswerOptionIds = answerOptionIds.Distinct().ToArray();
            problem = await client.PostBadRequest(link, request);

            //AnswerOptionNotFoundException
            request = data.User1.CreateRadioQuestion1AnswerRequest(answerOptionIds: new int[] { int.MaxValue });
            problem = await client.PostNotFound(link, request);

            //InvalidAnswerOptionExamException other questions answer option.
            request = data.User1.CreateRadioQuestion1AnswerRequest(answerOptionIds: new int[] { data.User2.RadioQuestion2AnswerIds.First() });
            problem = await client.PostBadRequest(link, request);

            await UserUpdateQuestionAnswersTest(data.User1, client);

            client.Authorize(data.User2.User.Token);
            await UserUpdateQuestionAnswersTest(data.User2, client);
        }