Skip to content

Commit 6e4acc3

Browse files
Merge pull request #4 from vladbatushkov/alpha4
Add initial Testing projects
2 parents bd8088b + ba8ef34 commit 6e4acc3

13 files changed

Lines changed: 175 additions & 24 deletions

File tree

Strazh/Analysis/Analyzer.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,37 @@ public static async Task Analyze(AnalyzerConfig config)
3030
Console.WriteLine($"Analyzer ready to analyze {projectAnalyzers.Count()} project/s.");
3131

3232
var workspace = new AdhocWorkspace();
33-
var isDelete = config.IsDelete;
34-
short index = 1;
35-
foreach (var projectAnalyzer in projectAnalyzers)
33+
var projects = new List<(Project, IProjectAnalyzer)>();
34+
35+
var sortedProjectAnalyzers = projectAnalyzers; // TODO sort
36+
37+
foreach (var projectAnalyzer in sortedProjectAnalyzers)
3638
{
37-
var triples = await AnalyzeProject(index, workspace, projectAnalyzer, config.Tier);
38-
if (triples.Count > 0)
39-
{
40-
await DbManager.InsertData(triples, config.Credentials, isDelete);
41-
}
42-
index++;
43-
isDelete = false;
39+
var project = projectAnalyzer.AddToWorkspace(workspace);
40+
projects.Add((project, projectAnalyzer));
41+
}
42+
for (var index = 0; index < projects.Count; index++)
43+
{
44+
var triples = await AnalyzeProject(index + 1, projects[index], config.Tier);
45+
triples = triples.GroupBy(x => x.ToString()).Select(x => x.First()).OrderBy(x => x.NodeA.Label).ToList();
46+
await DbManager.InsertData(triples, config.Credentials, config.IsDelete && index == 0);
4447
}
4548
workspace.Dispose();
4649
}
4750

