Exemple #1
0
        public void ToAssignmentResultDtoShouldConvertTestResults()
        {
            //Arrange
            var converter        = new AssignmentWitResultsConverter();
            var assigment        = new ExerciseBuilder().Build();
            var testsWithResults = new List <TestWithLastResultOfUser>
            {
                new TestWithLastResultOfUserBuilder().WithAssignmentId(assigment.Id).Build(),
                new TestWithLastResultOfUserBuilder().WithAssignmentId(assigment.Id).Build(),
            };
            var assignmentWithResults = new AssignmentWithLastResultsOfUser
            {
                Assignment = assigment,
                TestsWithLastResultOfUser = testsWithResults
            };

            //Act
            var result = converter.ToAssignmentResultDto(assignmentWithResults);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.TestResults.Count, Is.EqualTo(testsWithResults.Count));

            foreach (var testWithUserResults in testsWithResults)
            {
                Assert.That(result.TestResults, Has.Some.Matches((TestResultDto dto) => dto.TestName == testWithUserResults.Test.TestName));
            }
        }
        public void GetResultsForUserAsyncShouldRetrieveAssignmentsWithLastTestsResultsOfUserAndConvertThemToAssignmentResultDtos()
        {
            //Arrange
            var chapterId              = _random.NextPositive();
            var userId                 = _random.NextPositive();
            var assignmentWithResults  = new AssignmentWithLastResultsOfUser();
            var assignmentsWithResults = new List <AssignmentWithLastResultsOfUser> {
                assignmentWithResults
            };

            _testResultRepositoryMock.Setup(repo => repo.GetLastTestResultsOfChapterAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime?>()))
            .ReturnsAsync(assignmentsWithResults);

            var assignmentResultDto = new AssignmentResultDto();

            _testResultConverterMock
            .Setup(converter => converter.ToAssignmentResultDto(It.IsAny <AssignmentWithLastResultsOfUser>()))
            .Returns(assignmentResultDto);

            //Act
            var results = _service.GetResultsForUserAsync(chapterId, userId, null).Result;

            //Assert
            Assert.That(results, Has.Exactly(1).EqualTo(assignmentResultDto));
            _testResultRepositoryMock.Verify(repo => repo.GetLastTestResultsOfChapterAsync(chapterId, userId, null), Times.Once);
            _testResultConverterMock.Verify(converter => converter.ToAssignmentResultDto(assignmentWithResults), Times.Once);
        }
        public AssignmentResultDto ToAssignmentResultDto(AssignmentWithLastResultsOfUser assignmentWithLastResultsOfUser)
        {
            var resultDto = new AssignmentResultDto
            {
                AssignmentId = assignmentWithLastResultsOfUser.Assignment.Id,
                TestResults  = new List <TestResultDto>()
            };

            foreach (var testWithResults in assignmentWithLastResultsOfUser.TestsWithLastResultOfUser)
            {
                var testResultDto = new TestResultDto
                {
                    TestId   = testWithResults.Test.Id,
                    TestName = testWithResults.Test.TestName,
                    Passed   = testWithResults.TestResult.Passed,
                    Message  = testWithResults.TestResult.Message
                };
                resultDto.TestResults.Add(testResultDto);
            }

            return(resultDto);
        }