public void Validate_WhenAccountingWasReturnedFromAccountingRepository_AssertValidateWasCalledOnEachApplyPostingLineCommand()
        {
            IAccounting accounting = _fixture.BuildAccountingMock().Object;
            IEnumerable <Mock <IApplyPostingLineCommand> > applyPostingLineCommandMockCollection = new[]
            {
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock()
            };
            IApplyPostingJournalCommand sut = CreateSut(accounting: accounting, applyPostingLineCommandCollection: applyPostingLineCommandMockCollection.Select(applyPostingLineCommandMock => applyPostingLineCommandMock.Object).ToArray());

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

            foreach (Mock <IApplyPostingLineCommand> applyPostingLineCommandMock in applyPostingLineCommandMockCollection)
            {
                applyPostingLineCommandMock.Verify(m => m.Validate(
                                                       It.Is <IValidator>(value => value == _validatorMockContext.ValidatorMock.Object),
                                                       It.Is <IAccounting>(value => value == accounting)),
                                                   Times.Once);
            }
        }
        public void Validate_WhenCalled_ReturnsValidator()
        {
            IApplyPostingJournalCommand sut = CreateSut();

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

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
        public void Validate_WhenCalled_AssertGetAccountingAsyncWasCalledOnAccountingRepository()
        {
            int accountingNumber            = _fixture.Create <int>();
            IApplyPostingJournalCommand sut = CreateSut(accountingNumber);

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

            _accountingRepositoryMock.Verify(m => m.GetAccountingAsync(
                                                 It.Is <int>(value => value == accountingNumber),
                                                 It.Is <DateTime>(value => value == DateTime.Today)),
                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldNotBeNullWasCalledOnObjectValidatorWithPostingLineCollection()
        {
            IEnumerable <IApplyPostingLineCommand> applyPostingLineCommandCollection = _fixture.CreateMany <IApplyPostingLineCommand>(_random.Next(10, 25)).ToArray();
            IApplyPostingJournalCommand            sut = CreateSut(applyPostingLineCommandCollection: applyPostingLineCommandCollection);

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

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldNotBeNull(
                                                                 It.Is <IEnumerable <IApplyPostingLineCommand> >(value => value.Equals(applyPostingLineCommandCollection)),
                                                                 It.Is <Type>(type => type == sut.GetType()),
                                                                 It.Is <string>(field => string.CompareOrdinal(field, "PostingLineCollection") == 0)),
                                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidatorWithAccountingNumber()
        {
            int accountingNumber            = _fixture.Create <int>();
            IApplyPostingJournalCommand sut = CreateSut(accountingNumber);

            sut.Validate(_validatorMockContext.ValidatorMock.Object, _accountingRepositoryMock.Object, _commonRepositoryMock.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);
        }
        public void Validate_WhenAccountingWasNotReturnedFromAccountingRepository_AssertValidateWasNotCalledOnAnyApplyPostingLineCommand()
        {
            IEnumerable <Mock <IApplyPostingLineCommand> > applyPostingLineCommandMockCollection = new[]
            {
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock(),
                CreateApplyPostingLineCommandMock()
            };
            IApplyPostingJournalCommand sut = CreateSut(hasAccounting: false, applyPostingLineCommandCollection: applyPostingLineCommandMockCollection.Select(applyPostingLineCommandMock => applyPostingLineCommandMock.Object).ToArray());

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

            foreach (Mock <IApplyPostingLineCommand> applyPostingLineCommandMock in applyPostingLineCommandMockCollection)
            {
                applyPostingLineCommandMock.Verify(m => m.Validate(
                                                       It.IsAny <IValidator>(),
                                                       It.IsAny <IAccounting>()),
                                                   Times.Never);
            }
        }
        public void Validate_WhenCommonRepositoryIsNull_ThrowsArgumentNullException()
        {
            IApplyPostingJournalCommand sut = CreateSut();

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

            // ReSharper disable PossibleNullReferenceException
            Assert.That(result.ParamName, Is.EqualTo("commonRepository"));
            // ReSharper restore PossibleNullReferenceException
        }