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); }
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)); }