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 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); }
public async void ShouldGetUserExams() { var client = httpClientFactory.CreateClient(); var httpCallHelper = new HttpCallHelper(client); //create 4 public user exam out of 2 are published var tuple = await httpCallHelper.CreateExam(); var user = tuple.Item1; await httpCallHelper.CreateExam(true, false, null, user); await httpCallHelper.CreatePublishedExam(true, false, null, user); await httpCallHelper.CreatePublishedExam(true, false, null, user); //create 4 private user exam out of 2 are await httpCallHelper.CreateExam(true, true, null, user); await httpCallHelper.CreateExam(true, true, null, user); await httpCallHelper.CreatePublishedExam(true, true, null, user); await httpCallHelper.CreatePublishedExam(true, true, null, user); var linkAll1 = "exams/user/exams"; var linkAll2 = "exams/user/exams?privateType=all&publishType=all"; var linkAllPrivates = "exams/user/exams?privateType=private"; var linkAllPublics = "exams/user/exams?privateType=public"; var linkAllPublished = "exams/user/exams?publishType=published"; var linkAllNotPublished = "exams/user/exams?publishType=notPublished"; await client.GetUnauthorized(linkAll1); client.Authorize(user.Token); //all var exams = await client.GetExamsSuccesfully(linkAll1); Assert.True(exams.Count() == 8); //all2 exams = await client.GetExamsSuccesfully(linkAll2); Assert.True(exams.Count() == 8); //privates exams = await client.GetExamsSuccesfully(linkAllPrivates); Assert.True(exams.Count() == 4); //publics exams = await client.GetExamsSuccesfully(linkAllPublics); Assert.True(exams.Count() == 4); //published exams = await client.GetExamsSuccesfully(linkAllPublished); Assert.True(exams.Count() == 4); //not published exams = await client.GetExamsSuccesfully(linkAllNotPublished); Assert.True(exams.Count() == 4); //creating more user exams ... for (int i = 0; i < 5; i++) { var isPrivate = i % 2 == 0; await httpCallHelper.CreateExam(true, isPrivate, null, user); } //authorize after create exam unauthirized client.Authorize(user.Token); var limitOffsetTester = new LimitOffsetTester(client, linkAll1); await limitOffsetTester.DoTest(GetExams); }
public async void ShouldSelectPublishedExams() { var client = httpClientFactory.CreateClient(); var httpCallHelper = new HttpCallHelper(client); var dbContextHelper = new DbContextHelper(this.dbContextFactory); //create at least two public and two private exams var tuple = await httpCallHelper.CreateExam(); var examPublicDto1 = tuple.Item3; tuple = await httpCallHelper.CreateExam(); var examPublicDto2 = tuple.Item3; tuple = await httpCallHelper.CreateExam(true, true); var examPrivateDto1 = tuple.Item3; tuple = await httpCallHelper.CreateExam(true, true); var examPrivateDto2 = tuple.Item3; await dbContextHelper.SetPublishExamAsync(examPublicDto1.Id); await dbContextHelper.SetPublishExamAsync(examPublicDto2.Id); await dbContextHelper.SetPublishExamAsync(examPrivateDto1.Id); await dbContextHelper.SetPublishExamAsync(examPrivateDto2.Id); var getLink = "exams"; var getLinkIncludeTags = "exams?includeTags=true"; var getLinkIncludeUser = "******"; var getLinkIncludeTagsAndUser = "******"; //no user and tags var responseExams = await client.GetExamsSuccesfully(getLink); foreach (var exam in responseExams) { Assert.True(exam.IsPublished); Assert.False(exam.IsPrivate); AssertHelper.AssertNoUserAndNoTagsIncluded(exam); } //with tags responseExams = await client.GetExamsSuccesfully(getLinkIncludeTags); foreach (var exam in responseExams) { Assert.True(exam.IsPublished); Assert.False(exam.IsPrivate); AssertHelper.AssertOnlyTagsIncluded(exam); } //with user responseExams = await client.GetExamsSuccesfully(getLinkIncludeUser); foreach (var exam in responseExams) { Assert.True(exam.IsPublished); Assert.False(exam.IsPrivate); AssertHelper.AssertOnlyUserIncluded(exam); } //with tags and user responseExams = await client.GetExamsSuccesfully(getLinkIncludeTagsAndUser); foreach (var exam in responseExams) { Assert.True(exam.IsPublished); Assert.False(exam.IsPrivate); Assert.NotNull(exam.User); if (exam.Id == examPublicDto2.Id || exam.Id == examPublicDto1.Id) { Assert.True(exam.Tags.Count > 0); } } //limit, ofset tests... //creating some exams for (int i = 0; i < 11; i++) { tuple = await httpCallHelper.CreateExam(); var examId = tuple.Item3.Id; var token = tuple.Item1.Token; client.Authorize(token); await httpCallHelper.PublishExam(examId); } var limitOffsetTester = new LimitOffsetTester(client, getLink); await limitOffsetTester.DoTest(GetExams); }