public void Validate_WhenCalled_ReturnsValidator()
        {
            IGetDebtorAccountCollectionQuery sut = CreateSut();

            IValidator result = sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object);

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
        public void Validate_WhenAccountingRepositoryIsNull_ThrowsArgumentNullException()
        {
            IGetDebtorAccountCollectionQuery sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Validate(_validatorMockContext.ValidatorMock.Object, null));

            Assert.That(result.ParamName, Is.EqualTo("accountingRepository"));
        }
        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_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 Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidator()
        {
            int accountingNumber = _fixture.Create <int>();
            IGetDebtorAccountCollectionQuery sut = CreateSut(accountingNumber);

            sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object);

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeKnownValue(
                                                                 It.Is <int>(value => value == accountingNumber),
                                                                 It.IsNotNull <Func <int, Task <bool> > >(),
                                                                 It.Is <Type>(type => type == sut.GetType()),
                                                                 It.Is <string>(field => string.CompareOrdinal(field, "AccountingNumber") == 0),
                                                                 It.Is <bool>(allowNull => allowNull == false)),
                                                             Times.Once);
        }