Пример #1
0
        public void ShouldReturnZeroWhenEventStoreIsEmpty()
        {
            // Clear the event list.
            eventStore.Events = Enumerable.Empty <IEvent>();

            var query = new CalculationResultQuery();

            var result = queryHandler.ExecuteQuery(query);

            Assert.AreEqual(0, result);
        }
Пример #2
0
        public TResult ExecuteQuery<TQuery, TResult>(TQuery query)
            where TResult : IQueryResult
            where TQuery : IQuery
        {
            IQueryHandler<TQuery, TResult> handler = null;
            var resolvedHandlers = _container.GetAllInstances<IQueryHandler<TQuery, TResult>>();

            var queryHandlers = resolvedHandlers as IQueryHandler<TQuery, TResult>[] ?? resolvedHandlers.ToArray();
            if (!queryHandlers.Any())
            {
                throw new Exception($"Unable to resolve a query handler for type {query.GetType()}.");
            }

            if (queryHandlers.Count() > 1)
            {
                throw new Exception($"Ambiguous call to handler for type {query.GetType()}.  There are more than one handler registered to the same type.");
            }

            handler = queryHandlers.First();
            return handler.ExecuteQuery(query);
        }