public async void ShouldCreateExamAndFailWhenUnauthorized() { var client = httpClientFactory.CreateClient(); var httpCallHelper = new HttpCallHelper(client); var dbContextHelper = new DbContextHelper(this.dbContextFactory); var tags = SampleExamContextHelper.SeededTags.Select(e => e.TagId).ToArray(); var loggedUser = (await httpCallHelper.CreateUserAndLogin()).Item4; var examData = TestData.Exam.Create.NewExamData(true, false, tags); client.Authorize(loggedUser.Token); var responseExam = await client.PostExamSuccesfully("/exams", new Create.Request() { Exam = examData }); var exam = dbContextHelper.SelectExamWitTags(responseExam.Id); AssertHelper.AssertExam(examData, responseExam, exam); AssertHelper.AssertExamTags(examData.Tags.ToArray(), responseExam, exam); client.Unauthorize(); await client.PostUnauthorized("/exams", new Create.Request() { Exam = examData }); //should save without tags examData.Tags = null; client.Authorize(loggedUser.Token); responseExam = await client.PostExamSuccesfully("/exams", new Create.Request() { Exam = examData }); exam = dbContextHelper.SelectExamWitTags(responseExam.Id); AssertHelper.AssertExam(examData, responseExam, exam); Assert.True(responseExam.Tags.Count == 0); Assert.True(exam.ExamTags.Count == 0); }
public async void ShouldEditExam() { var client = httpClientFactory.CreateClient(); var httpCallHelper = new HttpCallHelper(client); var dbContextHelper = new DbContextHelper(this.dbContextFactory); var tuple = await httpCallHelper.CreateExam(); var loggedUser = tuple.Item1; var examDto = tuple.Item3; var putLink = $"/exams/{examDto.Id}"; var newTags = new List <string>(); newTags.Add(examDto.Tags.First().Tag); newTags.AddRange(SampleExamContextHelper.SeededTags.Select(e => e.TagId).ToArray()); var uniqueString = Guid.NewGuid().ToGuidString(); newTags.AddRange(new string[] { $"{uniqueString}_Tag1", $"{uniqueString}_Tag2" }); var examData = new Edit.ExamData() { Title = $"{examDto.Title}_2", Description = $"{examDto.Description}_2", TimeInMinutes = examDto.TimeInMinutes + 1, PassPercentage = examDto.PassPercentage + 1, IsPrivate = !examDto.IsPrivate, Tags = newTags }; await client.PutUnauthorized(putLink, new Edit.Request() { Exam = examData }); client.Authorize(loggedUser.Token); var responseExam = await client.PutExamSuccesfully(putLink, new Edit.Request() { Exam = examData }); var exam = dbContextHelper.SelectExamWitTags(examDto.Id); var updatedAt1 = exam.UpdatedAt; AssertHelper.AssertExam(examData, responseExam, exam); AssertHelper.AssertExamTags(examData.Tags.ToArray(), responseExam, exam); responseExam = await client.PutExamSuccesfully(putLink, new Edit.Request() { Exam = examData }); exam = dbContextHelper.SelectExamWitTags(examDto.Id); var updatedAt2 = exam.UpdatedAt; AssertHelper.AssertExam(examData, responseExam, exam); AssertHelper.AssertExamTags(examData.Tags.ToArray(), responseExam, exam); Assert.Equal(updatedAt1, updatedAt2); responseExam = await client.PutExamSuccesfully(putLink, new Edit.Request() { Exam = new Edit.ExamData() }); exam = dbContextHelper.SelectExamWitTags(examDto.Id); var updatedAt3 = exam.UpdatedAt; AssertHelper.AssertExam(examData, responseExam, exam); AssertHelper.AssertExamTags(examData.Tags.ToArray(), responseExam, exam); Assert.Equal(updatedAt2, updatedAt3); }