public async Task Handler_ReturnsSalesDTOCollection()
        {
            // Arrange
            var startDate = DateTime.Parse("2018-01-01");
            var endDate   = DateTime.Parse("2021-01-01");
            var query     = new GetSalesByDateQuery {
                StartDate = startDate, EndDate = endDate
            };

            // Act
            var handler = new GetSalesByDateQuery.GetSalesByDateQueryHandler(Context, Mapper);

            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            (result as List <SaleDTO>).Count.ShouldBeGreaterThanOrEqualTo(4);
            result.ShouldBeOfType <List <SaleDTO> >();
            result.ShouldNotBeNull();
        }
Esempio n. 2
0
        /// <inheritdoc/>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public async Task <SaleStatisticDTO> GetSalesStatistic(TimeUnit timeUnit, DateTime startDate, DateTime endDate)
        {
            if (endDate <= startDate)
            {
                throw new ArgumentOutOfRangeException(nameof(endDate));
            }

            var salesQuery = new GetSalesByDateQuery {
                StartDate = startDate, EndDate = endDate
            };
            var sales = await _mediator.Send(salesQuery);

            var saleStatistic = timeUnit switch
            {
                TimeUnit.Quarter => CalculateQuarterStatistic(sales, startDate, endDate),
                TimeUnit.Month => CalculateMonthStatistic(sales, startDate, endDate),
                TimeUnit.Week => CalculateWeekStatistic(sales, startDate, endDate),
                TimeUnit.Day => CalculateDayStatistic(sales, startDate, endDate),
                _ => null,
            };

            return(saleStatistic);
        }