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

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

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

            IGetDebtorAccountCollectionQuery query  = CreateQuery();
            IContactAccountCollection        result = await sut.QueryAsync(query);

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

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

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

            IGetDebtorAccountCollectionQuery query  = CreateQuery();
            IContactAccountCollection        result = await sut.QueryAsync(query);

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

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

            Assert.That(result.StatusDate, Is.EqualTo(statusDate));
        }
        public async Task QueryAsync_WhenContactAccountCollectionWasReturnedFromAccountingRepository_AssertFindDebtorsAsyncWasCalledOnCalculatedContactAccountCollection()
        {
            Mock <IContactAccountCollection> calculatedContactAccountCollectionMock = _fixture.BuildContactAccountCollectionMock();
            IContactAccountCollection        contactAccountCollection = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedContactAccountCollectionMock.Object).Object;
            QueryHandler sut = CreateSut(contactAccountCollection: contactAccountCollection);

            DateTime statusDate = _fixture.Create <DateTime>();
            IGetDebtorAccountCollectionQuery query = CreateQuery(statusDate: statusDate);
            await sut.QueryAsync(query);

            calculatedContactAccountCollectionMock.Verify(m => m.FindDebtorsAsync(), Times.Once);
        }
        public async Task QueryAsync_WhenContactAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedDebtorAccountCollection()
        {
            IContactAccountCollection calculatedDebtorAccountCollection  = _fixture.BuildContactAccountCollectionMock().Object;
            IContactAccountCollection debtorAccountCollection            = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedDebtorAccountCollection).Object;
            IContactAccountCollection calculatedContactAccountCollection = _fixture.BuildContactAccountCollectionMock(findDebtorsContactAccountCollection: debtorAccountCollection).Object;
            IContactAccountCollection contactAccountCollection           = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedContactAccountCollection).Object;
            QueryHandler sut = CreateSut(contactAccountCollection: contactAccountCollection);

            IGetDebtorAccountCollectionQuery query  = CreateQuery();
            IContactAccountCollection        result = await sut.QueryAsync(query);

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

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

            _accountingRepositoryMock.Verify(m => m.GetContactAccountsAsync(
                                                 It.Is <int>(value => value == accountingNumber),
                                                 It.Is <DateTime>(value => value == statusDate)),
                                             Times.Once);
        }
        public void QueryAsync_WhenQueryIsNull_ThrowsArgumentNullException()
        {
            QueryHandler sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("query"));
        }