示例#1
0
        public async Task ApplyProjectBuildAsync_ParseCommandLineAndCallsHandler()
        {
            (IComparable version, BuildOptions added, BuildOptions removed, ContextState state, IProjectLogger logger)result = default;

            var handler = ICommandLineHandlerFactory.ImplementHandle((version, added, removed, state, logger) =>
            {
                result = (version, added, removed, state, logger);
            });

            var parser = ICommandLineParserServiceFactory.CreateCSharp();

            var applyChangesToWorkspace = CreateInitializedInstance(commandLineParser: parser, handlers: new[] { handler });

            var update = IProjectVersionedValueFactory.FromJson(version: 2,
                                                                @"{
   ""ProjectChanges"": {
        ""CompilerCommandLineArgs"": {
            ""Difference"": { 
                ""AnyChanges"": true,
                ""AddedItems"" : [ ""/reference:Added.dll"" ],
                ""RemovedItems"" : [ ""/reference:Removed.dll"" ]
            }
        }
    }
}");
            await applyChangesToWorkspace.ApplyProjectBuildAsync(update, new ContextState(isActiveEditorContext : true, isActiveConfiguration : false), CancellationToken.None);

            Assert.Equal(2, result.version);
            Assert.True(result.state.IsActiveEditorContext);
            Assert.NotNull(result.logger);

            Assert.Single(result.added !.MetadataReferences.Select(r => r.Reference), "Added.dll");
            Assert.Single(result.removed !.MetadataReferences.Select(r => r.Reference), "Removed.dll");
        }
示例#2
0
        private static ApplyChangesToWorkspaceContext CreateInstance(ConfiguredProject?project = null, ICommandLineParserService?commandLineParser = null, IProjectLogger?logger = null, params IWorkspaceContextHandler[] handlers)
        {
            if (project == null)
            {
                var unconfiguredProject = UnconfiguredProjectFactory.ImplementFullPath(@"C:\Project\Project.csproj");

                project = ConfiguredProjectFactory.ImplementUnconfiguredProject(unconfiguredProject);
            }

            commandLineParser ??= ICommandLineParserServiceFactory.Create();
            logger ??= IProjectLoggerFactory.Create();

            var factories = handlers.Select(h => ExportFactoryFactory.ImplementCreateValueWithAutoDispose(() => h))
                            .ToArray();

            var applyChangesToWorkspaceContext = new ApplyChangesToWorkspaceContext(project, logger, factories);

            applyChangesToWorkspaceContext.CommandLineParsers.Add(commandLineParser);

            return(applyChangesToWorkspaceContext);
        }