public async Task QueryAsync_WhenCalled_AssertStatusDateWasCalledOnGetPostingLineCollectionQuery()
        {
            QueryHandler sut = CreateSut();

            Mock <IGetPostingLineCollectionQuery> queryMock = CreateQueryMock();
            await sut.QueryAsync(queryMock.Object);

            queryMock.Verify(m => m.StatusDate, Times.Exactly(2));
        }
        public async Task QueryAsync_WhenCalled_AssertNumberOfPostingLinesWasCalledOnGetPostingLineCollectionQuery()
        {
            QueryHandler sut = CreateSut();

            Mock <IGetPostingLineCollectionQuery> queryMock = CreateQueryMock();
            await sut.QueryAsync(queryMock.Object);

            queryMock.Verify(m => m.NumberOfPostingLines, Times.Once);
        }
        public async Task QueryAsync_WhenNoPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsEmptyPostingLineCollection()
        {
            QueryHandler sut = CreateSut(false);

            IGetPostingLineCollectionQuery query  = CreateQuery();
            IPostingLineCollection         result = await sut.QueryAsync(query);

            Assert.That(result.Count(), Is.EqualTo(0));
        }
        public async Task QueryAsync_WhenNoPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsNotNull()
        {
            QueryHandler sut = CreateSut(false);

            IGetPostingLineCollectionQuery query  = CreateQuery();
            IPostingLineCollection         result = await sut.QueryAsync(query);

            Assert.That(result, Is.Not.Null);
        }
        public void QueryAsync_WhenQueryIsNull_ThrowsArgumentNullException()
        {
            QueryHandler sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.QueryAsync(null));

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("query"));
            // ReSharper restore PossibleNullReferenceException
        }
        public async Task QueryAsync_WhenNoPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsWhereStatusDateIsEqualToStatusDateFromGetPostingLineCollectionQuery()
        {
            QueryHandler sut = CreateSut(false);

            DateTime statusDate = _fixture.Create <DateTime>().Date;
            IGetPostingLineCollectionQuery query  = CreateQuery(statusDate: statusDate);
            IPostingLineCollection         result = await sut.QueryAsync(query);

            Assert.That(result.StatusDate, Is.EqualTo(statusDate));
        }
        public async Task QueryAsync_WhenPostingLineCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedPostingLineCollection()
        {
            IPostingLineCollection calculatedPostingLineCollection = _fixture.BuildPostingLineCollectionMock().Object;
            IPostingLineCollection postingLineCollection           = _fixture.BuildPostingLineCollectionMock(calculatedPostingLineCollection: calculatedPostingLineCollection).Object;
            QueryHandler           sut = CreateSut(postingLineCollection: postingLineCollection);

            IGetPostingLineCollectionQuery query  = CreateQuery();
            IPostingLineCollection         result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(calculatedPostingLineCollection));
        }
        public async Task QueryAsync_WhenCalled_AssertGetPostingLinesAsyncWasCalledOnAccountingRepository()
        {
            QueryHandler sut = CreateSut();

            int      accountingNumber            = _fixture.Create <int>();
            DateTime statusDate                  = _fixture.Create <DateTime>().Date;
            int      numberOfPostingLines        = _fixture.Create <int>();
            IGetPostingLineCollectionQuery query = CreateQuery(accountingNumber, statusDate, numberOfPostingLines);
            await sut.QueryAsync(query);

            _accountingRepositoryMock.Verify(m => m.GetPostingLinesAsync(
                                                 It.Is <int>(value => value == accountingNumber),
                                                 It.Is <DateTime>(value => value == statusDate),
                                                 It.Is <int>(value => value == numberOfPostingLines)),
                                             Times.Once);
        }