public void TestOpenCloseAdditionalDocument() { var pid = ProjectId.CreateNewId(); var text = SourceText.From("public class C { }"); var version = VersionStamp.Create(); var docInfo = DocumentInfo.Create(DocumentId.CreateNewId(pid), "c.cs", loader: TextLoader.From(TextAndVersion.Create(text, version))); var projInfo = ProjectInfo.Create( pid, version: VersionStamp.Default, name: "TestProject", assemblyName: "TestProject.dll", language: LanguageNames.CSharp, additionalDocuments: new[] { docInfo }); using (var ws = new AdhocWorkspace()) { ws.AddProject(projInfo); var doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(false, doc.TryGetText(out var currentText)); ws.OpenAdditionalDocument(docInfo.Id); doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(true, doc.TryGetText(out currentText)); Assert.Equal(true, doc.TryGetTextVersion(out var currentVersion)); Assert.Same(text, currentText); Assert.Equal(version, currentVersion); ws.CloseAdditionalDocument(docInfo.Id); doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(false, doc.TryGetText(out currentText)); } }
public void TestOpenCloseAdditionalDocument() { var pid = ProjectId.CreateNewId(); var text = SourceText.From("public class C { }"); var version = VersionStamp.Create(); var docInfo = DocumentInfo.Create(DocumentId.CreateNewId(pid), "c.cs", loader: TextLoader.From(TextAndVersion.Create(text, version))); var projInfo = ProjectInfo.Create( pid, version: VersionStamp.Default, name: "TestProject", assemblyName: "TestProject.dll", language: LanguageNames.CSharp, additionalDocuments: new[] { docInfo }); using (var ws = new AdhocWorkspace()) { ws.AddProject(projInfo); SourceText currentText; VersionStamp currentVersion; var doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(false, doc.TryGetText(out currentText)); ws.OpenAdditionalDocument(docInfo.Id); doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(true, doc.TryGetText(out currentText)); Assert.Equal(true, doc.TryGetTextVersion(out currentVersion)); Assert.Same(text, currentText); Assert.Equal(version, currentVersion); ws.CloseAdditionalDocument(docInfo.Id); doc = ws.CurrentSolution.GetAdditionalDocument(docInfo.Id); Assert.Equal(false, doc.TryGetText(out currentText)); } }