public void Merge_RemoveValidatorWithNoCollectorTypeDefinied_ValidatorIsRemoved() { _componenValidationCollectorStub1.Stub(stub => stub.AddedPropertyRules).Return(new[] { _addingPropertyRule1 }); _componenValidationCollectorStub1.Stub(stub => stub.RemovedPropertyRules).Return(new IRemovingComponentPropertyRule[0]); _componenValidationCollectorStub2.Stub(stub => stub.AddedPropertyRules).Return(new[] { _addingPropertyRule2, _addingPropertyRule3 }); _componenValidationCollectorStub2.Stub(stub => stub.RemovedPropertyRules).Return(new[] { _removingPropertyRule1 }); _propertyValidatorExtractorFactoryMock .Expect( mock => mock.Create( Arg <IEnumerable <ValidatorRegistrationWithContext> > .Matches( c => c.Count() == 1 && c.ToArray()[0].ValidatorRegistration.ValidatorType == typeof(NotEmptyValidator)), Arg <ILogContext> .Is.NotNull)) .Return(_propertyValidatorExtractorMock); _propertyValidatorExtractorMock .Expect(mock => mock.ExtractPropertyValidatorsToRemove(_addingPropertyRule1)) .Return(new[] { _notEmptyValidator }); var result = _merger.Merge( new[] { new[] { new ValidationCollectorInfo(_componenValidationCollectorStub1, typeof(ApiBasedComponentValidationCollectorProvider)) }, new[] { new ValidationCollectorInfo(_componenValidationCollectorStub2, typeof(ApiBasedComponentValidationCollectorProvider)) } }).CollectedRules.ToArray(); _propertyValidatorExtractorFactoryMock.VerifyAllExpectations(); _propertyValidatorExtractorMock.VerifyAllExpectations(); Assert.That(result.Count(), Is.EqualTo(3)); Assert.That(result[0].Validators, Is.EquivalentTo(new IPropertyValidator[] { _notNullValidator, _notEqualValidator })); Assert.That(result[1].Validators, Is.EquivalentTo(new IPropertyValidator[] { _maximumLengthValidator })); Assert.That(result[2].Validators, Is.EquivalentTo(new IPropertyValidator[] { _minimumLengthValidator })); }
public void ApplyRemoveValidatorRegistrations_NoHardConstraint() { _addingComponentPropertyRule.RegisterValidator(_stubPropertyValidator1); _addingComponentPropertyRule.RegisterValidator(_stubPropertyValidator2); _addingComponentPropertyRule.RegisterValidator(_stubPropertyValidator3); Assert.That(_addingComponentPropertyRule.Validators.Count(), Is.EqualTo(3)); _propertyValidatorExtractorMock .Expect( mock => mock.ExtractPropertyValidatorsToRemove(_addingComponentPropertyRule)) .Return(new IPropertyValidator[] { _stubPropertyValidator1, _stubPropertyValidator3 }); _addingComponentPropertyRule.ApplyRemoveValidatorRegistrations(_propertyValidatorExtractorMock); _propertyValidatorExtractorMock.VerifyAllExpectations(); Assert.That(_addingComponentPropertyRule.Validators, Is.EqualTo(new[] { _stubPropertyValidator2 })); }