Beispiel #1
0
        public void ExecutesAggregator()
        {
            var testee = new AggregatorStrategy <TestQuestion, string, int>();

            var context        = new Context();
            var aggregatorMock = new Mock <IAggregator <string, string, int> >();

            var expressionProviderMock = new Mock <IExpressionProvider <TestQuestion, string, int, string> >();
            var question   = new TestQuestion();
            var expression = new TestExpression <string>();

            expressionProviderMock.Setup(provider => provider.GetExpressions(question)).Returns(new[] { expression });

            var definition = new TestableDefinition <string>
            {
                Aggregator          = aggregatorMock.Object,
                ExpressionProviders = new[] { expressionProviderMock.Object }
            };

            const int Parameter = 7;

            testee.Execute(question, Parameter, definition, context);

            AssertThatAggregatorIsCalledWithExpressionsFromDefinition(aggregatorMock, new[] { expression }, Parameter);
        }
Beispiel #2
0
        public void ExecutesAggregator_WhenStrategyWithMappingIsUsed()
        {
            const string Answer = "42";

            var testee = new AggregatorStrategy <TestQuestion, string, int, int>();

            var context    = new Context();
            var aggregator = A.Fake <IAggregator <int, string, int> >();

            var expressionProvider = A.Fake <IExpressionProvider <TestQuestion, string, int, int> >();
            var question           = new TestQuestion();
            var expression         = new TestExpression <int>();

            A.CallTo(() => expressionProvider.GetExpressions(question)).Returns(new[] { expression });
            var definition = new TestableDefinition <int>
            {
                Aggregator          = aggregator,
                ExpressionProviders = new[] { expressionProvider }
            };

            const int Parameter = 7;

            A.CallTo(() => aggregator.Aggregate(
                         A <IEnumerable <IExpression <int, int> > > .That.Matches(_ => _.Contains(expression) && _.Count() == 1),
                         Parameter,
                         A <Context> ._)).Returns(Answer);

            string result = testee.Execute(question, Parameter, definition, context);

            result.Should().Be(Answer);
        }