public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndKeyValueEntryForPostingJournalWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModelWithSortedApplyPostingLines()
        {
            ApplyPostingLineCollectionViewModel postingLineCollection = BuildApplyPostingLineCollectionViewModel(
                BuildApplyPostingLineViewModel(),
                BuildApplyPostingLineViewModel(),
                BuildApplyPostingLineViewModel(),
                BuildApplyPostingLineViewModel(),
                BuildApplyPostingLineViewModel(),
                BuildApplyPostingLineViewModel());
            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;

            for (int i = 1; i < applyPostingJournalViewModel.ApplyPostingLines.Count; i++)
            {
                Assert.That(applyPostingJournalViewModel.ApplyPostingLines[i].PostingDate.UtcDateTime.Date, Is.LessThanOrEqualTo(applyPostingJournalViewModel.ApplyPostingLines[i - 1].PostingDate.UtcDateTime.Date));
                if (applyPostingJournalViewModel.ApplyPostingLines[i].PostingDate.UtcDateTime.Date != applyPostingJournalViewModel.ApplyPostingLines[i - 1].PostingDate.UtcDateTime.Date)
                {
                    continue;
                }

                Assert.That(applyPostingJournalViewModel.ApplyPostingLines[i].SortOrder ?? 0, Is.LessThanOrEqualTo(applyPostingJournalViewModel.ApplyPostingLines[i - 1].SortOrder ?? 0));
            }
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValue_ReturnsPartialViewResultWhereViewDataIsNotEqualToNull()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.ViewData, Is.Not.Null);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValue_ReturnsPartialViewResultWhereViewDataContainingKeyForPostingJournalKey()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.ViewData.ContainsKey("PostingJournalKey"), Is.True);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValue_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModel()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.Model, Is.TypeOf <ApplyPostingJournalViewModel>());
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValue_ReturnsPartialViewResult()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result, Is.TypeOf <PartialViewResult>());
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndNoKeyValueEntryForPostingJournalWasReturnedFromQueryBus_AssertPublishAsyncWasNotCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournal()
        {
            Controller sut = CreateSut(false);

            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_WhenPostingJournalKeyHasValueAndPostingJournalHeaderIsWhiteSpace_ReturnsPartialViewResultWhereWithViewDataDoesNotContainKeyForHeader()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.ViewData.ContainsKey("Header"), Is.False);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndPostingJournalHeaderIsNotNullEmptyOrWhiteSpace_ReturnsPartialViewResultWhereWithViewContainingHeaderWithValueNotEqualToNull()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.ViewData["Header"], Is.Not.Null);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyIsEmpty_ReturnsNotNull()
        {
            Controller sut = CreateSut();

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

            Assert.That(result, Is.Not.Null);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyIsWhiteSpace_ReturnsBadRequestResult()
        {
            Controller sut = CreateSut();

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

            Assert.That(result, Is.TypeOf <BadRequestResult>());
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndNoKeyValueEntryForPostingJournalWasReturnedFromQueryBus_AssertQueryAsyncWasCalledTwiceOnQueryBusWithPullKeyValueEntryQueryForPostingJournalKey()
        {
            Controller sut = CreateSut(false);

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

            _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_WhenPostingJournalKeyHasValueAndKeyValueEntryForPostingJournalWasReturnedFromQueryBus_AssertToObjectWasCalledOnKeyValueEntryForPostingJournal()
        {
            Mock <IKeyValueEntry> keyValueEntryForPostingJournalMock = BuildKeyValueEntryForPostingJournalMock();
            Controller            sut = CreateSut(keyValueEntryForPostingJournal: keyValueEntryForPostingJournalMock.Object);

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

            keyValueEntryForPostingJournalMock.Verify(m => m.ToObject <It.IsSubtype <ApplyPostingJournalViewModel> >(), Times.Once);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValue_ReturnsPartialViewResultWhereViewDataContainingPostingJournalKeyWithValueEqualToPostingJournalKeyFromArguments()
        {
            Controller sut = CreateSut(_random.Next(100) > 50);

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

            Assert.That(result.ViewData["PostingJournalKey"], Is.EqualTo(postingJournalKey));
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndNoKeyValueEntryForPostingJournalWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModelWithEmptyApplyPostingLines()
        {
            Controller sut = CreateSut(false);

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

            ApplyPostingJournalViewModel applyPostingJournalViewModel = (ApplyPostingJournalViewModel)result.Model;

            Assert.That(applyPostingJournalViewModel.ApplyPostingLines, Is.Empty);
        }
        public async Task RemovePostingLineFromPostingJournal_WhenPostingJournalKeyHasValueAndNoKeyValueEntryForPostingJournalWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsApplyPostingJournalViewModelWithAccountingNumberEqualToAccountingNumberFromArguments()
        {
            Controller sut = CreateSut(false);

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

            ApplyPostingJournalViewModel applyPostingJournalViewModel = (ApplyPostingJournalViewModel)result.Model;

            Assert.That(applyPostingJournalViewModel.AccountingNumber, Is.EqualTo(accountingNumber));
        }
        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_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_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_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);
        }
        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);
        }