public async Task Should_not_invoke_enricher_for_other_result() { var command = CreateCommand(new MyCommand()); var context = CreateContextForCommand(command); context.Complete(12); await sut.HandleAsync(context); A.CallTo(() => ruleEnricher.EnrichAsync(A <IEnrichedRuleEntity> ._, requestContext)) .MustNotHaveHappened(); }
public async Task <IReadOnlyList <IEnrichedRuleEntity> > QueryAsync(Context context) { var rules = await rulesIndex.GetRulesAsync(context.App.Id); var enriched = await ruleEnricher.EnrichAsync(rules, context); return(enriched); }
public override async Task HandleAsync(CommandContext context, NextDelegate next) { await base.HandleAsync(context, next); if (context.PlainResult is IRuleEntity rule && NotEnriched(context)) { var enriched = await ruleEnricher.EnrichAsync(rule, contextProvider.Context); context.Complete(enriched); } }
protected override async Task <object> EnrichResultAsync(CommandContext context, CommandResult result) { var payload = await base.EnrichResultAsync(context, result); if (payload is IRuleEntity rule && payload is not IEnrichedRuleEntity) { payload = await ruleEnricher.EnrichAsync(rule, contextProvider.Context); } return(payload); }
public async Task Should_get_rules_from_index_and_enrich() { var original = new List <IRuleEntity> { new RuleEntity() }; var enriched = new List <IEnrichedRuleEntity> { new RuleEntity() }; A.CallTo(() => rulesIndex.GetRulesAsync(appId.Id)) .Returns(original); A.CallTo(() => ruleEnricher.EnrichAsync(original, requestContext)) .Returns(enriched); var result = await sut.QueryAsync(requestContext); Assert.Same(enriched, result); }
public async Task <IReadOnlyList <IEnrichedRuleEntity> > QueryAsync(Context context, CancellationToken ct = default) { var rules = await rulesIndex.GetRulesAsync(context.App.Id, ct); if (rules.Count > 0) { var enriched = await ruleEnricher.EnrichAsync(rules, context, ct); return(enriched); } return(EmptyResults); }
public async Task <IReadOnlyList <IEnrichedRuleEntity> > QueryAsync(Context context) { var rules = await rulesIndex.GetRulesAsync(context.App.Id); rules.RemoveAll(x => x.IsDeleted); if (rules.Count > 0) { var enriched = await ruleEnricher.EnrichAsync(rules, context); return(enriched); } return(EmptyResults); }