48-
private static async Task<IList<Triple>> AnalyzeProject(short index, AdhocWorkspace workspace, IProjectAnalyzer projectAnalyzer, Tiers mode)
51+
private static async Task<IList<Triple>> AnalyzeProject(int index, (Project project, IProjectAnalyzer projectAnalyzer) item, Tiers mode)
4952
{
5053
Console.WriteLine($"Project #{index}:");
51-
var project = projectAnalyzer.AddToWorkspace(workspace);
52-
var root = GetRoot(project.FilePath);
54+
var root = GetRoot(item.project.FilePath);
5355
var rootNode = new FolderNode(root, root);
54-
var projectName = GetProjectName(project.Name);
56+
var projectName = GetProjectName(item.project.Name);
5557
Console.WriteLine($"Analyzing {projectName} project...");
5658

5759
var triples = new List<Triple>();
5860
if (mode == Tiers.All || mode == Tiers.Project)
5961
{
6062
Console.WriteLine($"Analyzing Project tier...");
61-
var projectBuild = projectAnalyzer.Build().FirstOrDefault();
63+
var projectBuild = item.projectAnalyzer.Build().FirstOrDefault();
6264
var projectNode = new ProjectNode(projectName);
6365
triples.Add(new TripleIncludedIn(projectNode, rootNode));
6466
projectBuild.ProjectReferences.ToList().ForEach(x =>
@@ -75,20 +77,19 @@ private static async Task<IList<Triple>> AnalyzeProject(short index, AdhocWorksp
7577
Console.WriteLine($"Analyzing Project tier complete.");
7678
}
7779

78-
if (project.SupportsCompilation
80+
if (item.project.SupportsCompilation
7981
&& (mode == Tiers.All || mode == Tiers.Code))
8082
{
8183
Console.WriteLine($"Analyzing Code tier...");
82-
var compilation = await project.GetCompilationAsync();
83-
var syntaxTreeRoot = compilation.SyntaxTrees;
84+
var compilation = await item.project.GetCompilationAsync();
85+
var syntaxTreeRoot = compilation.SyntaxTrees.Where(x => !x.FilePath.Contains("obj"));
8486
foreach (var st in syntaxTreeRoot)
8587
{
8688
var sem = compilation.GetSemanticModel(st);
87-
Extractor.AnalyzeTree<ClassDeclarationSyntax>(triples, st, sem, rootNode);
8889
Extractor.AnalyzeTree<InterfaceDeclarationSyntax>(triples, st, sem, rootNode);
90+
Extractor.AnalyzeTree<ClassDeclarationSyntax>(triples, st, sem, rootNode);
8991
}
9092
Console.WriteLine($"Analyzing Code tier complete.");
91-
triples = triples.GroupBy(x => x.ToString()).Select(x => x.First()).ToList();
9293
}
9394

9495
Console.WriteLine($"Analyzing {projectName} project complete.");

Strazh/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Strazh": {
44
"commandName": "Project",
5-
"commandLineArgs": "-c \"neo4j:neo4j:strazh\" -p \"C:\\src\\agoda-front-end\\cronos\\framework\\src\\Agoda.Cronos.Bootstrap\\Agoda.Cronos.Bootstrap.csproj\" \"C:\\src\\agoda-front-end\\cronos\\framework\\src\\Tests\\Agoda.Cronos.BootstrapUnitTests\\Agoda.Cronos.BootstrapUnitTests.csproj\""
5+
"commandLineArgs": "-c \"neo4j:neo4j:strazh\" -p \"C:\\src\\github\\strazh\\SystemUnderTest\\Strazh.Tests.ProjectB\\Strazh.Tests.ProjectB.csproj\" \"C:\\src\\github\\strazh\\SystemUnderTest\\Strazh.Tests.ProjectA\\Strazh.Tests.ProjectA.csproj\""
66
}
77
}
88
}

Strazh/Strazh.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1111
..\Dockerfile = ..\Dockerfile
1212
EndProjectSection
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strazh.Tests.ProjectA", "..\SystemUnderTest\Strazh.Tests.ProjectA\Strazh.Tests.ProjectA.csproj", "{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strazh.Tests.ProjectB", "..\SystemUnderTest\Strazh.Tests.ProjectB\Strazh.Tests.ProjectB.csproj", "{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{EF685B52-D0F9-4350-9956-90CF2DE13610}"
19+
EndProject
1420
Global
1521
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1622
Debug|Any CPU = Debug|Any CPU
@@ -21,10 +27,22 @@ Global
2127
{1C92D6A7-867F-42CC-933B-DB78249BA75B}.Debug|Any CPU.Build.0 = Debug|Any CPU
2228
{1C92D6A7-867F-42CC-933B-DB78249BA75B}.Release|Any CPU.ActiveCfg = Release|Any CPU
2329
{1C92D6A7-867F-42CC-933B-DB78249BA75B}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC}.Release|Any CPU.Build.0 = Release|Any CPU
2438
EndGlobalSection
2539
GlobalSection(SolutionProperties) = preSolution
2640
HideSolutionNode = FALSE
2741
EndGlobalSection
42+
GlobalSection(NestedProjects) = preSolution
43+
{CBE72A8F-DDA9-45DC-987B-B55FA9A3EC2C} = {EF685B52-D0F9-4350-9956-90CF2DE13610}
44+
{D8AEF0F8-1FC1-4CAF-AC35-C62D29A83ABC} = {EF685B52-D0F9-4350-9956-90CF2DE13610}
45+
EndGlobalSection
2846
GlobalSection(ExtensibilityGlobals) = postSolution
2947
SolutionGuid = {2B976F72-0E21-452F-9EAE-868AEEF480D8}
3048
EndGlobalSection
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Strazh.Tests.ProjectB.Math;
2+
using System;
3+
4+
namespace Strazh.Tests.ProjectA
5+
{
6+
public class MathConsumer
7+
{
8+
public readonly IMathService _mathService;
9+
10+
public MathConsumer(IMathService mathService)
11+
{
12+
_mathService = mathService;
13+
}
14+
15+
public int SumOfSum(int a, int b, int c)
16+
{
17+
var sumAb = _mathService.Sum(a, b);
18+
var sumBc = _mathService.Sum(b, c);
19+
var sumAc = _mathService.Sum(a, c);
20+
return _mathService.Sum(sumAb, sumBc, sumAc);
21+
}
22+
23+
public int SumOfStrings(string str1, string str2)
24+
{
25+
return _mathService.Sum(_mathService.Sum(0, str1), str2);
26+
}
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\Strazh.Tests.ProjectB\Strazh.Tests.ProjectB.csproj" />
9+
</ItemGroup>
10+
11+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Strazh.Tests.ProjectB.Math
2+
{
3+
public interface IMathService
4+
{
5+
public int Sum(int a, string b);
6+
7+
public int Sum(int a, int b);
8+
9+
public int Sum(int a, int b, int c);
10+
}
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Strazh.Tests.ProjectB.Math
2+
{
3+
public class MathService : IMathService
4+
{
5+
public int Sum(int a, string b)
6+
{
7+
return Sum(a, int.TryParse(b, out var x) ? x : 0);
8+
}
9+
10+
public int Sum(int a, int b)
11+
{
12+
return a + b;
13+
}
14+
15+
public int Sum(int a, int b, int c)
16+
{
17+
return Sum(Sum(a, b), c);
18+
}
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Strazh.Tests.ProjectB.Root.Left.Left
6+
{
7+
public class Leaf1
8+
{
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Strazh.Tests.ProjectB.Root.Left.Right
6+
{
7+
public class Leaf2 {
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Strazh.Tests.ProjectB.Root.Right.Left
6+
{
7+
public class Leaf3
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)