コード例 #1
0
        public void Validate_WhenCalled_ReturnsValidator()
        {
            IGetPostalCodeCollectionQuery sut = CreateSut();

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

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
コード例 #2
0
        public void Validate_WhenCalled_AssertShouldBeKnownValueWasCalledOnObjectValidator()
        {
            string countryCode = _fixture.Create <string>();
            IGetPostalCodeCollectionQuery sut = CreateSut(countryCode);

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

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldBeKnownValue(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, countryCode.ToUpper()) == 0),
                                                                 It.IsNotNull <Func <string, Task <bool> > >(),
                                                                 It.Is <Type>(value => sut.GetType() == value),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "CountryCode") == 0),
                                                                 It.Is <bool>(value => value == false)),
                                                             Times.Once());
        }
        public async Task <IEnumerable <IPostalCode> > QueryAsync(IGetPostalCodeCollectionQuery query)
        {
            NullGuard.NotNull(query, nameof(query));

            query.Validate(_validator, _contactRepository);

            IEnumerable <IPostalCode> postalCodes = await _contactRepository.GetPostalCodesAsync(query.CountryCode);

            if (postalCodes == null)
            {
                return(new List <IPostalCode>(0));
            }

            return(postalCodes.Select(postalCode =>
            {
                postalCode.Country = _countryHelper.ApplyLogicForPrincipal(postalCode.Country);
                return postalCode;
            })
                   .ToList());
        }
コード例 #4
0
        public void Validate_WhenContactRepositoryIsNull_ThrowsArgumentNullException()
        {
            IGetPostalCodeCollectionQuery sut = CreateSut();

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

            Assert.That(result.ParamName, Is.EqualTo("contactRepository"));
        }