public void CreateSolutionFromClassLibrary1()
            {
                Assert.AreEqual(true, CodeFactory.TryFindProjectFile("ClassLibrary1.csproj", out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new FieldNameMustNotBeginWithUnderscore(), },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual("ClassLibrary1", solution.Projects.Single().Name);
                var expected = new[]
                {
                    "AllowCompilationErrors.cs",
                    "AssemblyInfo.cs",
                    "ClassLibrary1Class1.cs",
                };
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
            public void CreateSolutionFromProjectFile()
            {
                Assert.AreEqual(true, CodeFactory.TryFindProjectFile(ExecutingAssemblyDll, out var projectFile));
                var solution = CodeFactory.CreateSolution(
                    projectFile,
                    new[] { new FieldNameMustNotBeginWithUnderscore(), },
                    CreateMetadataReferences(typeof(object)));

                Assert.AreEqual(Path.GetFileNameWithoutExtension(ExecutingAssemblyDll.FullName), solution.Projects.Single().Name);
                var expected = projectFile.Directory
                               .EnumerateFiles("*.cs", SearchOption.AllDirectories)
                               .Where(f => !f.DirectoryName.Contains("bin"))
                               .Where(f => !f.DirectoryName.Contains("obj"))
                               .Select(f => f.Name)
                               .OrderBy(x => x)
                               .ToArray();
                var actual = solution.Projects
                             .SelectMany(p => p.Documents)
                             .Select(d => d.Name)
                             .OrderBy(x => x)
                             .ToArray();
                //// ReSharper disable UnusedVariable for debug.
                var expectedString = string.Join(Environment.NewLine, expected);
                var actualString   = string.Join(Environment.NewLine, actual);

                //// ReSharper restore UnusedVariable
                CollectionAssert.AreEqual(expected, actual);
            }
Beispiel #3
0
 public void TryFindProjectFileFromName(string name)
 {
     Assert.AreEqual(true, CodeFactory.TryFindProjectFile(name, out var projectFile));
     Assert.AreEqual(name, projectFile.Name);
     projectFile = CodeFactory.FindProjectFile(name);
     Assert.AreEqual(name, projectFile.Name);
 }
Beispiel #4
0
 public void ProjectFileNoErrorAnalyzer()
 {
     Assert.AreEqual(true, CodeFactory.TryFindProjectFile("Gu.Roslyn.Asserts.csproj", out var csproj));
     AnalyzerAssert.Valid <NoErrorAnalyzer>(csproj);
     AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), csproj);
     AnalyzerAssert.Valid(new NoErrorAnalyzer(), csproj);
 }
Beispiel #5
0
        public async Task AnalyzeProjectFile()
        {
            Assert.AreEqual(true, CodeFactory.TryFindProjectFile("Gu.Roslyn.Asserts.csproj", out FileInfo projectFile));
            var diagnostics = await Analyze.GetDiagnosticsAsync(new FieldNameMustNotBeginWithUnderscore(), projectFile, MetadataReferences)
                              .ConfigureAwait(false);

            CollectionAssert.IsEmpty(diagnostics.SelectMany(x => x));
        }
Beispiel #6
0
 public void TryFindProjectFileFromDll()
 {
     Assert.AreEqual(true, CodeFactory.TryFindProjectFile(ExecutingAssemblyDll, out var projectFile));
     Assert.AreEqual(Path.GetFileNameWithoutExtension(ExecutingAssemblyDll.FullName) + ".csproj", projectFile.Name);
 }