public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsOnePostingWarningMatchingPostingWarningIdentifier_ReturnsPartialViewResultWhereModelIsPostingWarningCollectionViewModelWithSortedPostingWarnings()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

            Guid postingWarningIdentifier = postingWarningIdentifierCollection[_random.Next(0, postingWarningIdentifierCollection.Length - 1)];
            PartialViewResult result      = (PartialViewResult)await sut.RemovePostingWarningFromPostingJournalResult(_fixture.Create <int>(), _fixture.Create <string>(), postingWarningIdentifier);

            PostingWarningCollectionViewModel resultViewModel = (PostingWarningCollectionViewModel)result.Model;

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

                Assert.That(resultViewModel[i].PostingLine.SortOrder, Is.LessThanOrEqualTo(resultViewModel[i - 1].PostingLine.SortOrder));
                if (resultViewModel[i].PostingLine.SortOrder != resultViewModel[i - 1].PostingLine.SortOrder)
                {
                    continue;
                }

                Assert.That((int)resultViewModel[i].Reason, Is.LessThanOrEqualTo((int)resultViewModel[i - 1].Reason));
            }
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryDoesNotContainPostingWarningForPostingWarningIdentifier_AssertPublishAsyncWasNotCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournalResult()
        {
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(BuildPostingWarningIdentifierCollection());
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

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

            _commandBusMock.Verify(m => m.PublishAsync(It.IsAny <IDeleteKeyValueEntryCommand>()), Times.Never());
        }
        public async Task LoadAccounting_WhenAccountingWasReturnedFromQueryBusAndKeyValueEntryForPostingJournalResultWasReturnedFromQueryBus_ReturnsPartialViewResultWhereModelIsAccountingViewModelWithPostingJournalResultEqualToPostingJournalResultFromQueryBus()
        {
            ApplyPostingJournalResultViewModel postingJournalResult = _fixture.Create <ApplyPostingJournalResultViewModel>();
            IKeyValueEntry keyValueEntryForPostingJournalResultKey  = _fixture.BuildKeyValueEntryMock(toObject: postingJournalResult).Object;
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResultKey: keyValueEntryForPostingJournalResultKey);

            PartialViewResult result = (PartialViewResult)await sut.LoadAccounting(_fixture.Create <int>());

            AccountingViewModel accountingViewModel = (AccountingViewModel)result.Model;

            Assert.That(accountingViewModel.PostingJournalResult, Is.EqualTo(postingJournalResult));
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryDoesNotContainPostingWarningForPostingWarningIdentifier_AssertQueryAsyncWasCalledOnceOnQueryBusWithPullKeyValueEntryQueryForPostingJournalResultKey()
        {
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(BuildPostingWarningIdentifierCollection());
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

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

            _queryBusMock.Verify(m => m.QueryAsync <IPullKeyValueEntryQuery, IKeyValueEntry>(It.Is <IPullKeyValueEntryQuery>(query => query != null && string.CompareOrdinal(query.Key, postingJournalResultKey) == 0)), Times.Once);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsOnePostingWarningMatchingPostingWarningIdentifier_AssertPublishAsyncWasCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournalResult()
        {
            Guid postingWarningIdentifier = Guid.NewGuid();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifier);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

            string postingJournalResultKey = _fixture.Create <string>();
            await sut.RemovePostingWarningFromPostingJournalResult(_fixture.Create <int>(), postingJournalResultKey, postingWarningIdentifier);

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IDeleteKeyValueEntryCommand>(command => command != null && string.CompareOrdinal(command.Key, postingJournalResultKey) == 0)), Times.Once);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsMultiplePostingWarningsWhereOneMatchesPostingWarningIdentifier_AssertPublishAsyncWasNotCalledOnCommandBusWithDeleteKeyValueEntryCommandForPostingJournalResult()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

            Guid postingWarningIdentifier = postingWarningIdentifierCollection[_random.Next(0, postingWarningIdentifierCollection.Length - 1)];
            await sut.RemovePostingWarningFromPostingJournalResult(_fixture.Create <int>(), _fixture.Create <string>(), postingWarningIdentifier);

            _commandBusMock.Verify(m => m.PublishAsync(It.IsAny <IDeleteKeyValueEntryCommand>()), Times.Never());
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryDoesNotContainPostingWarningForPostingWarningIdentifier_AssertPublishAsyncWasCalledOnCommandBusWithPushKeyValueEntryCommandForPostingJournalResult()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

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

            _commandBusMock.Verify(m => m.PublishAsync(It.Is <IPushKeyValueEntryCommand>(command => command != null && string.CompareOrdinal(command.Key, postingJournalResultKey) == 0 && command.Value != null && command.Value.GetType() == typeof(ApplyPostingJournalResultViewModel) && ((ApplyPostingJournalResultViewModel)command.Value).PostingLines != null && ((ApplyPostingJournalResultViewModel)command.Value).PostingLines.Count == 0 && ((ApplyPostingJournalResultViewModel)command.Value).PostingWarnings != null && ((ApplyPostingJournalResultViewModel)command.Value).PostingWarnings.Count == postingWarningIdentifierCollection.Length && ((ApplyPostingJournalResultViewModel)command.Value).PostingWarnings.All(postingWarningViewModel => postingWarningIdentifierCollection.Any(postingWarningIdentifier => postingWarningViewModel.Identifier == postingWarningIdentifier)))), Times.Once);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsOnePostingWarningMatchingPostingWarningIdentifier_ReturnsPartialViewResultWhereModelIsPostingWarningCollectionViewModelWithEmptyPostingWarnings()
        {
            Guid postingWarningIdentifier = Guid.NewGuid();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifier);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

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

            PostingWarningCollectionViewModel resultViewModel = (PostingWarningCollectionViewModel)result.Model;

            Assert.That(resultViewModel, Is.Empty);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryDoesNotContainPostingWarningForPostingWarningIdentifier_ReturnsPartialViewResultWhereModelIsPostingWarningCollectionViewModelWithPostingWarningsFromReturnedPostingJournalResult()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

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

            PostingWarningCollectionViewModel resultViewModel = (PostingWarningCollectionViewModel)result.Model;

            Assert.That(resultViewModel.All(postingWarningViewModel => postingWarningIdentifierCollection.Any(postingWarningIdentifier => postingWarningViewModel.Identifier == postingWarningIdentifier)), Is.True);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsMultiplePostingWarningsWhereOneMatchesPostingWarningIdentifier_AssertQueryAsyncWasCalledOnceOnQueryBusWithPullKeyValueEntryQueryForPostingJournalResultKey()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

            string postingJournalResultKey  = _fixture.Create <string>();
            Guid   postingWarningIdentifier = postingWarningIdentifierCollection[_random.Next(0, postingWarningIdentifierCollection.Length - 1)];
            await sut.RemovePostingWarningFromPostingJournalResult(_fixture.Create <int>(), postingJournalResultKey, postingWarningIdentifier);

            _queryBusMock.Verify(m => m.QueryAsync <IPullKeyValueEntryQuery, IKeyValueEntry>(It.Is <IPullKeyValueEntryQuery>(query => query != null && string.CompareOrdinal(query.Key, postingJournalResultKey) == 0)), Times.Once);
        }
        public async Task RemovePostingWarningFromPostingJournalResult_WhenPostingJournalResultKeyHasValueAndPostingJournalResultFromKeyValueEntryContainsMultiplePostingWarningsWhereOneMatchesPostingWarningIdentifier_ReturnsPartialViewResultWhereModelIsPostingWarningCollectionViewModelWithPostingWarningsFromReturnedPostingJournalResultExceptPostingWarningForPostingWarningIdentifier()
        {
            Guid[] postingWarningIdentifierCollection = BuildPostingWarningIdentifierCollection();
            PostingWarningCollectionViewModel  postingWarningCollectionViewModel  = BuildPostingWarningCollectionViewModel(postingWarningIdentifierCollection);
            ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = BuildApplyPostingJournalResultViewModel(postingWarningCollectionViewModel);
            IKeyValueEntry keyValueEntryForPostingJournalResult = BuildKeyValueEntryForPostingJournalResult(applyPostingJournalResultViewModel);
            Controller     sut = CreateSut(keyValueEntryForPostingJournalResult: keyValueEntryForPostingJournalResult);

            Guid postingWarningIdentifier = postingWarningIdentifierCollection[_random.Next(0, postingWarningIdentifierCollection.Length - 1)];
            PartialViewResult result      = (PartialViewResult)await sut.RemovePostingWarningFromPostingJournalResult(_fixture.Create <int>(), _fixture.Create <string>(), postingWarningIdentifier);

            PostingWarningCollectionViewModel resultViewModel = (PostingWarningCollectionViewModel)result.Model;

            Assert.That(resultViewModel.All(postingWarningViewModel => postingWarningIdentifierCollection.Where(identifier => identifier != postingWarningIdentifier).Any(identifier => postingWarningViewModel.Identifier == identifier)), Is.True);
        }
 private Mock <IKeyValueEntry> BuildKeyValueEntryForPostingJournalResultMock(ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = null)
 {
     return(_fixture.BuildKeyValueEntryMock(toObject: applyPostingJournalResultViewModel ?? BuildApplyPostingJournalResultViewModel()));
 }
 private IKeyValueEntry BuildKeyValueEntryForPostingJournalResult(ApplyPostingJournalResultViewModel applyPostingJournalResultViewModel = null)
 {
     return(BuildKeyValueEntryForPostingJournalResultMock(applyPostingJournalResultViewModel).Object);
 }