Пример #1
0
 /// <summary>
 /// Ignore.
 /// </summary>
 public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
 {
     return(new DefaultRuleProvider()
            .GetRules(connection, level)
            .Take(RuleCount)
            .ToList());
 }
Пример #2
0
        void Expect(RuleLevel level, IEnumerable <TTarget> testCases)
        {
            foreach (var testCase in testCases)
            {
                var messages = Scope.GetMessages(testCase, "testCase", _rules);

                if (level != messages.Level)
                {
                    var builder = new StringBuilder();
                    builder.AppendFormat("Expected '{0}', but got '{1}'.{2}", level, messages.Level, Environment.NewLine);

                    builder.AppendFormat("Value: {0}{1}", testCase, Environment.NewLine);

                    if (messages.Count > 0)
                    {
                        builder.Append("Messages:");
                        foreach (var message in messages)
                        {
                            builder.AppendLine().Append(message);
                        }
                    }
                    throw new RuleException(builder.ToString(), "rule");
                }
            }
        }
Пример #3
0
        void IScope.Write(RuleLevel level, string message)
        {
            if (level > _level)
                _level = level;

            _log.Log(MatchLevel(level), message);
        }
        void IScope.Write(RuleLevel level, string message)
        {
            if (level > _level)
                _level = level;

            _messenger(GetName, level, message);
        }
Пример #5
0
        public static void Ctor_GivenNullOrWhiteSpaceMessage_ThrowsArgumentNullException(string message)
        {
            const string    ruleId = "TEST_ID";
            const string    title  = "title";
            const RuleLevel level  = RuleLevel.Error;

            Assert.That(() => new RuleMessage(ruleId, title, level, message), Throws.ArgumentNullException);
        }
 IScope IScope.Create(string name)
 {
     return new DelayedScope(() => Scope.ComposePathInternal(GetName(), name), _messenger, level =>
         {
             if (level > _level)
                 _level = level;
         });
 }
 IScope IScope.Create(string name)
 {
     return new TrackScope(level =>
         {
             if (level > _level)
                 _level = level;
         });
 }
Пример #8
0
        public static void Ctor_GivenInvalidRuleLevel_ThrowsArgumentException()
        {
            const string    id    = "TEST_ID";
            const string    title = "test";
            const RuleLevel level = (RuleLevel)999;

            Assert.That(() => new FakeRule(id, title, level), Throws.ArgumentException);
        }
Пример #9
0
 IScope IScope.Create(string name)
 {
     return new LogScope(Scope.ComposePath(_name, name), _logProvider, level =>
         {
             if (level > _level)
                 _level = level;
         });
 }
Пример #10
0
        public static void Level_PropertyGet_MatchesCtorArg()
        {
            const string    id    = "TEST_ID";
            const string    title = "test";
            const RuleLevel level = RuleLevel.Error;
            var             rule  = new FakeRule(id, title, level);

            Assert.That(rule.Level, Is.EqualTo(level));
        }
Пример #11
0
        public static void Ctor_GivenInvalidRuleLevel_ThrowsArgumentException()
        {
            const string    ruleId  = "TEST_ID";
            const string    title   = "title";
            const RuleLevel level   = (RuleLevel)999;
            const string    message = "message";

            Assert.That(() => new RuleMessage(ruleId, title, level, message), Throws.ArgumentException);
        }
Пример #12
0
 IScope IScope.Create(string name)
 {
     return(new DelayedScope(() => Scope.ComposePathInternal(GetName(), name), _messenger, level =>
     {
         if (level > _level)
         {
             _level = level;
         }
     }));
 }
Пример #13
0
        public static void Message_PropertyGet_MatchesCtorArg()
        {
            const string    ruleId  = "TEST_ID";
            const string    title   = "title";
            const RuleLevel level   = RuleLevel.Error;
            const string    message = "message";

            var ruleMessage = new RuleMessage(ruleId, title, level, message);

            Assert.That(ruleMessage.Message, Is.EqualTo(message));
        }
