Пример #1
0
        public void SortTransactionsByDate_test()
        {
            var processor = new TranasctionsProcessor(new FakeCurrenciesRepo());

            var result = processor.SortTransactions(transactions, TransactionSortBy.Date).Result;

            result.First().Currency.ShouldBe("usd");
            result.First().Value.ShouldBe(123.06m);

            result.Last().Currency.ShouldBe("gbp");
            result.Last().Value.ShouldBe(123.06m);
        }
Пример #2
0
        public async Task <CustomResponse <IEnumerable <TransactionLine> > > Post([FromBody] IEnumerable <TransactionLine> transactions, [FromQuery(Name = "sortby")] BUSINESS_MODEL.TransactionSortBy sortby)
        {
            var result = new CustomResponse <IEnumerable <TransactionLine> >();

            try
            {
                var processor           = new TranasctionsProcessor(this._repo);
                var businessTranactions = transactions.ToBusinessModel().ToList();

                if (await processor.ValidateTransactions(businessTranactions))
                {
                    var sortedTransactions = await processor.SortTransactions(businessTranactions, sortby);

                    result.Data = sortedTransactions.ToWebsiteModel();
                }
                else
                {
                    result.Errors = new List <string> {
                        "Invalid transaction found. Negative transaction value is not allowed"
                    };
                }
            }
            catch (CurrencyNotFountException ex)
            {
                result.Errors = new List <string> {
                    ex.Message
                };
            }
            catch
            {
                // TODO LOG the incident to the propriet log storage for future analysis
                result.Errors = new List <string> {
                    "Ups there was an error in our system. Please try again or later."
                };
            }

            return(await Task.Run(() => {
                return result;
            }));
        }