public async Task <GetTransactionsDownloadResponse> Handle(GetTransactionsDownloadQuery message)
        {
            var endDate = message.EndDate.ToDate();
            var endDateBeginningOfNextMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1);
            var transactions = await _transactionRepository.GetAllTransactionDetailsForAccountByDate(message.AccountId, message.StartDate, endDateBeginningOfNextMonth);

            if (!transactions.Any())
            {
                throw new ValidationException("There are no transactions in the date range");
            }

            var accountResponse = await _accountApiClient.GetAccount(message.AccountId);

            var apprenticeshipEmployerTypeEnum = (ApprenticeshipEmployerType)Enum.Parse(typeof(ApprenticeshipEmployerType), accountResponse.ApprenticeshipEmployerType, true);

            foreach (var transaction in transactions)
            {
                GenerateTransactionDescription(transaction);
            }

            var fileFormatter = _transactionsFormatterFactory.GetTransactionsFormatterByType(
                message.DownloadFormat.Value,
                apprenticeshipEmployerTypeEnum);

            return(new GetTransactionsDownloadResponse
            {
                FileData = fileFormatter.GetFileData(transactions),
                FileExtension = fileFormatter.FileExtension,
                MimeType = fileFormatter.MimeType
            });
        }
        public async Task <GetTransactionsDownloadResponse> Handle(GetTransactionsDownloadQuery message)
        {
            var endDate = message.EndDate.ToDate();
            var endDateBeginningOfNextMonth = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(1);
            var transactions = await _transactionRepository.GetAllTransactionDetailsForAccountByDate(message.AccountId.Value, message.StartDate, endDateBeginningOfNextMonth);

            if (!transactions.Any())
            {
                throw new ValidationException("There are no transactions in the date range");
            }

            var fileFormatter = _transactionsFormatterFactory.GetTransactionsFormatterByType(message.DownloadFormat.Value);

            return(new GetTransactionsDownloadResponse
            {
                FileData = fileFormatter.GetFileData(transactions),
                FileExtension = fileFormatter.FileExtension,
                MimeType = fileFormatter.MimeType
            });
        }
コード例 #3
0
        public void ThenIShouldGetLevyCsvFormatter()
        {
            var formatter = _paymentFormatterFactory.GetTransactionsFormatterByType(DownloadFormatType.CSV, ApprenticeshipEmployerType.Levy);

            Assert.AreEqual(_levyCsvFormatter.Object, formatter);
        }