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

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

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

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

            Assert.That(result.ParamName, Is.EqualTo("accountingRepository"));
        }
        public async Task QueryAsync_WhenNoAccountCollectionWasReturnedFromAccountingRepository_ReturnsNotNull()
        {
            QueryHandler sut = CreateSut(false);

            IGetAccountCollectionQuery query  = CreateQuery();
            IAccountCollection         result = await sut.QueryAsync(query);

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

            IGetAccountCollectionQuery query  = CreateQuery();
            IAccountCollection         result = await sut.QueryAsync(query);

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

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

            Assert.That(result.StatusDate, Is.EqualTo(statusDate));
        }
        public async Task QueryAsync_WhenAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedAccountCollection()
        {
            IAccountCollection calculatedAccountCollection = _fixture.BuildAccountCollectionMock().Object;
            IAccountCollection accountCollection           = _fixture.BuildAccountCollectionMock(calculatedAccountCollection: calculatedAccountCollection).Object;
            QueryHandler       sut = CreateSut(accountCollection: accountCollection);

            IGetAccountCollectionQuery query  = CreateQuery();
            IAccountCollection         result = await sut.QueryAsync(query);

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

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

            _accountingRepositoryMock.Verify(m => m.GetAccountsAsync(
                                                 It.Is <int>(value => value == accountingNumber),
                                                 It.Is <DateTime>(value => value == statusDate)),
                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidator()
        {
            int accountingNumber           = _fixture.Create <int>();
            IGetAccountCollectionQuery 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);
        }