Пример #1
0
        public void TestChangeDocumentFilePath_TryApplyChanges_Throws()
        {
            using (var ws = new NoChangesAllowedWorkspace())
            {
                var projectId = ws.AddProject("TestProject", LanguageNames.CSharp).Id;

                var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
                Assert.Null(originalDoc.FilePath);

                var newPath    = @"\foo\TestDocument.cs";
                var changedDoc = originalDoc.WithFilePath(newPath);
                Assert.Equal(newPath, changedDoc.FilePath);

                NotSupportedException e = null;
                try
                {
                    ws.TryApplyChanges(changedDoc.Project.Solution);
                }
                catch (NotSupportedException x)
                {
                    e = x;
                }

                Assert.NotNull(e);
                Assert.Equal(WorkspacesResources.Changing_document_property_is_not_supported, e.Message);
            }
        }
Пример #2
0
        public void TestChangeDocumentSourceCodeKind_TryApplyChanges_Throws()
        {
            using (var ws = new NoChangesAllowedWorkspace())
            {
                var projectId = ws.AddProject("TestProject", LanguageNames.CSharp).Id;

                var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
                Assert.Equal(SourceCodeKind.Regular, originalDoc.SourceCodeKind);

                var changedDoc = originalDoc.WithSourceCodeKind(SourceCodeKind.Script);
                Assert.Equal(SourceCodeKind.Script, changedDoc.SourceCodeKind);

                NotSupportedException e = null;
                try
                {
                    ws.TryApplyChanges(changedDoc.Project.Solution);
                }
                catch (NotSupportedException x)
                {
                    e = x;
                }

                Assert.NotNull(e);
                Assert.Equal(WorkspacesResources.Changing_document_property_is_not_supported, e.Message);
            }
        }
Пример #3
0
        public void TestChangeDocumentFolders_TryApplyChanges_Throws()
        {
            using (var ws = new NoChangesAllowedWorkspace())
            {
                var projectId   = ws.AddProject("TestProject", LanguageNames.CSharp).Id;
                var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));

                Assert.Equal(0, originalDoc.Folders.Count);

                var changedDoc = originalDoc.WithFolders(new[] { "A", "B" });
                Assert.Equal(2, changedDoc.Folders.Count);
                Assert.Equal("A", changedDoc.Folders[0]);
                Assert.Equal("B", changedDoc.Folders[1]);

                NotSupportedException e = null;
                try
                {
                    ws.TryApplyChanges(changedDoc.Project.Solution);
                }
                catch (NotSupportedException x)
                {
                    e = x;
                }

                Assert.NotNull(e);
                Assert.Equal(WorkspacesResources.Changing_document_property_is_not_supported, e.Message);
            }
        }
Пример #4
0
        public void TestChangeDocumentContent_TryApplyChanges_Throws()
        {
            using var ws = new NoChangesAllowedWorkspace();
            var projectId   = ws.AddProject("TestProject", LanguageNames.CSharp).Id;
            var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));

            var changedDoc = originalDoc.WithText(SourceText.From("new"));

            NotSupportedException e = null;

            try
            {
                ws.TryApplyChanges(changedDoc.Project.Solution);
            }
            catch (NotSupportedException x)
            {
                e = x;
            }

            Assert.NotNull(e);
            Assert.Equal(WorkspacesResources.Changing_documents_is_not_supported, e.Message);
        }