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

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

            Assert.That(result, Is.SameAs(_validatorMockContext.ValidatorMock.Object));
        }
        public void Validate_WhenCommonRepositoryIsNull_ThrowsArgumentNullException()
        {
            ICreateContactAccountCommand sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("commonRepository"));
        }
        public async Task ExecuteAsync_WhenCalled_AssertCreateContactAccountAsyncWasCalledOnAccountingRepository()
        {
            CommandHandler sut = CreateSut();

            IContactAccount contactAccount       = _fixture.BuildContactAccountMock().Object;
            ICreateContactAccountCommand command = CreateCommand(contactAccount);
            await sut.ExecuteAsync(command);

            _accountingRepositoryMock.Verify(m => m.CreateContactAccountAsync(It.Is <IContactAccount>(value => value == contactAccount)), Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldBeUnknownValueWasCalledOnObjectValidatorWithAccountNumber()
        {
            string accountNumber             = _fixture.Create <string>().ToUpper();
            ICreateContactAccountCommand sut = CreateSut(accountNumber);

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

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