コード例 #1
0
        public void GetOrCreateChapterAsyncShouldReturnChapterIfItExistsForTheCurrentPeriod()
        {
            //Arrange
            var existingPeriod = new Period {
                Id = _random.NextPositive()
            };
            var courseCode      = Guid.NewGuid().ToString();
            var existingChapter = new ChapterBuilder().WithId()
                                  .WithCourse(courseCode)
                                  .WithPeriod(existingPeriod).Build();

            _periodRepositoryMock.Setup(repo => repo.GetCurrentPeriodAsync()).ReturnsAsync(existingPeriod);

            _chapterRepositoryMock.Setup(repo => repo.GetSingleAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(existingChapter);

            //Act
            var result = _service.GetOrCreateChapterAsync(courseCode, existingChapter.Number).Result;

            //Assert
            _periodRepositoryMock.Verify(repo => repo.GetCurrentPeriodAsync(), Times.Once);
            _chapterRepositoryMock.Verify(repo => repo.GetSingleAsync(courseCode, existingChapter.Number, existingPeriod.Id), Times.Once);
            _chapterRepositoryMock.Verify(repo => repo.AddAsync(It.IsAny <Chapter>()), Times.Never);
            Assert.That(result, Is.EqualTo(existingChapter));
        }