public async void AllDetailsTests()
        {
            var client = httpClientFactory.CreateClient();
            var data   = new QuestionTestData(client);

            var linkNoneExisting          = $"/questions/{int.MaxValue}";
            var u1PublicNotPublishedLink  = $"/questions/{data.u1PublicNotPublished.Item5.Id}";
            var u1PublicPublishedLink     = $"/questions/{data.u1PublicPublished.Item5.Id}";
            var u1PrivateNotPublishedLink = $"/questions/{data.u1PrivateNotPublished.Item5.Id}";
            var u1PrivatePublishedLink    = $"/questions/{data.u1PrivatePublished.Item5.Id}";

            var u2PublicNotPublishedLink  = $"/questions/{data.u2PublicNotPublished.Item5.Id}";
            var u2PublicPublishedLink     = $"/questions/{data.u2PublicPublished.Item5.Id}";
            var u2PrivateNotPublishedLink = $"/questions/{data.u2PrivateNotPublished.Item5.Id}";
            var u2PrivatePublishedLink    = $"/questions/{data.u2PrivatePublished.Item5.Id}";

            client.Unauthorize();
            //non-existing
            await client.GetNotFound(linkNoneExisting);

            //user 1
            await client.GetNotFound(u1PublicNotPublishedLink);

            var questionDto = await client.GetQuestionSuccesfully(u1PublicPublishedLink);

            Assert.Equal(questionDto.Id, data.u1PublicPublished.Item5.Id);
            Assert.Equal(0, questionDto.AnswerOptions.Count);

            await client.GetNotFound(u1PrivateNotPublishedLink);

            await client.GetNotFound(u1PrivatePublishedLink);

            //user 2
            await client.GetNotFound(u2PublicNotPublishedLink);

            questionDto = await client.GetQuestionSuccesfully(u2PublicPublishedLink);

            Assert.Equal(questionDto.Id, data.u2PublicPublished.Item5.Id);
            Assert.Equal(0, questionDto.AnswerOptions.Count);

            await client.GetNotFound(u2PrivateNotPublishedLink);

            await client.GetNotFound(u2PrivatePublishedLink);

            questionDto = await client.GetQuestionSuccesfully($"{u1PublicPublishedLink}?includeAnswerOptions=true");

            Assert.Equal(questionDto.Id, data.u1PublicPublished.Item5.Id);
            Assert.Equal(data.u1PublicPublished.Item5.AnswerOptions.Count, questionDto.AnswerOptions.Count);
        }
        public async void UserExamCreateTests()
        {
            var client = httpClientFactory.CreateClient();
            var data   = new QuestionTestData(client);
            var helper = new HttpCallHelper(client);

            client.Unauthorize();
            var u1PublicNotPublishedLink  = $"/userexams/{data.u1PublicNotPublished.Item3.Id}";
            var u1PublicPublishedLink     = $"/userexams/{data.u1PublicPublished.Item3.Id}";
            var u1PrivateNotPublishedLink = $"/userexams/{data.u1PrivateNotPublished.Item3.Id}";
            var u1PrivatePublishedLink    = $"/userexams/{data.u1PrivatePublished.Item3.Id}";

            var u2PublicNotPublishedLink  = $"/userexams/{data.u2PublicNotPublished.Item3.Id}";
            var u2PublicPublishedLink     = $"/userexams/{data.u2PublicPublished.Item3.Id}";
            var u2PrivateNotPublishedLink = $"/userexams/{data.u2PrivateNotPublished.Item3.Id}";
            var u2PrivatePublishedLink    = $"/userexams/{data.u2PrivatePublished.Item3.Id}";
            var linkNoneExisting          = $"/userexams/{int.MaxValue}";

            await client.PostUnauthorized(u1PublicNotPublishedLink);

            //login user1
            client.Authorize(data.u1PublicNotPublished.Item1.Token);

            await client.PostNotFound(linkNoneExisting);

            await client.PostNotFound(u1PublicNotPublishedLink);

            var userExamDto = await client.PostUserExamSuccesfully(u1PublicPublishedLink);

            AssertHelper.AsserUserExam(userExamDto);

            await client.PostNotFound(u1PrivateNotPublishedLink);

            userExamDto = await client.PostUserExamSuccesfully(u1PrivatePublishedLink);

            AssertHelper.AsserUserExam(userExamDto);

            await client.PostNotFound(u2PublicNotPublishedLink);

            userExamDto = await client.PostUserExamSuccesfully(u2PublicPublishedLink);

            AssertHelper.AsserUserExam(userExamDto);

            await client.PostNotFound(u2PrivateNotPublishedLink);

            await client.PostNotFound(u2PrivatePublishedLink);
        }
