示例#1
0
        /// <summary>
        /// Defines a RuleSet that can be used to group together several validators.
        /// </summary>
        /// <param name="ruleSetName">The name of the ruleset.</param>
        /// <param name="action">Action that encapsulates the rules in the ruleset.</param>
        public void RuleSet(string ruleSetName, Action action)
        {
            ruleSetName.Guard("A name must be specified when calling RuleSet.");
            action.Guard("A ruleset definition must be specified when calling RuleSet.");

            using (nestedValidators.OnItemAdded(r => r.RuleSet = ruleSetName)) {
                action();
            }
        }
		public void When_Item_Added_Raises_ItemAdded() {
			string addedItem = null;
			var items = new TrackingCollection<string>();

			using(items.OnItemAdded(x => addedItem = x)) {
				items.Add("foo");
			}

			addedItem.ShouldEqual("foo");
		}
示例#3
0
        public void When_Item_Added_Raises_ItemAdded()
        {
            string addedItem = null;
            var    items     = new TrackingCollection <string>();

            using (items.OnItemAdded(x => addedItem = x)) {
                items.Add("foo");
            }

            addedItem.ShouldEqual("foo");
        }
		public void Should_not_raise_event_once_handler_detached() {
			var addedItems = new List<string>();
			var items = new TrackingCollection<string>();
			
			using(items.OnItemAdded(addedItems.Add)) {
				items.Add("foo");
			}
			items.Add("bar");

			addedItems.Count.ShouldEqual(1);
		}
示例#5
0
        public void Should_not_raise_event_once_handler_detached()
        {
            var addedItems = new List <string>();
            var items      = new TrackingCollection <string>();

            using (items.OnItemAdded(addedItems.Add)) {
                items.Add("foo");
            }
            items.Add("bar");

            addedItems.Count.ShouldEqual(1);
        }
        /// <summary>
        /// Defines a RuleSet that can be used to group together several validators
        /// </summary>
        /// <param name="ruleSetName">The name of the ruleset</param>
        /// <param name="action">Action that encapsulates the rules in the ruleset</param>
        public void RuleSet(
            string ruleSetName,
            Action action)
        {
            ruleSetName.NotNullOrEmpty(nameof(ruleSetName));
            action.NotNull(nameof(action));

            using (_nestedValidators.OnItemAdded(r => r.RuleSet = ruleSetName))
            {
                action();
            }
        }
示例#7
0
        /// <inheritdoc />
        public void When(Func <TValidatedType, bool> predicate, Action action)
        {
            var addedPropertyRules = new List <IAddingComponentPropertyRule>();
            Action <IAddingComponentPropertyRule>   onRuleAdded   = addedPropertyRules.Add;
            Action <IRemovingComponentPropertyRule> onRuleRemoved =
                a => { throw new InvalidOperationException("Conditions are not allowed for removing validation rules registrations."); };

            using (_addedPropertyRules.OnItemAdded(onRuleAdded))
            {
                using (_removedPropertyRules.OnItemAdded(onRuleRemoved))
                {
                    action();
                }
            }

            // Must apply the predictae after the rule has been fully created to ensure any rules-specific conditions have already been applied.
            addedPropertyRules.ForEach(x => x.ApplyCondition(predicate.CoerceToNonGeneric()));
        }