public void When_value_is_Default_for_type_validator_should_fail_datetime() { var defaultValue = default(DateTime); var validator = new NotEmptyValidator(defaultValue); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => defaultValue)); result.IsValid().ShouldBeFalse(); }
private TrainEditForm(Timetable tt) { Eto.Serialization.Xaml.XamlReader.Load(this); this.tt = tt; th = new TrainEditHelper(); nameValidator = new NotEmptyValidator(nameTextBox, errorMessage: T._("Bitte einen Zugnamen eingeben!")); locomotiveComboBox.Items.AddRange(GetAllItems(tt, t => t.Locomotive)); lastComboBox.Items.AddRange(GetAllItems(tt, t => t.Last)); mbrComboBox.Items.AddRange(GetAllItems(tt, t => t.Mbr)); KeyDown += (s, e) => daysControl.HandleKeypress(e); resetTransitionButton.TextColor = Colors.Red; if (tt.Type == TimetableType.Network && tt.Version.CompareTo(TimetableVersion.Extended_FPL2) < 0) { linkGroupBox.Visible = false; } else { linkGridView.AddColumn <TrainLink>(tl => tl.TrainCount.ToString(), T._("Anzahl")); linkGridView.AddColumn <TrainLink>(tl => tl.TimeOffset.ToTimeString(), T._("Erster Abstand")); linkGridView.AddColumn <TrainLink>(tl => tl.TimeDifference.ToTimeString(), T._("Zeitdifferenz")); } }
public void IsValidMustReturnTrueIfTheSpecifiedValueIsNotIEnumarableAndString() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(); Assert.IsTrue(notEmptyValidator.IsValid(new object())); Assert.IsTrue(notEmptyValidator.IsValid(1)); }
public void DefaultErrorMessage_NotEmptyValidator() { var validator = new NotEmptyValidator(null); Assert.That(validator.ErrorMessageSource, Is.TypeOf(typeof(LocalizedStringSource))); Assert.That(validator.ErrorMessageSource.GetString(), Is.EqualTo(Messages.notempty_error)); }
private EditStationForm() { Eto.Serialization.Xaml.XamlReader.Load(this); positionValidator = new NumberValidator(positionTextBox, false, false, errorMessage: "Bitte eine Zahl als Position eingeben!"); nameValidator = new NotEmptyValidator(nameTextBox, errorMessage: "Bitte einen Bahnhofsnamen eingeben!"); validators = new ValidatorCollection(positionValidator, nameValidator); this.Shown += (s, e) => { stationRendererHeight = stationRenderer.Height; stationRendererWidth = stationRenderer.Width; }; stationRenderer.SizeChanged += (s, e) => { if (WindowShown && stationRenderer.Height > stationRendererHeight) { var diff = stationRenderer.Height - stationRendererHeight; this.Height += diff; stationRendererHeight = stationRenderer.Height; } if (WindowShown && stationRenderer.Width > stationRendererWidth) { var diff = stationRenderer.Width - stationRendererWidth; this.Width += diff; stationRendererWidth = stationRenderer.Width; } }; }
public void IsValidMustReturnTrueIfTheSpecifiedValueIsNotEmptyList() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(); Assert.IsTrue(notEmptyValidator.IsValid(new List <int> { 1, 2 })); }
public void IsValidMustReturnFalseIfTheSpecifiedValueIsNullEmptyOrWhitespace() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(); Assert.IsFalse(notEmptyValidator.IsValid(null)); Assert.IsFalse(notEmptyValidator.IsValid(string.Empty)); Assert.IsFalse(notEmptyValidator.IsValid(" ")); }
public void Format_NotEmptyValidator() { var validator = new NotEmptyValidator(null); var result = _formatter.Format(validator, _typeNameFormatter); Assert.That(result, Is.EqualTo("NotEmptyValidator")); }
public void When_value_is_Default_for_type_validator_should_fail_int() { var validator = new NotEmptyValidator(default(int)); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => 0)); result.IsValid().ShouldBeFalse(); var result1 = validator.Validate(new PropertyValidatorContext(null, new object(), x => 1)); result1.IsValid().ShouldBeTrue(); }
public void Uses_custom_resouces() { ValidatorOptions.ResourceProviderType = typeof(MyResources); var validator = new NotEmptyValidator(null); var result = validator.Validate(new PropertyValidatorContext("name", null, x => null)); result.Single().ErrorMessage.ShouldEqual("foo"); ValidatorOptions.ResourceProviderType = null; }
public void isValidWithValue() { NotEmptyValidator val = new NotEmptyValidator(); Expect.On(ictl).Call(ictl.getValue()).Return( "pepe" ); rep.ReplayAll(); Assert.IsTrue(val.isValid(ictl)); }
public void isValid() { NotEmptyValidator val = new NotEmptyValidator(); ictl = rep.Stub <iControl>(); Expect.On(ictl).Call(ictl.getValue()).Return(String.Empty); rep.ReplayAll(); Assert.IsFalse(val.isValid(ictl)); }
public void Should_create_notemptyadapter_for_notemptyvalidator() { // Given var validator = new NotEmptyValidator(1); // When var result = factory.Create(this.rule, validator); // Then result.ShouldBeOfType <NotEmptyAdapter>(); }
public void SetUp() { _property = PropertyInfoAdapter.Create(typeof(Customer).GetProperty("UserName")); _userNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.UserName); _lastNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName); _stubPropertyValidator1 = new StubPropertyValidator(); _stubPropertyValidator2 = new NotEmptyValidator(null); _stubPropertyValidator3 = new NotEqualValidator("gfsf"); _propertyValidatorExtractorMock = MockRepository.GenerateStrictMock <IPropertyValidatorExtractor>(); _addingComponentPropertyRule = AddingComponentPropertyRule.Create(_userNameExpression, typeof(CustomerValidationCollector1)); }
public void SetUp() { _notEmptyValidator = new NotEmptyValidator(null); _notNullValidator = new NotNullValidator(); _notEqualValidator = new NotEqualValidator("test"); _maximumLengthValidator = new MaximumLengthValidator(30); _minimumLengthValidator = new MinimumLengthValidator(5); _componenValidationCollectorStub1 = MockRepository.GenerateStub <IComponentValidationCollector>(); _componenValidationCollectorStub2 = MockRepository.GenerateStub <IComponentValidationCollector>(); _componenValidationCollectorStub3 = MockRepository.GenerateStub <IComponentValidationCollector>(); _firstNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.FirstName); _lastNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName); _addingPropertyRule1 = AddingComponentPropertyRule.Create(_firstNameExpression, _componenValidationCollectorStub1.GetType()); _addingPropertyRule1.RegisterValidator(_notEmptyValidator); _addingPropertyRule1.RegisterValidator(_notNullValidator); _addingPropertyRule1.RegisterValidator(_notEqualValidator); _addingPropertyRule2 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType()); _addingPropertyRule2.RegisterValidator(_maximumLengthValidator); _addingPropertyRule3 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType()); _addingPropertyRule3.RegisterValidator(_minimumLengthValidator); _addingPropertyRule4 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType()); _addingPropertyRule4.RegisterValidator(_notNullValidator); _removingPropertyRule1 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1)); _removingPropertyRule1.RegisterValidator(typeof(NotEmptyValidator)); _removingPropertyRule2 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1)); _removingPropertyRule2.RegisterValidator(typeof(NotNullValidator), _componenValidationCollectorStub1.GetType()); _removingPropertyRule3 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1)); _removingPropertyRule3.RegisterValidator(typeof(NotNullValidator), typeof(string)); //Unknow collector type! _removingPropertyRule4 = RemovingComponentPropertyRule.Create(_lastNameExpression, typeof(CustomerValidationCollector1)); _removingPropertyRule4.RegisterValidator(typeof(MaximumLengthValidator)); _propertyValidatorExtractorFactoryMock = MockRepository.GenerateStrictMock <IPropertyValidatorExtractorFactory>(); _propertyValidatorExtractorMock = MockRepository.GenerateStrictMock <IPropertyValidatorExtractor>(); _merger = new OrderPrecedenceValidationCollectorMerger(_propertyValidatorExtractorFactoryMock); }
private EditStationForm(Timetable tt, IPluginInterface pluginInterface) { this.pluginInterface = pluginInterface; Eto.Serialization.Xaml.XamlReader.Load(this); var positionValidator = new NumberValidator(positionTextBox, false, false, errorMessage: T._("Bitte eine Zahl als Position eingeben!")); var nameValidator = new NotEmptyValidator(nameTextBox, errorMessage: T._("Bitte einen Bahnhofsnamen eingeben!")); validators = new ValidatorCollection(positionValidator, nameValidator); this.Shown += (s, e) => { stationRendererHeight = stationRenderer.Height; stationRendererWidth = stationRenderer.Width; }; stationRenderer.SizeChanged += (s, e) => { var size = ClientSize; var changed = false; if (WindowShown && stationRenderer.Height > stationRendererHeight) { var diff = stationRenderer.Height - stationRendererHeight; size.Height += diff; stationRendererHeight = stationRenderer.Height; changed = true; } if (WindowShown && stationRenderer.Width > stationRendererWidth) { var diff = stationRenderer.Width - stationRendererWidth; size.Width += diff; stationRendererWidth = stationRenderer.Width; changed = true; } if (changed) { ClientSize = size; } }; typeComboBox.DataStore = tt.Stations.Select(s => s.StationType).Distinct().Where(s => s != "").OrderBy(s => s).Select(s => new ListItem { Text = s }); }
public void SetUp() { _defaultMessageEvaluatorMock = MockRepository.GenerateStrictMock <IDefaultMessageEvaluator>(); _validatorGlobalizationServiceMock = MockRepository.GenerateStrictMock <IErrorMessageGlobalizationService>(); _validator1 = new NotNullValidator(); _errorMessageSource1 = _validator1.ErrorMessageSource; _validator2 = new NotEmptyValidator(null); _errorMessageSource2 = _validator2.ErrorMessageSource; _validator3 = new NotEqualValidator("test"); _errorMessageSource3 = _validator3.ErrorMessageSource; _propertyRule = PropertyRule.Create(ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName)); _propertyRule.AddValidator(_validator1); _propertyRule.AddValidator(_validator2); _propertyRule.AddValidator(_validator3); _service = new ValidationRuleGlobalizationService(_defaultMessageEvaluatorMock, _validatorGlobalizationServiceMock); }
public void Correctly_assigns_default_localized_error_message() { var originalCulture = Thread.CurrentThread.CurrentUICulture; try { var validator = new NotEmptyValidator(null); foreach (var culture in new[] {"en", "de", "fr"}) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); var message = Messages.ResourceManager.GetString("notempty_error"); var errorMessage = new MessageFormatter().AppendPropertyName("name").BuildMessage(message); Debug.WriteLine(errorMessage); var result = validator.Validate(new PropertyValidatorContext("name", null, x => null)); result.Single().ErrorMessage.ShouldEqual(errorMessage); } } finally { // Always reset the culture. Thread.CurrentThread.CurrentUICulture = originalCulture; } }
public void SetUp() { _validatorRegistration1 = new ValidatorRegistration(typeof(NotEmptyValidator), null); _validatorRegistration2 = new ValidatorRegistration(typeof(NotEqualValidator), typeof(CustomerValidationCollector1)); _validatorRegistration3 = new ValidatorRegistration(typeof(NotNullValidator), null); _validatorRegistration4 = new ValidatorRegistration(typeof(LengthValidator), typeof(CustomerValidationCollector2)); _validatorRegistration5 = new ValidatorRegistration(typeof(NotEqualValidator), typeof(CustomerValidationCollector2)); _validatorRegistration6 = new ValidatorRegistration(typeof(LengthValidator), null); _removingPropertyRuleStub1 = MockRepository.GenerateStub <IRemovingComponentPropertyRule>(); _removingPropertyRuleStub1.Stub(stub => stub.Property).Return(PropertyInfoAdapter.Create(typeof(Customer).GetProperty("LastName"))); _removingPropertyRuleStub2 = MockRepository.GenerateStub <IRemovingComponentPropertyRule>(); _removingPropertyRuleStub2.Stub(stub => stub.Property).Return(PropertyInfoAdapter.Create(typeof(Customer).GetProperty("FirstName"))); _registrationWithContext1 = new ValidatorRegistrationWithContext(_validatorRegistration1, _removingPropertyRuleStub1); _registrationWithContext2 = new ValidatorRegistrationWithContext(_validatorRegistration2, _removingPropertyRuleStub1); _registrationWithContext3 = new ValidatorRegistrationWithContext(_validatorRegistration3, _removingPropertyRuleStub1); _registrationWithContext4 = new ValidatorRegistrationWithContext(_validatorRegistration4, _removingPropertyRuleStub1); _registrationWithContext5 = new ValidatorRegistrationWithContext(_validatorRegistration5, _removingPropertyRuleStub1); _registrationWithContext6 = new ValidatorRegistrationWithContext(_validatorRegistration1, _removingPropertyRuleStub1); _registrationWithContext7 = new ValidatorRegistrationWithContext(_validatorRegistration6, _removingPropertyRuleStub2); //other property -> filtered! _stubPropertyValidator1 = new StubPropertyValidator(); //not extracted _stubPropertyValidator2 = new NotEmptyValidator(null); //extracted _stubPropertyValidator3 = new NotEqualValidator("gfsf"); //extracted _stubPropertyValidator4 = new LengthValidator(0, 10); //not extracted _logContextMock = MockRepository.GenerateStrictMock <ILogContext>(); _extractor = new PropertyValidatorExtractor( new[] { _registrationWithContext1, _registrationWithContext2, _registrationWithContext3, _registrationWithContext4, _registrationWithContext5, _registrationWithContext6, _registrationWithContext7 }, _logContextMock); }
public void Should_create_notemptyadapter_for_notemptyvalidator() { // Given var validator = new NotEmptyValidator(1); // When var result = factory.Create(this.rule, validator); // Then result.ShouldBeOfType<NotEmptyAdapter>(); }
public NullableNotEmptyValidator() { _underlyingNotEmptyValidator = new NotEmptyValidator <T, TProperty>(); }
private void AddAttributeValidation() { var type = typeof(TModel); var ignoreAttrsAttr = type.GetTypeInfo().GetCustomAttributes(typeof(IgnoreValidationAttributesAttribute), true) .FirstOrDefault() as IgnoreValidationAttributesAttribute; var ignoreProps = ignoreAttrsAttr != null ? new HashSet <string>(ignoreAttrsAttr.Properties ?? new string[0]) : new HashSet <string>(); foreach (var prop in type.GetProperties().Where(o => !ignoreProps.Contains(o.Name))) { var attrs = prop.GetCustomAttributes(true); //Add validation from attributes foreach (var attr in attrs.OfType <ValidationAttribute>()) { IPropertyValidator propValidator = null; #region NotNullAttribute if (attr is NotNullAttribute) { propValidator = new NotNullValidator(); } #endregion #region EmailAttribute if (attr is EmailAttribute) { propValidator = new EmailValidator(); } #endregion #region EnumAttribute var enumAttr = attr as EnumAttribute; if (enumAttr != null) { propValidator = new EnumValidator(enumAttr.Type); } #endregion #region NotEmptyAttribute var notEmptyAttr = attr as NotEmptyAttribute; if (notEmptyAttr != null) { propValidator = new NotEmptyValidator(notEmptyAttr.DefaultValue ?? prop.PropertyType.GetDefaultValue()); } #endregion #region NotNullOrEmptyAttribute var notNullOrEmptyAttr = attr as NotNullOrEmptyAttribute; if (notNullOrEmptyAttr != null) { propValidator = new NotEmptyValidator(prop.PropertyType.GetDefaultValue()); AddAttributePropertyValidator(new NotNullValidator(), prop, attr.IncludePropertyName); } #endregion #region EqualAttribute AddComparisonValidator(attr as EqualAttribute, type, prop, o => new EqualValidator(o), (func, info) => new EqualValidator(func, info)); #endregion #region LengthAttribute var lengthAttr = attr as LengthAttribute; if (lengthAttr != null) { propValidator = new LengthValidator(lengthAttr.Min, lengthAttr.Max); } #endregion #region NotEqualAttribute AddComparisonValidator(attr as NotEqualAttribute, type, prop, o => new NotEqualValidator(o), (func, info) => new NotEqualValidator(func, info)); #endregion #region RegularExpressionAttribute var regexAttr = attr as RegularExpressionAttribute; if (regexAttr != null) { propValidator = new RegularExpressionValidator(regexAttr.Expression, regexAttr.RegexOptions); } #endregion #region CreditCardAttribute if (attr is CreditCardAttribute) { propValidator = new CreditCardValidator(); } #endregion #region ScalePrecisionAttribute var scalePrecisionAttr = attr as ScalePrecisionAttribute; if (scalePrecisionAttr != null) { propValidator = new ScalePrecisionValidator(scalePrecisionAttr.Scale, scalePrecisionAttr.Precision); } #endregion #region ExactLengthAttribute var exctLenAttr = attr as ExactLengthAttribute; if (exctLenAttr != null) { propValidator = new ExactLengthValidator(exctLenAttr.Length); } #endregion #region ExclusiveBetweenAttribute var exclusiveBetweenAttribute = attr as ExclusiveBetweenAttribute; if (exclusiveBetweenAttribute != null) { if (exclusiveBetweenAttribute.From != null && exclusiveBetweenAttribute.To != null && exclusiveBetweenAttribute.From.GetType() != exclusiveBetweenAttribute.To.GetType()) { var fromConverted = Convert.ChangeType(exclusiveBetweenAttribute.From, exclusiveBetweenAttribute.To.GetType()); propValidator = new ExclusiveBetweenValidator(fromConverted as IComparable, exclusiveBetweenAttribute.To as IComparable); } else { propValidator = new ExclusiveBetweenValidator(exclusiveBetweenAttribute.From as IComparable, exclusiveBetweenAttribute.To as IComparable); } } #endregion #region ExclusiveBetweenAttribute var inclusiveBetweenAttribute = attr as InclusiveBetweenAttribute; if (inclusiveBetweenAttribute != null) { if (inclusiveBetweenAttribute.From != null && inclusiveBetweenAttribute.To != null && inclusiveBetweenAttribute.From.GetType() != inclusiveBetweenAttribute.To.GetType()) { var fromConverted = Convert.ChangeType(inclusiveBetweenAttribute.From, inclusiveBetweenAttribute.To.GetType()); propValidator = new InclusiveBetweenValidator(fromConverted as IComparable, inclusiveBetweenAttribute.To as IComparable); } else { propValidator = new InclusiveBetweenValidator(inclusiveBetweenAttribute.From as IComparable, inclusiveBetweenAttribute.To as IComparable); } } #endregion #region GreaterThanAttribute AddComparisonValidator(attr as GreaterThanAttribute, type, prop, o => new GreaterThanValidator(o as IComparable), (func, info) => new GreaterThanValidator(func, info)); #endregion #region GreaterThanOrEqualAttribute AddComparisonValidator(attr as GreaterThanOrEqualAttribute, type, prop, o => new GreaterThanOrEqualValidator(o as IComparable), (func, info) => new GreaterThanOrEqualValidator(func, info)); #endregion #region LessThanOrEqualAttribute AddComparisonValidator(attr as LessThanOrEqualAttribute, type, prop, o => new LessThanOrEqualValidator(o as IComparable), (func, info) => new LessThanOrEqualValidator(func, info)); #endregion #region LessThanAttribute AddComparisonValidator(attr as LessThanAttribute, type, prop, o => new LessThanValidator(o as IComparable), (func, info) => new LessThanValidator(func, info)); #endregion if (propValidator == null) { continue; } AddAttributePropertyValidator(propValidator, prop, attr.IncludePropertyName); } } }
public void When_value_is_null_validator_should_fail() { var validator = new NotEmptyValidator(default(string)); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => null)); result.IsValid().ShouldBeFalse(); }
public void When_validation_fails_error_should_be_set() { var validator = new NotEmptyValidator(default(string)); var result = validator.Validate(new PropertyValidatorContext("name", null, x => null)); result.Single().ErrorMessage.ShouldEqual("'name' should not be empty."); }
private TrainEditForm(Timetable tt) { Eto.Serialization.Xaml.XamlReader.Load(this); this.tt = tt; th = new TrainEditHelper(); nameValidator = new NotEmptyValidator(nameTextBox, errorMessage: "Bitte einen Zugnamen eingeben!"); daysBoxes = new[] { mondayCheckBox, tuesdayCheckBox, wednesdayCheckBox, thursdayCheckBox, fridayCheckBox, saturdayCheckBox, sundayCheckBox }; foreach (var dayBox in daysBoxes) { dayBox.CheckedChanged += CheckBoxStateChanged; } locomotiveComboBox.Items.AddRange(GetAllItems(tt, t => t.Locomotive)); lastComboBox.Items.AddRange(GetAllItems(tt, t => t.Last)); mbrComboBox.Items.AddRange(GetAllItems(tt, t => t.Mbr)); KeyDown += (s, e) => { if (!e.Control) { return; } var handled = true; if (new[] { Keys.D0, Keys.Keypad0 }.Contains(e.Key)) { ApplyShortcut(zShortcut); } else if (e.Key == Keys.A) { ApplyShortcut(aShortcut); } else if (e.Key == Keys.W && e.Shift) { ApplyShortcut(wExclSaShortcut); } else if (e.Key == Keys.W) { ApplyShortcut(wShortcut); } else if (e.Key == Keys.S) { ApplyShortcut(sShortcut); } else { handled = false; } e.Handled = handled; }; var shortcutsButtons = new[] { wShort, wSaShort, sShort, aShort, zShort }; var shortcuts = new[] { wShortcut, wExclSaShortcut, sShortcut, aShortcut, zShortcut }; shortcutsToggle = new ToggleButton[shortcuts.Length]; for (int i = 0; i < shortcutsButtons.Length; i++) { var toggle = new ToggleButton(shortcutsButtons[i]) { Tag = shortcuts[i], AllowDisable = false }; toggle.ToggleClick += ApplyShortcutBtn; shortcutsToggle[i] = toggle; } }
public void When_there_is_a_value_then_the_validator_should_pass() { var validator = new NotEmptyValidator(default(string)); var result = validator.Validate(new PropertyValidatorContext(null, new object(), x => "Farf")); result.IsValid().ShouldBeTrue(); }
public void IsValidMustReturnTrueIfTheSpecifiedValueIsNotEmpty() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(); Assert.IsTrue(notEmptyValidator.IsValid("1234")); }
public void IsValidMustReturnFalseIfTheSpecifiedValueIsEmptyList() { NotEmptyValidator notEmptyValidator = new NotEmptyValidator(); Assert.IsFalse(notEmptyValidator.IsValid(new List <int>())); }
public void isValidWithNull() { NotEmptyValidator val = new NotEmptyValidator(); val.isValid(null); }
public void Merge_WithValidationCollectors() { var collector1 = new TypeWithoutBaseTypeCollector1(); var collector2 = new TypeWithoutBaseTypeCollector2(); var validationCollectorInfos = new[] { new[] { new ValidationCollectorInfo( collector1, typeof(ValidationAttributesBasedCollectorProvider)) }, new[] { new ValidationCollectorInfo(collector2, typeof(ApiBasedComponentValidationCollectorProvider)) } }; var userNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.UserName); var lastNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName); var stubValidator1 = new NotNullValidator(); var stubValidator2 = new NotEmptyValidator(null); var stubValidator3 = new NotEqualValidator("test"); var stubValidator4 = new StubPropertyValidator(); _validatorFormatterStub.Stub( stub => stub.Format(Arg <IPropertyValidator> .Matches(c => c.GetType() == typeof(NotNullValidator)), Arg <Func <Type, string> > .Is.Anything)) .Return("FluentValidation.Validators.NotNullValidator"); _validatorFormatterStub.Stub( stub => stub.Format(Arg <IPropertyValidator> .Matches(c => c.GetType() == typeof(LengthValidator)), Arg <Func <Type, string> > .Is.Anything)) .Return("FluentValidation.Validators.LengthValidator"); _validatorFormatterStub.Stub( stub => stub.Format(Arg <IPropertyValidator> .Matches(c => c.GetType() == typeof(NotEmptyValidator)), Arg <Func <Type, string> > .Is.Anything)) .Return("FluentValidation.Validators.NotEmptyValidator"); _validatorFormatterStub.Stub( stub => stub.Format(Arg <IPropertyValidator> .Matches(c => c.GetType() == typeof(NotEqualValidator)), Arg <Func <Type, string> > .Is.Anything)) .Return("FluentValidation.Validators.NotEqualValidator"); _validatorFormatterStub.Stub( stub => stub.Format(Arg <IPropertyValidator> .Matches(c => c.GetType() == typeof(StubPropertyValidator)), Arg <Func <Type, string> > .Is.Anything)) .Return("Remotion.Validation.UnitTests.TestHelpers.StubPropertyValidator"); var userNamePropertyRule = PropertyRule.Create(userNameExpression); userNamePropertyRule.AddValidator(stubValidator1); userNamePropertyRule.AddValidator(stubValidator1); userNamePropertyRule.AddValidator(stubValidator2); var lastNamePropertyRule = PropertyRule.Create(lastNameExpression); lastNamePropertyRule.AddValidator(stubValidator3); var noPropertyRuleStub = new ValidationRuleStub(); noPropertyRuleStub.AddValidator(stubValidator4); var removingPropertyRuleStub1 = MockRepository.GenerateStub <IRemovingComponentPropertyRule>(); removingPropertyRuleStub1.Stub(stub => stub.CollectorType).Return(typeof(CustomerValidationCollector1)); var removingPropertyRuleStub2 = MockRepository.GenerateStub <IRemovingComponentPropertyRule>(); removingPropertyRuleStub2.Stub(stub => stub.CollectorType).Return(typeof(CustomerValidationCollector2)); var logContextInfo1 = new LogContextInfo( stubValidator2, new[] { new ValidatorRegistrationWithContext(new ValidatorRegistration(typeof(NotEmptyValidator), null), removingPropertyRuleStub1), new ValidatorRegistrationWithContext(new ValidatorRegistration(typeof(NotEmptyValidator), null), removingPropertyRuleStub1), new ValidatorRegistrationWithContext(new ValidatorRegistration(typeof(NotEmptyValidator), null), removingPropertyRuleStub2) }); var logContextInfo2 = new LogContextInfo( stubValidator1, new[] { new ValidatorRegistrationWithContext(new ValidatorRegistration(typeof(NotNullValidator), null), removingPropertyRuleStub2) }); var logContextInfo3 = new LogContextInfo( stubValidator3, new[] { new ValidatorRegistrationWithContext(new ValidatorRegistration(typeof(NotEqualValidator), null), removingPropertyRuleStub1) }); _logContextStub.Stub(stub => stub.GetLogContextInfos(userNamePropertyRule)).Return(new[] { logContextInfo1, logContextInfo2 }); _logContextStub.Stub(stub => stub.GetLogContextInfos(lastNamePropertyRule)).Return(new[] { logContextInfo3 }); _logContextStub.Stub(stub => stub.GetLogContextInfos(noPropertyRuleStub)).Return(new LogContextInfo[0]); var fakeValidationRules = new IValidationRule[] { userNamePropertyRule, lastNamePropertyRule, noPropertyRuleStub }; _wrappedMergerStub.Stub( stub => stub.Merge( validationCollectorInfos)).Return(new ValidationCollectorMergeResult(fakeValidationRules, _logContextStub)); var expectedAfterMerge = "\r\nAFTER MERGE:" + "\r\n\r\n -> Remotion.Validation.UnitTests.TestDomain.Customer#UserName" + "\r\n VALIDATORS:" + "\r\n -> FluentValidation.Validators.NotNullValidator (x2)" + "\r\n -> FluentValidation.Validators.NotEmptyValidator (x1)" + "\r\n MERGE LOG:" + "\r\n -> 'FluentValidation.Validators.NotEmptyValidator' was removed from collectors 'CustomerValidationCollector1, CustomerValidationCollector2'" + "\r\n -> 'FluentValidation.Validators.NotNullValidator' was removed from collector 'CustomerValidationCollector2'" + "\r\n\r\n -> Remotion.Validation.UnitTests.TestDomain.Person#LastName" + "\r\n VALIDATORS:" + "\r\n -> FluentValidation.Validators.NotEqualValidator (x1)" + "\r\n MERGE LOG:" + "\r\n -> 'FluentValidation.Validators.NotEqualValidator' was removed from collector 'CustomerValidationCollector1'" + "\r\n\r\n -> Remotion.Validation.UnitTests.Implementation.ValidationRuleStub" + "\r\n VALIDATORS:" + "\r\n -> Remotion.Validation.UnitTests.TestHelpers.StubPropertyValidator (x1)"; CheckLoggingMethod(() => _diagnosticOutputRuleMergeDecorator.Merge(validationCollectorInfos), expectedAfterMerge, 0); var expectedBeforeMerge = "\r\nBEFORE MERGE:" + "\r\n\r\n-> Remotion.Validation.Providers.ValidationAttributesBasedCollectorProvider#Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseTypeCollector1" + "\r\n\r\n -> Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseType#Property1" + "\r\n ADDED HARD CONSTRAINT VALIDATORS:" + "\r\n -> FluentValidation.Validators.NotNullValidator (x1)" + "\r\n -> FluentValidation.Validators.NotEqualValidator (x1)" + "\r\n\r\n -> Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseType#Property2" + "\r\n ADDED SOFT CONSTRAINT VALIDATORS:" + "\r\n -> FluentValidation.Validators.LengthValidator (x1)" + "\r\n ADDED META VALIDATION RULES:" + "\r\n -> Remotion.Validation.UnitTests.TestDomain.ValidationRules.MaxLengthMetaValidationRule" + "\r\n\r\n-> Remotion.Validation.Providers.ApiBasedComponentValidationCollectorProvider#Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseTypeCollector2" + "\r\n\r\n -> Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseType#Property2" + "\r\n REMOVED VALIDATORS:" + "\r\n -> FluentValidation.Validators.NotEmptyValidator (x1)" + "\r\n -> FluentValidation.Validators.MaximumLengthValidator#Remotion.Validation.UnitTests.Implementation.TestDomain.TypeWithoutBaseTypeCollector1 (x1)"; CheckLoggingMethod(() => _diagnosticOutputRuleMergeDecorator.Merge(validationCollectorInfos), expectedBeforeMerge, 1); }