Esempio n. 1
0
        public void TryApplyWorksThrowsIfChangeIsDisallowedForParseOption()
        {
            // If we don't support the main change kind, then the other method should be called
            using var workspace = new CustomizedCanApplyWorkspace(
                      allowedKinds: new ApplyChangesKind[] { },
                      canApplyParseOptions: (_, newParseOptions) =>
                      newParseOptions.Features["Feature"] == "ExpectedValue"
                      );

            var project = workspace.CurrentSolution.Projects.Single();

            var exception = Assert.Throws <NotSupportedException>(
                () =>
                workspace.TryApplyChanges(
                    project.WithParseOptions(
                        project.ParseOptions !.WithFeatures(
                            new[] { KeyValuePairUtil.Create("Feature", "WrongThing") }
                            )
                        ).Solution
                    )
                );

            Assert.Equal(
                WorkspacesResources.Changing_parse_options_is_not_supported,
                exception.Message
                );
        }
Esempio n. 2
0
        public void TryApplyWorksThrowsIfChangeIsDisallowedForCompilationOption()
        {
            // If we don't support the main change kind, then the other method should be called
            using var workspace = new CustomizedCanApplyWorkspace(
                      allowedKinds: new ApplyChangesKind[] { },
                      canApplyCompilationOptions: (_, newCompilationOptions) =>
                      newCompilationOptions.MainTypeName == "Expected"
                      );

            var project = workspace.CurrentSolution.Projects.Single();

            var exception = Assert.Throws <NotSupportedException>(
                () =>
                workspace.TryApplyChanges(
                    project.WithCompilationOptions(
                        project.CompilationOptions !.WithMainTypeName("WrongThing")
                        ).Solution
                    )
                );

            Assert.Equal(
                WorkspacesResources.Changing_compilation_options_is_not_supported,
                exception.Message
                );
        }
Esempio n. 3
0
        public void TryApplyWorksWhenAddingEditorConfigWithoutSupportingCompilationOptionsChanging()
        {
            using var workspace = new CustomizedCanApplyWorkspace(allowedKinds: ApplyChangesKind.AddAnalyzerConfigDocument);

            var project = workspace.CurrentSolution.Projects.Single();

            Assert.True(workspace.TryApplyChanges(project.AddAnalyzerConfigDocument(".editorconfig", SourceText.From("")).Project.Solution));
        }
Esempio n. 4
0
        public void TryApplyWorksSpecificChangeIsAllowedForCompilationOption()
        {
            // If we don't support the main change kind, then the other method should be called
            using var workspace = new CustomizedCanApplyWorkspace(
                      allowedKinds: new ApplyChangesKind[] { },
                      canApplyCompilationOptions: (_, newCompilationOptions) => newCompilationOptions.MainTypeName == "Test");

            var project = workspace.CurrentSolution.Projects.Single();

            Assert.True(workspace.TryApplyChanges(project.WithCompilationOptions(project.CompilationOptions !.WithMainTypeName("Test")).Solution));
        }
Esempio n. 5
0
        public void TryApplyWorksSpecificChangeIsAllowedForParseOption()
        {
            // If we don't support the main change kind, then the other method should be called
            using var workspace = new CustomizedCanApplyWorkspace(
                      allowedKinds: new ApplyChangesKind[] { },
                      canApplyParseOptions: (_, newParseOptions) => newParseOptions.Features["Feature"] == "ExpectedValue");

            var project = workspace.CurrentSolution.Projects.Single();

            Assert.True(
                workspace.TryApplyChanges(
                    project.WithParseOptions(project.ParseOptions !.WithFeatures(new[] { KeyValuePairUtil.Create("Feature", "ExpectedValue") })).Solution));
        }