예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }