Esempio n. 1
0
        public void GetNearestSolution_finds_solution_from_solution_path()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\RoslynDom.sln";
            var file = FileSupport.GetNearestSolution(path);

            Assert.IsTrue(file.EndsWith(@"\RoslynDom.sln"));
        }
Esempio n. 2
0
        public void GetNearestSolution_returns_null_for_no_solution()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\..\..";
            var file = FileSupport.GetNearestSolution(path);

            Assert.IsNull(file);
        }
Esempio n. 3
0
        public void Can_get_root_group_from_project()
        {
            var slnFile = FileSupport.GetNearestSolution(Environment.CurrentDirectory);

            var ws = MSBuildWorkspace.Create();
            // For now: wait for the result
            var solution  = ws.OpenSolutionAsync(slnFile).Result;
            var project   = solution.Projects.Where(x => x.Name == "RoslynDomExampleTests").FirstOrDefault();
            var rootGroup = RDom.CSharp.LoadGroup(project);

            Assert.IsNotNull(rootGroup);
            Assert.AreEqual(1, rootGroup.Roots.First().ChildNamespaces.Count());
        }
Esempio n. 4
0
        public void Can_get_root_group_from_project_via_solution()
        {
            var slnFile = FileSupport.GetNearestSolution(Environment.CurrentDirectory);

            var ws = MSBuildWorkspace.Create();
            // For now: wait for the result
            var solution = ws.OpenSolutionAsync(slnFile).Result;
            var project  = solution.Projects.Where(x => x.Name == "RoslynDom").FirstOrDefault();
            // I don't want to test much about the project - because things will change
            //Assert.IsNotNull(project);
            //var trees = new List<SyntaxTree>();
            //foreach (var doc in project.Documents )
            //{
            //   // TODO: consider how async should fit in - not in the test, it belongs deeper in the system
            //   var tree = doc.GetSyntaxTreeAsync().Result;
            //   trees.Add(tree);
            //}

            var compilation     = project.GetCompilationAsync().Result;
            var globalNamespace = compilation.GlobalNamespace;
            var reference       = compilation.GetTypeByMetadataName("RoslynDom.RDomBase");
            var method          = reference.GetMembers().ElementAt(11);
            var span            = method.DeclaringSyntaxReferences.First().Span;
            var tree            = method.DeclaringSyntaxReferences.First().SyntaxTree;
            var syntax          = method.DeclaringSyntaxReferences.First().GetSyntax();


            // var rootGroup = RDom.CSharp.LoadGroup(compilation, trees.ToArray());
            var rootGroup = RDom.CSharp.Load(compilation);

            Assert.IsNotNull(rootGroup);
            var classes = rootGroup.Roots
                          .SelectMany(x => x.RootClasses)
                          .ToList();

            Assert.IsTrue(classes.Count() > 50);
            var type = classes.First().BaseType.Type;

            Assert.IsInstanceOfType(type, typeof(RoslynDom.RDomBase));
        }