Exemple #1
0
        public Task <IPostingJournalResult> ApplyPostingJournalAsync(IPostingJournal postingJournal, IPostingWarningCalculator postingWarningCalculator)
        {
            NullGuard.NotNull(postingJournal, nameof(postingJournal))
            .NotNull(postingWarningCalculator, nameof(postingWarningCalculator));

            return(ExecuteAsync(async() =>
            {
                IPostingLineCollection postingLineCollection = new PostingLineCollection();
                foreach (IGrouping <int, IPostingLine> group in postingJournal.PostingLineCollection.GroupBy(postingLine => postingLine.Accounting.Number))
                {
                    using PostingLineModelHandler postingLineModelHandler = new PostingLineModelHandler(DbContext, AccountingModelConverter.Create(), _eventPublisher, DateTime.MinValue, DateTime.Today, true, true, applyingPostingLines: true);

                    AccountingIdentificationState accountingIdentificationState = new AccountingIdentificationState(group.Key);

                    IPostingLine[] createdPostingLineCollection = (await postingLineModelHandler.CreateAsync(group.OrderBy(m => m.PostingDate).ThenBy(m => m.SortOrder), accountingIdentificationState, true)).ToArray();

                    IPostingLine[] updatedPostingLineCollection = (await postingLineModelHandler.UpdateAsync(createdPostingLineCollection.OrderBy(m => m.PostingDate.Date).ThenBy(m => m.SortOrder), accountingIdentificationState)).ToArray();
                    foreach (IPostingLine postingLine in updatedPostingLineCollection)
                    {
                        IPostingLine[] affectedPostingCollection = (await postingLineModelHandler.ReadAsync(m => m.AccountingIdentifier == accountingIdentificationState.AccountingIdentifier && (m.PostingDate == postingLine.PostingDate && m.PostingLineIdentifier > postingLine.SortOrder || m.PostingDate > postingLine.PostingDate), prepareReadState: accountingIdentificationState)).ToArray();
                        foreach (IPostingLine affectedPostingLine in affectedPostingCollection.Where(m => updatedPostingLineCollection.Contains(m) == false))
                        {
                            await postingLineModelHandler.UpdateAsync(affectedPostingLine, accountingIdentificationState);
                        }
                    }

                    postingLineCollection.Add(updatedPostingLineCollection);
                }

                return (IPostingJournalResult) new PostingJournalResult(postingLineCollection, postingWarningCalculator);
            },
                                MethodBase.GetCurrentMethod()));
        }
Exemple #2
0
        public void ToDomain_WhenCalled_ReturnsNotNull()
        {
            IApplyPostingJournalCommand sut = CreateSut();

            IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object);

            Assert.That(result, Is.Not.Null);
        }
Exemple #3
0
        public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionNotEmpty()
        {
            IApplyPostingJournalCommand sut = CreateSut();

            IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object);

            Assert.That(result.PostingLineCollection, Is.Not.Empty);
        }
Exemple #4
0
        public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionContainingSameAmountOfPostingLinesAsApplyPostingLineCommands()
        {
            int numberOfApplyPostingLineCommands = _random.Next(10, 25);

            IApplyPostingLineCommand[]  applyPostingLineCommandCollection = _fixture.CreateMany <IApplyPostingLineCommand>(numberOfApplyPostingLineCommands).ToArray();
            IApplyPostingJournalCommand sut = CreateSut(applyPostingLineCommandCollection: applyPostingLineCommandCollection);

            IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object);

            Assert.That(result.PostingLineCollection.Count(), Is.EqualTo(numberOfApplyPostingLineCommands));
        }
        public async Task ExecuteAsync_WhenCalled_AssertApplyPostingJournalAsyncWasCalledOnAccountingRepository()
        {
            CommandHandler sut = CreateSut();

            IPostingJournal             postingJournal             = _fixture.BuildPostingJournalMock().Object;
            IApplyPostingJournalCommand applyPostingJournalCommand = CreateApplyPostingJournalCommand(postingJournal);
            await sut.ExecuteAsync(applyPostingJournalCommand);

            _accountingRepositoryMock.Verify(m => m.ApplyPostingJournalAsync(
                                                 It.Is <IPostingJournal>(value => value == postingJournal),
                                                 It.Is <IPostingWarningCalculator>(value => value == _postingWarningCalculatorMock.Object)),
                                             Times.Once);
        }
