示例#1
0
        public void CheckValid()
        {
            _collectorValidatorMock1.Expect(stub => stub.CheckValid(_collector));
            _collectorValidatorMock2.Expect(stub => stub.CheckValid(_collector));

            _compoundCollectorValidator.CheckValid(_collector);

            _collectorValidatorMock1.VerifyAllExpectations();
            _collectorValidatorMock2.VerifyAllExpectations();
        }
        public void BuildValidator()
        {
            ExpectMocks();

            _collectorValidatorMock.Expect(mock => mock.CheckValid(_componenValidationCollectorStub1)).Repeat.Once();
            _collectorValidatorMock.Expect(mock => mock.CheckValid(_componenValidationCollectorStub2)).Repeat.Once();
            _collectorValidatorMock.Expect(mock => mock.CheckValid(_componenValidationCollectorStub3)).Repeat.Once();

            _metaRuleValidatorMock
            .Expect(mock => mock.Validate(Arg <IValidationRule[]> .List.Equal(_fakeValidationRuleResult)))
            .Return(new[] { _validMetaValidationResult1, _validMetaValidationResult2 });

            _memberInformationNameResolverMock
            .Expect(mock => mock.GetPropertyName(Arg <IPropertyInformation> .Matches(pi => pi.Name == "FirstName")))
            .Return("FakeTechnicalPropertyName1");
            _memberInformationNameResolverMock
            .Expect(mock => mock.GetPropertyName(Arg <IPropertyInformation> .Matches(pi => pi.Name == "LastName")))
            .Return("FakeTechnicalPropertyName2");

            _validationRuleGlobalizationServiceMock
            .Expect(mock => mock.ApplyMetadata(_validationRuleStub1, typeof(SpecialCustomer1)));
            _validationRuleGlobalizationServiceMock
            .Expect(mock => mock.ApplyMetadata(_validationRuleStub2, typeof(SpecialCustomer1)));
            _validationRuleGlobalizationServiceMock
            .Expect(mock => mock.ApplyMetadata(_validationRuleStub3, typeof(SpecialCustomer1)));
            _validationRuleGlobalizationServiceMock
            .Expect(mock => mock.ApplyMetadata(_validationRuleStub4, typeof(SpecialCustomer1)));

            var result = _fluentValidationBuilder.BuildValidator(typeof(SpecialCustomer1));

            _validationCollectorProviderMock.VerifyAllExpectations();
            _validationCollectorMergerMock.VerifyAllExpectations();
            _metaRuleValidatorMock.VerifyAllExpectations();
            _memberInformationNameResolverMock.VerifyAllExpectations();
            _validationRuleGlobalizationServiceMock.VerifyAllExpectations();
            Assert.That(result, Is.TypeOf(typeof(Validator)));
            var validator = (Validator)result;

            Assert.That(validator.ValidationRules, Is.EqualTo(_fakeValidationRuleResult));
            Assert.That(_validationRuleStub3.PropertyName, Is.EqualTo("FakeTechnicalPropertyName1"));
            Assert.That(_validationRuleStub4.PropertyName, Is.EqualTo("FakeTechnicalPropertyName2"));
        }