ArchiMetrics.Analysis.Validation.KpiModelRule.Validate C# (CSharp) Method

Validate() public method

public Validate ( IModelNode modelTree ) : Task>
modelTree IModelNode
return Task>
		public Task<IEnumerable<IValidationResult>> Validate(IModelNode modelTree)
		{
			return
				Task.Factory.StartNew(
					() => modelTree.Children.SelectMany(x => x.Flatten())
							  .Where(x => x.Type == NodeKind.Class)
							  .Where(x => x.CyclomaticComplexity > _cyclomaticComplexity || x.MaintainabilityIndex < _maintainabilityIndex || x.LinesOfCode > _linesOfCode)
							  .Select(x => new KpiResult(false, x))
							  .Cast<IValidationResult>()
							  .AsArray()
							  .AsEnumerable());
		}
	}

Usage Example

			public async Task WhenTreeContainsUnmaintainableNodeThenIsNotPassed()
			{
				var rule = new KpiModelRule();
				var tree = new ModelNode(
					"tree", 
					NodeKind.Namespace, 
					CodeQuality.Good, 
					50, 
					30, 
					30, 
					new[] { new ModelNode("class", NodeKind.Class, CodeQuality.Good, 10, 20, 1) });

				var result = await rule.Validate(tree);

				Assert.AreEqual(1, result.Count());
			}