Example #1
0
        public async Task <IActionResult> GetAllAppointments()
        {
            var appointments = await getAllQueryHandler.ExecuteQueryAsync(new GetAllAppointmentsQuery(), new CancellationToken());

            if (appointments.Any())
            {
                return(Ok(appointments));
            }

            return(NotFound());
        }
Example #2
0
        public async Task  ShouldGetDepartureStation()
        {
            //Arrange
            var journeys = new JourneysBuilder().BuildJourneys();
            var selectJourneysCommand = new SelectJourneysCommand(BookingId.New, journeys);
            await CommandBus.PublishAsync(selectJourneysCommand, CancellationToken.None);

            //Act
            var query    = new GetDepartureStationsQuery(DateTime.Today, DateTime.Today.AddDays(3));
            var stations = await _queryHandler.ExecuteQueryAsync(query, CancellationToken.None);

            //Assert
            stations.Should().NotBeEmpty();
        }
Example #3
0
        public Task <TResult> ExecuteQueryAsync <TQuery, TResult>(TQuery query) where TQuery : IQuery where TResult : IQueryResult
        {
            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.ExecuteQueryAsync(query));
        }