Beispiel #1
0
        public GenericCalcUnitTests()
        {
            _input1 = new PassThroughUnit <int>();
            _input2 = new PassThroughUnit <int>();
            _input3 = new PassThroughUnit <int>();

            _sut = new GenericCalcUnit <int, int>(args => args.Values.Sum(),
                                                  _input1, _input2, _input3);
        }
Beispiel #2
0
        public JoinTests()
        {
            _inputLeft  = new PassThroughUnit <TestEntityA>();
            _inputRight = new PassThroughUnit <TestEntityB>();

            _sut = new Join <TestEntityA, TestEntityB>(
                _inputLeft, _inputRight,
                value => value.KeyA, value => value.KeyB,
                value => value.KeyA, value => value.KeyB);
        }
Beispiel #3
0
        public MultiJoinTests()
        {
            _inputA = new PassThroughUnit <TestEntityA>();
            _inputB = new PassThroughUnit <TestEntityB>();
            _inputC = new PassThroughUnit <TestEntityC>();

            _sut = new MultiJoin(
                new JoinDefinitionAdapter <TestEntityA>(_inputA, "A", e => e.KeyA, _ => Guid.NewGuid()),
                new JoinDefinitionAdapter <TestEntityB>(_inputB, "B", e => e.KeyB, _ => Guid.NewGuid()),
                new JoinDefinitionAdapter <TestEntityC>(_inputC, "C", e => e.KeyC, _ => Guid.NewGuid()));

            var resultInspector = new CallbackSubcriber <IDictionary <string, IList <object> > >(r => _result = r);

            _sut.Subscribe(resultInspector);
        }
Beispiel #4
0
        public Engine(IQaApiPublisher qaApiPublisher)
        {
            _questions = new PassThroughUnit <Question>();
            _answers   = new PassThroughUnit <Answer>();
            _users     = new PassThroughUnit <User>();

            _questions.Subscribe(new CallbackSubcriber <Question>(q => _maxQuestionId = Math.Max(_maxQuestionId, q.Id)));
            _answers.Subscribe(new CallbackSubcriber <Answer>(a => _maxAnswerId       = Math.Max(_maxAnswerId, a.Id)));
            _users.Subscribe(new CallbackSubcriber <User>(u => _maxUserId             = Math.Max(_maxUserId, u.Id)));

            var qaJoin = new Join <Question, Answer>(
                _questions, _answers,
                q => q.Id, a => a.QuestionId,
                q => q.Id, a => a.Id);

            new QaApiContentMaker(qaJoin).Subscribe(new CallbackSubcriber <QaApiContent>(qaApiPublisher.Publish));

            var userStatistics = new MultiJoin(
                new JoinDefinitionAdapter <User>(_users, "User", u => u.Id, u => u.Id),
                new JoinDefinitionAdapter <Question>(_questions, "Questions", q => q.UserId, q => q.Id),
                new JoinDefinitionAdapter <Answer>(_answers, "Answers", a => a.UserId, a => a.Id));

            var statMapper = new Mapper <IDictionary <string, IList <object> >, UserStatistic>(userStatistics, data =>
            {
                if (!data.ContainsKey("User") || data["User"].Count != 1)
                {
                    return(null);
                }

                return(new UserStatistic
                {
                    User = (User)data["User"].Single(),
                    QuestionsCount = data.ContainsKey("Questions") ? data["Questions"].Count : 0,
                    AnswerCount = data.ContainsKey("Answers") ? data["Answers"].Count : 0
                });
            });

            statMapper.Subscribe(new CallbackSubcriber <UserStatistic>(s => s?.ToString()));
        }