public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueContainsOnePostingLinesMatchingPostingLineIdentifier_AssertPublishAsyncWasCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournal()
        {
            Guid postingLineIdentifier = Guid.NewGuid();
            ApplyPostingLineViewModel           applyPostingLineViewModel           = BuildApplyPostingLineViewModel(postingLineIdentifier);
            ApplyPostingLineCollectionViewModel applyPostingLineCollectionViewModel = BuildApplyPostingLineCollectionViewModel(applyPostingLineViewModel);
            ApplyPostingJournalViewModel        applyPostingJournalViewModel        = BuildApplyPostingJournalViewModel(applyPostingLineCollectionViewModel: applyPostingLineCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournal = BuildKeyValueEntryForPostingJournal(applyPostingJournalViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            string postingJournalKey = _fixture.Create <string>();
            await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), postingJournalKey, postingLineIdentifier);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IDeleteKeyValueEntryCommand>(command => command != null && string.CompareOrdinal(command.Key, postingJournalKey) == 0)), Times.Once());
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueContainsOnePostingLinesMatchingPostingLineIdentifier_AssertQueryAsyncWasCalledTwiceOnQueryBusWithPullKeyValueEntryQueryForPostingJournalKey()
        {
            Guid postingLineIdentifier = Guid.NewGuid();
            ApplyPostingLineViewModel           applyPostingLineViewModel           = BuildApplyPostingLineViewModel(postingLineIdentifier);
            ApplyPostingLineCollectionViewModel applyPostingLineCollectionViewModel = BuildApplyPostingLineCollectionViewModel(applyPostingLineViewModel);
            ApplyPostingJournalViewModel        applyPostingJournalViewModel        = BuildApplyPostingJournalViewModel(applyPostingLineCollectionViewModel: applyPostingLineCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournal = BuildKeyValueEntryForPostingJournal(applyPostingJournalViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            string postingJournalKey = _fixture.Create <string>();
            await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), postingJournalKey, postingLineIdentifier);

            _queryBusMock.Verify(m => m.QueryAsync <IPullKeyValueEntryQuery, IKeyValueEntry>(It.Is <IPullKeyValueEntryQuery>(query => query != null && string.CompareOrdinal(query.Key, postingJournalKey) == 0)), Times.Exactly(2));
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueEntryDoesNotContainPostingLineForPostingLineIdentifier_AssertPublishAsyncWasNotCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournal()
        {
            ApplyPostingLineViewModel           applyPostingLineViewModel1          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           applyPostingLineViewModel2          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           applyPostingLineViewModel3          = BuildApplyPostingLineViewModel();
            ApplyPostingLineCollectionViewModel applyPostingLineCollectionViewModel = BuildApplyPostingLineCollectionViewModel(applyPostingLineViewModel1, applyPostingLineViewModel2, applyPostingLineViewModel3);
            ApplyPostingJournalViewModel        applyPostingJournalViewModel        = BuildApplyPostingJournalViewModel(applyPostingLineCollectionViewModel: applyPostingLineCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournal = BuildKeyValueEntryForPostingJournal(applyPostingJournalViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), _fixture.Create <string>(), Guid.NewGuid());

            _commandBusMock.Verify(m => m.PublishAsync(It.IsAny <IDeleteKeyValueEntryCommand>()), Times.Never());
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueContainsOnePostingLinesMatchingPostingLineIdentifier_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModelWithEmptyApplyPostingLines()
        {
            Guid postingLineIdentifier = Guid.NewGuid();
            ApplyPostingLineViewModel           postingLine           = BuildApplyPostingLineViewModel(postingLineIdentifier);
            ApplyPostingLineCollectionViewModel postingLineCollection = BuildApplyPostingLineCollectionViewModel(postingLine);
            ApplyPostingJournalViewModel        postingJournal        = BuildApplyPostingJournalViewModel(applyPostingLineCollectionViewModel: postingLineCollection);
            IKeyValueEntry keyValueEntryForPostingJournal             = BuildKeyValueEntryForPostingJournal(postingJournal);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            PartialViewResult result = (PartialViewResult)await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), _fixture.Create <string>(), postingLineIdentifier);

            ApplyPostingJournalViewModel applyPostingJournalViewModel = (ApplyPostingJournalViewModel)result.Model;

            Assert.That(applyPostingJournalViewModel.ApplyPostingLines, Is.Empty);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueEntryDoesNotContainPostingLineForPostingLineIdentifier_AssertPublishAsyncWasCalledOnCommandBusWithPushKeyValueEntryCommandForPostingJournal()
        {
            int accountingNumber = _fixture.Create <int>();
            ApplyPostingLineViewModel           applyPostingLineViewModel1          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           applyPostingLineViewModel2          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           applyPostingLineViewModel3          = BuildApplyPostingLineViewModel();
            ApplyPostingLineCollectionViewModel applyPostingLineCollectionViewModel = BuildApplyPostingLineCollectionViewModel(applyPostingLineViewModel1, applyPostingLineViewModel2, applyPostingLineViewModel3);
            ApplyPostingJournalViewModel        applyPostingJournalViewModel        = BuildApplyPostingJournalViewModel(accountingNumber, applyPostingLineCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournal = BuildKeyValueEntryForPostingJournal(applyPostingJournalViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            string postingJournalKey = _fixture.Create <string>();
            await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), postingJournalKey, Guid.NewGuid());

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IPushKeyValueEntryCommand>(command => command != null && string.CompareOrdinal(command.Key, postingJournalKey) == 0 && command.Value != null && command.Value.GetType() == typeof(ApplyPostingJournalViewModel) && ((ApplyPostingJournalViewModel)command.Value).AccountingNumber == accountingNumber && ((ApplyPostingJournalViewModel)command.Value).ApplyPostingLines != null && ((ApplyPostingJournalViewModel)command.Value).ApplyPostingLines.Count == 3 && ((ApplyPostingJournalViewModel)command.Value).ApplyPostingLines.Contains(applyPostingLineViewModel1) && ((ApplyPostingJournalViewModel)command.Value).ApplyPostingLines.Contains(applyPostingLineViewModel2) && ((ApplyPostingJournalViewModel)command.Value).ApplyPostingLines.Contains(applyPostingLineViewModel3))), Times.Once);
        }
