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

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

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

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

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

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

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

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

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

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

            Assert.That(result.StatusDate, Is.EqualTo(statusDate));
        }
        public async Task QueryAsync_WhenBudgetAccountCollectionWasReturnedFromAccountingRepository_ReturnsCalculatedBudgetAccountCollection()
        {
            IBudgetAccountCollection calculatedBudgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock().Object;
            IBudgetAccountCollection budgetAccountCollection = _fixture.BuildBudgetAccountCollectionMock(calculatedBudgetAccountCollection: calculatedBudgetAccountCollection).Object;
            QueryHandler sut = CreateSut(budgetAccountCollection: budgetAccountCollection);

            IGetBudgetAccountCollectionQuery query = CreateQuery();
            IBudgetAccountCollection result = await sut.QueryAsync(query);

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

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

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