Example #3
0
        public async void AllListAuthQuestionsTest()
        {
            var client = httpClientFactory.CreateClient();
            var data   = new QuestionTestData(client);
            var helper = new HttpCallHelper(client);

            client.Unauthorize();
            var u1PublicNotPublishedLink  = $"/questions/private?examId={data.u1PublicNotPublished.Item3.Id}";
            var u1PublicPublishedLink     = $"/questions/private?examId={data.u1PublicPublished.Item3.Id}";
            var u1PrivateNotPublishedLink = $"/questions/private?examId={data.u1PrivateNotPublished.Item3.Id}";
            var u1PrivatePublishedLink    = $"/questions/private?examId={data.u1PrivatePublished.Item3.Id}";

            var u2PublicNotPublishedLink  = $"/questions/private?examId={data.u2PublicNotPublished.Item3.Id}";
            var u2PublicPublishedLink     = $"/questions/private?examId={data.u2PublicPublished.Item3.Id}";
            var u2PrivateNotPublishedLink = $"/questions/private?examId={data.u2PrivateNotPublished.Item3.Id}";
            var u2PrivatePublishedLink    = $"/questions/private?examId={data.u2PrivatePublished.Item3.Id}";
            var linkNoneExisting          = $"/questions/private?examId={int.MaxValue}";

            //login user1
            client.Authorize(data.u1PublicNotPublished.Item1.Token);

            await client.GetNotFound(linkNoneExisting);

            var questionsEnvelope = await client.GetQuestionsSuccesfully(u1PublicNotPublishedLink);

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(0, questionsEnvelope.Questions.First().AnswerOptions.Count);

            questionsEnvelope = await client.GetQuestionsSuccesfully(u1PublicPublishedLink);

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(0, questionsEnvelope.Questions.First().AnswerOptions.Count);

            questionsEnvelope = await client.GetQuestionsSuccesfully(u1PrivateNotPublishedLink);

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(0, questionsEnvelope.Questions.First().AnswerOptions.Count);

            questionsEnvelope = await client.GetQuestionsSuccesfully(u1PrivatePublishedLink);

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(0, questionsEnvelope.Questions.First().AnswerOptions.Count);

            await client.GetNotFound(u2PublicNotPublishedLink);

            questionsEnvelope = await client.GetQuestionsSuccesfully(u2PublicPublishedLink);

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(0, questionsEnvelope.Questions.First().AnswerOptions.Count);

            await client.GetNotFound(u2PrivateNotPublishedLink);

            await client.GetNotFound(u2PrivatePublishedLink);

            //includeAnswerOptions
            questionsEnvelope = await client.GetQuestionsSuccesfully($"{u1PublicNotPublishedLink}&includeAnswerOptions=true");

            Assert.Equal(questionsEnvelope.QuestionCount, questionsEnvelope.Questions.Count());
            Assert.Equal(1, questionsEnvelope.QuestionCount);
            Assert.Equal(data.u1PublicNotPublished.Item5.AnswerOptions.Count, questionsEnvelope.Questions.First().AnswerOptions.Count);

            //  limit , offset
            for (int i = 0; i < 11; i++)
            {
                await helper.CreateQuestionInExam(
                    data.u1PublicNotPublished.Item1.Token,
                    data.u1PublicNotPublished.Item3.Id, i % 2 == 0);
            }

            //login user1
            client.Authorize(data.u1PublicNotPublished.Item1.Token);

            var limitOffsetTester = new LimitOffsetTester(client, u1PublicNotPublishedLink);
            await limitOffsetTester.DoTest(QuestionHelper.GetQuestions);
        }