Esempio n. 6
0
        private string BuildPostingLineJson(Guid?identifier = null, bool hasDetails = true)
        {
            ApplyPostingLineViewModel postingLine = _fixture.Build <ApplyPostingLineViewModel>()
                                                    .With(m => m.Identifier, identifier)
                                                    .With(m => m.PostingDate, DateTimeOffset.Now.AddDays(_random.Next(0, 7) * -1).Date)
                                                    .With(m => m.Reference, _random.Next(100) > 50 ? _fixture.Create <string>().Substring(0, 16) : null)
                                                    .With(m => m.AccountNumber, _fixture.Create <string>().Substring(0, 16).ToUpper())
                                                    .With(m => m.Details, hasDetails ? _fixture.Create <string>() : null)
                                                    .With(m => m.BudgetAccountNumber, _random.Next(100) > 50 ? _fixture.Create <string>().Substring(0, 16).ToUpper() : null)
                                                    .With(m => m.Debit, _random.Next(100) > 50 ? Math.Abs(_fixture.Create <decimal>()) : null)
                                                    .With(m => m.Credit, _random.Next(100) > 50 ? Math.Abs(_fixture.Create <decimal>()) : null)
                                                    .With(m => m.ContactAccountNumber, _random.Next(100) > 50 ? _fixture.Create <string>().Substring(0, 16).ToUpper() : null)
                                                    .With(m => m.SortOrder, (int?)null)
                                                    .Create();

            return(JsonSerializer.Serialize(postingLine));
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalFromKeyValueEntryDoesNotContainPostingLineForPostingLineIdentifier_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModelWithApplyPostingLinesFromReturnedPostingJournal()
        {
            ApplyPostingLineViewModel           postingLine1          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           postingLine2          = BuildApplyPostingLineViewModel();
            ApplyPostingLineViewModel           postingLine3          = BuildApplyPostingLineViewModel();
            ApplyPostingLineCollectionViewModel postingLineCollection = BuildApplyPostingLineCollectionViewModel(postingLine1, postingLine2, postingLine3);
            ApplyPostingJournalViewModel        postingJournal        = BuildApplyPostingJournalViewModel(applyPostingLineCollectionViewModel: postingLineCollection);
            IKeyValueEntry keyValueEntryForPostingJournal             = BuildKeyValueEntryForPostingJournal(postingJournal);
            Controller     sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournal);

            PartialViewResult result = (PartialViewResult)await sut.RemovePostingLineFromPostingJournal(_fixture.Create <int>(), _fixture.Create <string>(), Guid.NewGuid());

            ApplyPostingJournalViewModel applyPostingJournalViewModel = (ApplyPostingJournalViewModel)result.Model;

            Assert.That(applyPostingJournalViewModel.ApplyPostingLines, Is.Not.Empty);
            Assert.That(applyPostingJournalViewModel.ApplyPostingLines.Contains(postingLine1), Is.True);
            Assert.That(applyPostingJournalViewModel.ApplyPostingLines.Contains(postingLine2), Is.True);
            Assert.That(applyPostingJournalViewModel.ApplyPostingLines.Contains(postingLine3), Is.True);
        }