Пример #14
0
        /// <summary>
        /// Retrieves an empty set of rules used for reporting.
        /// </summary>
        /// <param name="connection">A schematic connection.</param>
        /// <param name="level">The level used for reporting.</param>
        /// <returns>An empty set of rules.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="connection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="level"/> does not have a valid enum value.</exception>
        public IEnumerable <IRule> GetRules(ISchematicConnection connection, RuleLevel level)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (!level.IsValid())
            {
                throw new ArgumentException($"The { nameof(RuleLevel) } provided must be a valid enum.", nameof(level));
            }

            return(Array.Empty <IRule>());
        }
 public static void Raise(IScope scope, RuleLevel ruleLevel, string message)
 {
     switch (ruleLevel)
     {
         case RuleLevel.None:
             scope.Write(RuleLevel.Warn, message);
             break;
         case RuleLevel.Warn:
         case RuleLevel.Error:
             scope.Write(RuleLevel.Error, message);
             break;
         default:
             throw new ArgumentOutOfRangeException("level");
     }
 }
 void IScope.Write(RuleLevel level, string message)
 {
     _modifier(_inner, level, message);
 }
 IScope IScope.Create(string name)
 {
     return new SimpleScope(Scope.ComposePathInternal(_name, name), _messenger, level =>
         {
             if (level > _level)
                 _level = level;
         });
 }
Пример #18
0
 static LogLevel MatchLevel(RuleLevel level)
 {
     switch (level)
     {
         case RuleLevel.None:
             return LogLevel.Info;
         case RuleLevel.Warn:
             return LogLevel.Warn;
         case RuleLevel.Error:
             return LogLevel.Error;
         default:
             throw new ArgumentOutOfRangeException("level");
     }
 }
 void IScope.Write(RuleLevel level, string message)
 {
     if (level > _level)
         _level = level;
 }
Пример #20
0
		/// <summary>
		/// Validates the specified domain object, ignoring any rules that do not satisfy the filter.
		/// </summary>
		/// <param name="obj"></param>
		/// <param name="level"></param>
		/// <param name="ruleFilter"></param>
		/// <exception cref="EntityValidationException">Validation failed.</exception>
		private void Validate(DomainObject obj, RuleLevel level, Predicate<ISpecification> ruleFilter)
		{
			var domainClass = obj.GetClass();

			var ruleSets = new List<ISpecification>();

			if (CheckLevel(level, RuleLevel.Low))
			{
				// first check for a cached rule-set
				ValidationRuleSet lowLevelRules;
				if (!_lowLevelRuleSets.TryGetValue(domainClass, out lowLevelRules))
				{
					// otherwise build it
					lowLevelRules = IsValidationEnabled(domainClass) ?
						ValidationRuleSetCache.GetLowLevelRules(domainClass)
						: new ValidationRuleSet();

					// cache for future use
					_lowLevelRuleSets.Add(domainClass, lowLevelRules);
				}
				ruleSets.Add(lowLevelRules);
			}

			if (CheckLevel(level, RuleLevel.High))
			{
				// first check for a cached rule-set
				ValidationRuleSet highLevelRules;
				if (!_highLevelRuleSets.TryGetValue(domainClass, out highLevelRules))
				{
					// otherwise build it
						highLevelRules = IsValidationEnabled(domainClass) ?
							ValidationRuleSetCache.GetHighLevelRules(domainClass)
						: new ValidationRuleSet();

						// cache for future use
						_highLevelRuleSets.Add(domainClass, highLevelRules);
					}
					ruleSets.Add(highLevelRules);
				}

			var rules = new ValidationRuleSet(ruleSets);
			var result = rules.Test(obj, ruleFilter);
			if (result.Fail)
			{
				var message = string.Format(SR.ExceptionInvalidEntity, TerminologyTranslator.Translate(obj.GetClass()));
				throw new EntityValidationException(message, result.Reasons);
			}
		}
Пример #21
0
		private static bool CheckLevel(RuleLevel level, RuleLevel refLevel)
		{
			return (level & refLevel) == refLevel;
		}