コード例 #1
0
        public async Task <GetResult <Period> > GetLastPeriod()
        {
            if (_periods.Count == 0)
            {
                return(await Task.FromResult(
                           GetResult <Period> .CreateFailure("No periods found")));
            }

            Period period = _periods
                            .OrderBy(p => p.Start)
                            .LastOrDefault();

            return(await Task.FromResult(
                       GetResult <Period> .CreateSuccess(period)));
        }
コード例 #2
0
        public async Task <GetResult <IEnumerable <TransactionDto> > > GetTransactions()
        {
            _logger.LogVerbose("Received request for transactions.");

            GetResult <IEnumerable <Transaction> > getTransactionsResult = await _accountingDataAccess.GetTransactions();

            if (!getTransactionsResult.IsSuccess)
            {
                return(GetResult <IEnumerable <TransactionDto> > .CreateFailure(getTransactionsResult.FailureMessage));
            }

            IEnumerable <TransactionDto> transactions =
                _mapper.Map <IEnumerable <Transaction>, IEnumerable <TransactionDto> >(getTransactionsResult.Result);

            return(GetResult <IEnumerable <TransactionDto> > .CreateSuccess(transactions));
        }
コード例 #3
0
        public async Task <GetResult <Period> > GetPeriodForDate(DateTime date)
        {
            Period period = _periods
                            .FirstOrDefault(p =>
                                            p.Start <= date &&
                                            p.End >= date);

            if (period == null)
            {
                return(await Task.FromResult(
                           GetResult <Period> .CreateFailure($"No period found for date: {date:yyyy-MM-dd}")));
            }

            return(await Task.FromResult(
                       GetResult <Period> .CreateSuccess(period)));
        }
コード例 #4
0
        public async Task Given_NoExistingPeriods_When_Added_Then_ResultIsSuccess()
        {
            // Arrange.
            AccountingManager testObject = AccountingManagerFactory.Create(out IAccountingDataAccess accountingDataAccess);

            accountingDataAccess
            .GetLastPeriod()
            .Returns(GetResult <Period> .CreateFailure("No periods found"));

            accountingDataAccess
            .AddPeriod(Arg.Any <Period>())
            .Returns(ActionResult.CreateSuccess());

            var period = new PeriodDto(DateTime.Now, DateTime.Now);

            // Act.
            ActionResult result = await testObject.AddPeriod(period);

            // Assert.
            Assert.IsTrue(result.IsSuccess);
        }