public GenericOperationResult <StudentQuizResult> ProcessResults(Quiz takenQuiz, string studentName) { var result = OperationResult.GetGenericResultObject <StudentQuizResult>(); try { //create a new student quiz result var studentQuizResult = new StudentQuizResult(); //get the actual quiz and student that took the quiz var actualQuiz = _quizRepository.GetItem(takenQuiz.Id); var student = _userService.GetUser(studentName); //compare the results var compareResults = CompareQuizes(actualQuiz, takenQuiz); // get the measurments from the compared result and the actual quiz var totalPoints = actualQuiz.Questions.Sum(x => x.Points); var studentPoints = compareResults.StudentPoints; // populate the student quiz result object var date = DateTime.Now; studentQuizResult.DateUpdate = date; studentQuizResult.DateOpen = date; studentQuizResult.QuizId = actualQuiz.Id; studentQuizResult.StudentId = student.UserID; studentQuizResult.PointsTotal = totalPoints; studentQuizResult.PointsStudent = studentPoints; studentQuizResult.CorrectQuestions = compareResults.CorrectQuestions; studentQuizResult.DetailResult = DetailResultSerializer.SerializeDetailedQuizResultToXml(compareResults.QuizDetailResults); //store the new student quiz result object _studentQuizResultRepository.CreateItem(studentQuizResult); ProcessStudentRank(student.UserName); var actualStudentQuizResult = _studentQuizResultRepository.GetAllItems().Where( x => x.StudentId == student.UserID && x.QuizId == actualQuiz.Id && x.DateUpdate >= date).FirstOrDefault(); result.SetSuccess(); result.SetData(actualStudentQuizResult); return(result); } catch (Exception e) { result.SetException(); result.AddMessage(e.Message); result.AddExceptionMessage(e.Message); return(result); } }
public void Create() { // Arrange var id = 888; var item = GetFakeQuiz.StudentResult(id); // Act var result = repository.CreateItem(item); // Assert Assert.IsTrue(result); var insertedItem = repository.GetItem(id); Assert.IsTrue(insertedItem.Id == id); var items = repository.GetAllItems(); Assert.IsTrue(items.Count() == ITEMS_COUNT + 1); }