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

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

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

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

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

            Mock <IGetCreditorAccountCollectionQuery> 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);

            IGetCreditorAccountCollectionQuery 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;
            IGetCreditorAccountCollectionQuery query  = CreateQuery(statusDate: statusDate);
            IContactAccountCollection          result = await sut.QueryAsync(query);

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

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

            calculatedContactAccountCollectionMock.Verify(m => m.FindCreditorsAsync(), Times.Once);
        }
        public async Task QueryAsync_WhenContactAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedCreditorAccountCollection()
        {
            IContactAccountCollection calculatedCreditorAccountCollection = _fixture.BuildContactAccountCollectionMock().Object;
            IContactAccountCollection creditorAccountCollection           = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedCreditorAccountCollection).Object;
            IContactAccountCollection calculatedContactAccountCollection  = _fixture.BuildContactAccountCollectionMock(findCreditorContactAccountCollection: creditorAccountCollection).Object;
            IContactAccountCollection contactAccountCollection            = _fixture.BuildContactAccountCollectionMock(calculatedContactAccountCollection: calculatedContactAccountCollection).Object;
            QueryHandler sut = CreateSut(contactAccountCollection: contactAccountCollection);

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

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

            int      accountingNumber = _fixture.Create <int>();
            DateTime statusDate       = _fixture.Create <DateTime>().Date;
            IGetCreditorAccountCollectionQuery 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"));
        }