Esempio n. 1
0
        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);
        }