Exemple #6
0
        public async Task <IPostingJournalResult> ExecuteAsync(IApplyPostingJournalCommand applyPostingJournalCommand)
        {
            NullGuard.NotNull(applyPostingJournalCommand, nameof(applyPostingJournalCommand));

            applyPostingJournalCommand.Validate(_validator, _accountingRepository, _commonRepository);

            IPostingJournal       postingJournal       = applyPostingJournalCommand.ToDomain(_accountingRepository);
            IPostingJournalResult postingJournalResult = await _accountingRepository.ApplyPostingJournalAsync(postingJournal, _postingWarningCalculator);

            if (postingJournalResult == null)
            {
                return(await new PostingJournalResult(new PostingLineCollection(), _postingWarningCalculator).CalculateAsync(DateTime.Today));
            }

            return(await postingJournalResult.CalculateAsync(DateTime.Today));
        }
Exemple #7
0
        public async Task ApplyPostingJournalAsync_WhenCalled_ReturnsNonEmptyPostingJournalResult()
        {
            IAccountingRepository sut = CreateSut();

            IPostingJournal postingJournal = await BuildPostingJournalAsync(sut);

            IPostingWarningCalculator postingWarningCalculator = await BuildPostingWarningCalculator();

            IPostingJournalResult result = await sut.ApplyPostingJournalAsync(postingJournal, postingWarningCalculator);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.PostingLineCollection, Is.Not.Null);
            Assert.That(result.PostingLineCollection, Is.Not.Empty);
            Assert.That(result.PostingLineCollection.Count(), Is.EqualTo(postingJournal.PostingLineCollection.Count()));
            Assert.That(result.PostingWarningCollection, Is.Not.Null);
            Assert.That(result.PostingWarningCollection, Is.Empty);
        }
Exemple #8
0
        public void ToDomain_WhenCalled_ReturnsPostingJournalWherePostingLineCollectionContainingPostingLinesFromToDomainOnEachApplyPostingLineCommands()
        {
            IPostingLine[] postingLineCollection = new[]
            {
                _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object,
                           _fixture.BuildPostingLineMock().Object
            };
            IApplyPostingJournalCommand sut = CreateSut(applyPostingLineCommandCollection: postingLineCollection.Select(CreateApplyPostingLineCommand).ToArray());

            IPostingJournal result = sut.ToDomain(_accountingRepositoryMock.Object);

            foreach (IPostingLine postingLine in postingLineCollection)
            {
                Assert.That(result.PostingLineCollection.Contains(postingLine), Is.True);
            }
        }
        private Mock <IApplyPostingJournalCommand> CreateApplyPostingJournalCommandMock(IPostingJournal postingJournal = null)
        {
            Mock <IApplyPostingJournalCommand> applyPostingJournalCommandMock = new Mock <IApplyPostingJournalCommand>();

            applyPostingJournalCommandMock.Setup(m => m.Validate(It.IsAny <IValidator>(), It.IsAny <IAccountingRepository>(), It.IsAny <ICommonRepository>()))
            .Returns(_validatorMock.Object);
            applyPostingJournalCommandMock.Setup(m => m.ToDomain(It.IsAny <IAccountingRepository>()))
            .Returns(postingJournal ?? _fixture.BuildPostingJournalMock().Object);
            return(applyPostingJournalCommandMock);
        }
 private IApplyPostingJournalCommand CreateApplyPostingJournalCommand(IPostingJournal postingJournal = null)
 {
     return(CreateApplyPostingJournalCommandMock(postingJournal).Object);
 }