public void MethodHasExpectedComplexity(string method, int expectedComplexity)
            {
                var tree        = CSharpSyntaxTree.ParseText(method);
                var compilation = CSharpCompilation.Create(
                    "x",
                    syntaxTrees: new[] { tree },
                    references:
                    new MetadataReference[]
                {
                    MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
                    MetadataReference.CreateFromFile(typeof(Task).Assembly.Location)
                });
                //options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, false, null, null, null, new string[] { "System", "System.Threading.Tasks" }));

                var model      = compilation.GetSemanticModel(tree, true);
                var syntaxNode = tree
                                 .GetRoot()
                                 .DescendantNodes()
                                 .OfType <MethodDeclarationSyntax>()
                                 .First();

                var metrics = new m.Metrics();
                var timer   = metrics.Timer(
                    typeof(ProjectMetricTests),
                    "TestTimer",
                    m.TimeUnit.Milliseconds,
                    m.TimeUnit.Microseconds);

                var result = timer.Time(() => _counter.Calculate(syntaxNode, model));

                Assert.Equal(expectedComplexity, result);
            }
		public async Task MeasureProjectAnalysisPerformance()
		{
			using (var workspace = MSBuildWorkspace.Create())
			{
				var path = @"..\..\..\ArchiMetrics.Common\ArchiMetrics.Common.csproj".GetLowerCaseFullPath();
				var project = await workspace.OpenProjectAsync(path).ConfigureAwait(false);
				var metrics = new metrics.Metrics();
				var timer = metrics.Timer(GetType(), "test", TimeUnit.Seconds, TimeUnit.Seconds);
				for (var i = 0; i < 5; i++)
				{
					var amount = timer.Time(() => PerformReview(project).Result);
				}

				Assert.Less(timer.Mean, 90.0);
			}
		}
        public async Task MeasureSolutionAnalysisPerformance()
        {
            using (var workspace = MSBuildWorkspace.Create())
            {
                var path = @"..\..\..\..\archimetrics.sln".GetLowerCaseFullPath();
                var solution = await workspace.OpenSolutionAsync(path).ConfigureAwait(false);
                var metrics = new metrics.Metrics();
                var timer = metrics.Timer(GetType(), "test", TimeUnit.Seconds, TimeUnit.Seconds);
                for (var i = 0; i < 5; i++)
                {
                    var amount = timer.Time(() => PerformReview(solution).Result);
                }

                Assert.True(timer.Mean < 90.0);
            }
        }
Exemplo n.º 4
0
        public async Task MeasureProjectAnalysisPerformance()
        {
            using (var workspace = MSBuildWorkspace.Create())
            {
                var path    = @"..\..\..\..\src\ArchiMetrics.Analysis\ArchiMetrics.Analysis.csproj".GetLowerCaseFullPath();
                var project = await workspace.OpenProjectAsync(path).ConfigureAwait(false);

                var metrics = new metrics.Metrics();
                var timer   = metrics.Timer(GetType(), "test", TimeUnit.Seconds, TimeUnit.Seconds);
                for (var i = 0; i < 5; i++)
                {
                    var amount = timer.Time(() => PerformReview(project).Result);
                }

                Assert.True(timer.Mean < 90.0);
            }
        }
        public async Task MeasureSolutionAnalysisPerformance()
        {
            using (var workspace = MSBuildWorkspace.Create())
            {
                var path     = @"..\..\..\archimetrics.sln".GetLowerCaseFullPath();
                var solution = await workspace.OpenSolutionAsync(path).ConfigureAwait(false);

                var metrics = new metrics.Metrics();
                var timer   = metrics.Timer(GetType(), "test", TimeUnit.Seconds, TimeUnit.Seconds);
                for (var i = 0; i < 5; i++)
                {
                    var amount = timer.Time(() => PerformReview(solution).Result);
                }

                Assert.Less(timer.Mean, 90.0);
            }
        }
            public void MethodHasExpectedComplexity(string method, int expectedComplexity)
            {
                var tree = CSharpSyntaxTree.ParseText(method);
                var compilation = CSharpCompilation.Create(
                    "x",
                    syntaxTrees: new[] { tree },
                    references: new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), MetadataReference.CreateFromFile(typeof(Task).Assembly.Location) },
                    options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, usings: new[] { "System", "System.Threading.Tasks" }));

                var model = compilation.GetSemanticModel(tree, true);
                var syntaxNode = tree
                    .GetRoot()
                    .DescendantNodes()
                    .OfType<MethodDeclarationSyntax>()
                    .First();

                var metrics = new m.Metrics();
                var timer = metrics.Timer(
                    typeof(ProjectMetricTests),
                    "TestTimer",
                    m.TimeUnit.Milliseconds,
                    m.TimeUnit.Microseconds);

                var result = timer.Time(() => _counter.Calculate(syntaxNode, model));

                Assert.Equal(expectedComplexity, result);
            }