示例#1
0
        public Task <NutrientsListViewModel> ListAll()
        {
            var query       = new ListNutrients(ExpressionTemplates.AllExpression <Nutrient>());
            var handlerTask = this.listNutrientsHandler.HandleQueryAsync(query);

            return(handlerTask
                   .ContinueWith(antecedent => new NutrientsListViewModel(antecedent.Result)));
        }
示例#2
0
        public async Task HandleQueryAsync_WithValidArgs_ReturnsListOfNutrients()
        {
            // Arrange
            var allExpression = ExpressionTemplates.AllExpression <Nutrient>();
            var query         = new ListNutrients(allExpression);

            const int nutrientsCount = 3;
            var       nutrients      = GetFakeNutrients(nutrientsCount);

            A.CallTo(() => this.repository.FindAsync(allExpression))
            .Returns(Task.FromResult(nutrients));

            // Act
            var result = await this.sut.HandleQueryAsync(query);

            // Assert
            result.Should().NotBeNull();
            result.Should().NotBeEmpty();

            A.CallTo(() => this.repository.FindAsync(allExpression))
            .MustHaveHappenedOnceExactly();
        }