Beispiel #1
0
        public void TestOpenCloseAnnalyzerConfigDocument()
        {
            var pid     = ProjectId.CreateNewId();
            var text    = SourceText.From("public class C { }");
            var version = VersionStamp.Create();
            var analyzerConfigDocFilePath = PathUtilities.CombineAbsoluteAndRelativePaths(
                Temp.CreateDirectory().Path,
                ".editorconfig"
                );
            var docInfo = DocumentInfo.Create(
                DocumentId.CreateNewId(pid),
                name: ".editorconfig",
                loader: TextLoader.From(
                    TextAndVersion.Create(text, version, analyzerConfigDocFilePath)
                    ),
                filePath: analyzerConfigDocFilePath
                );
            var projInfo = ProjectInfo
                           .Create(
                pid,
                version: VersionStamp.Default,
                name: "TestProject",
                assemblyName: "TestProject.dll",
                language: LanguageNames.CSharp
                )
                           .WithAnalyzerConfigDocuments(new[] { docInfo });

            using (var ws = new AdhocWorkspace())
            {
                ws.AddProject(projInfo);
                var doc = ws.CurrentSolution.GetAnalyzerConfigDocument(docInfo.Id);
                Assert.False(doc.TryGetText(out var currentText));

                ws.OpenAnalyzerConfigDocument(docInfo.Id);

                doc = ws.CurrentSolution.GetAnalyzerConfigDocument(docInfo.Id);
                Assert.True(doc.TryGetText(out currentText));
                Assert.True(doc.TryGetTextVersion(out var currentVersion));
                Assert.Same(text, currentText);
                Assert.Equal(version, currentVersion);

                ws.CloseAnalyzerConfigDocument(docInfo.Id);

                doc = ws.CurrentSolution.GetAnalyzerConfigDocument(docInfo.Id);
                Assert.False(doc.TryGetText(out currentText));
            }
        }