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))); }
public Task <IEnumerable <Nutrient> > HandleQueryAsync(ListNutrients query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } return(this.repository.FindAsync(query.Filter)); }
public static async Task Main(string[] args) { var repository = new NutrientRepository(); var commandHandler = new CreateNutrientHandler(repository); var command = new CreateNutrient("Vitamin D"); await commandHandler.HandleCommandAsync(command); var queryHandler = new ListNutrientsHandler(repository); var query = new ListNutrients(o => o.Title == "Vitamin D"); var result = await queryHandler.HandleQueryAsync(query); System.Console.ReadKey(); }
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(); }