コード例 #1
0
        public async Task Execute_WithNonExistingId_ReturnsNull()
        {
            //Arrange
            var id = 99;

            _articlesRepositoryMock.Setup(r => r.GetArticleByIdAsync(id)).Returns(Task.FromResult <Article>(null));
            var readMapper      = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile <Helpers.AutoMapperProfiles>()));
            var getArticleQuery = new GetArticleQuery(_articlesRepositoryMock.Object, readMapper);

            //Act
            var result = await getArticleQuery.Execute(id);

            //Assert
            _articlesRepositoryMock.Verify(m => m.GetArticleByIdAsync(It.IsAny <int>()), Times.Once);
            Assert.That(result, Is.Null);
        }
コード例 #2
0
        public async Task Execute_WithExistingId_ReturnsCorrectArticleDto()
        {
            //Arrange
            var id = 1;

            _articlesRepositoryMock.Setup(r => r.GetArticleByIdAsync(id)).Returns(Task.FromResult(_testArticles.First()));
            var readMapper      = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile <Helpers.AutoMapperProfiles>()));
            var getArticleQuery = new GetArticleQuery(_articlesRepositoryMock.Object, readMapper);

            //Act
            var result = await getArticleQuery.Execute(id);

            //Assert
            _articlesRepositoryMock.Verify(m => m.GetArticleByIdAsync(It.IsAny <int>()), Times.Once);
            Assert.That(result, Is.Not.Null);
            Assert.That(result.GetType(), Is.EqualTo(typeof(ArticleDto)));
            Assert.That(result.Name1, Is.EqualTo(_testArticles.First().Name1));
        }