Inheritance: IModelNode
			public async Task WhenTreeDoesNotContainBranchThenIsNotPassed()
			{
				var rule = new BranchModelRule(new ModelNode("cheese", "type", CodeQuality.Good, 0, 0, 0));
				var tree = new ModelNode("node", "type", CodeQuality.Good, 0, 0, 0, new[] { new ModelNode("child", "type", CodeQuality.Good, 0, 0, 0, new[] { new ModelNode("leaf", "type", CodeQuality.Good, 0, 0, 0) }) });

				var result = await rule.Validate(tree);

				Assert.IsFalse(result.Any(x => x.Passed));
			}
			public async Task WhenTreeContainsComplexBranchThenIsPassed()
			{
				var rule = new BranchModelRule(new ModelNode("child", "type", CodeQuality.Good, 0, 0, 0, new[] { new ModelNode("leaf", "type", CodeQuality.Good, 0, 0, 0) }));
				var tree = new ModelNode("node", "type", CodeQuality.Good, 0, 0, 0, new[] { new ModelNode("child", "type", CodeQuality.Good, 0, 0, 0, new[] { new ModelNode("leaf", "type", CodeQuality.Good, 0, 0, 0) }) });

				var result = await rule.Validate(tree);

				Assert.IsTrue(result.All(x => x.Passed));
			}
            public async Task WhenTransformingThenAlsoTransformsChildren()
            {
                var rule = new TransformRule("Test", "[xyz]");
                var node = new ModelNode("a", "type", CodeQuality.Good, 3, 2, 1, new List<IModelNode> { new ModelNode("x", "type", CodeQuality.Good, 6, 5, 4) });

                var transformed = await _transformer.Transform(new[] { node }, new[] { rule }, CancellationToken.None);

                Assert.Equal("Test", transformed.First().Children.First().DisplayName);
            }
			public async Task WhenTransformingThenTransformsDisplayName()
			{
				var rule = new TransformRule("Test", "[xyz]");
				var node = new ModelNode("x", "type", CodeQuality.Good, 3, 2, 1);

				var transformed = await _transformer.Transform(new[] { node }, new[] { rule }, CancellationToken.None);

				Assert.AreEqual("Test", transformed.First().DisplayName);
			}
Esempio n. 5
0
		public async Task<IEnumerable<IValidationResult>> Validate(string solutionPath, IEnumerable<IModelRule> rules, IEnumerable<TransformRule> transformRules, CancellationToken cancellationToken)
		{
			var model = await _repository.GetVertices(solutionPath, cancellationToken).ConfigureAwait(false);
			var transformed = await _syntaxTransformer.Transform(model, transformRules, cancellationToken).ConfigureAwait(false);
			var modelTree = new ModelNode("All", NodeKind.Solution, CodeQuality.Good, 0, 0, 0, transformed.ToList());
			var tasks = rules.Select(r => r.Validate(modelTree));
			var results = await Task.WhenAll(tasks).ConfigureAwait(false);

			return results.SelectMany(x => x).AsArray();
		}
Esempio n. 6
0
			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());
			}