public void HandleAggregatableResponsesForSingleLanguage()
        {
            var request = new TestRequestPacket()
            {
                Seq       = 99,
                Command   = OmniSharpEndpoints.FindSymbols,
                Arguments = JsonConvert.SerializeObject(new FindSymbolsRequest {
                    Language = LanguageNames.CSharp
                })
            };

            var writer = new TestTextWriter(
                value =>
            {
                var packet = JsonConvert.DeserializeObject <EventPacket>(value);
                Assert.Equal("started", packet.Event);
            },
                value =>
            {
                var packet = JsonConvert.DeserializeObject <ResponsePacket>(value);
                Assert.Equal(request.Seq, packet.Request_seq);
                Assert.Equal(request.Command, packet.Command);
                Assert.True(packet.Success);
                Assert.True(packet.Running);
                Assert.Null(packet.Message);
                var quickFixResponse = ((JObject)packet.Body).ToObject <QuickFixResponse>();
                Assert.Equal(3, quickFixResponse.QuickFixes.Count());
                Assert.Equal("AAAFakeFindSymbolsService", quickFixResponse.QuickFixes.ElementAt(0).Text);
                Assert.Equal("BBBFakeFindSymbolsService", quickFixResponse.QuickFixes.ElementAt(1).Text);
                Assert.Equal("CCCFakeFindSymbolsService", quickFixResponse.QuickFixes.ElementAt(2).Text);
            }
                );

            var exports = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IRequestHandler>(
                    new BBBFakeFindSymbolsService(),
                    new Dictionary <string, object> {
                    ["EndpointName"] = OmniSharpEndpoints.FindSymbols, ["Language"] = LanguageNames.CSharp
                }),
                MefValueProvider.From <IRequestHandler>(
                    new CCCFakeFindSymbolsService(),
                    new Dictionary <string, object> {
                    ["EndpointName"] = OmniSharpEndpoints.FindSymbols, ["Language"] = LanguageNames.CSharp
                }),
                MefValueProvider.From <IRequestHandler>(
                    new AAAFakeFindSymbolsService(),
                    new Dictionary <string, object> {
                    ["EndpointName"] = OmniSharpEndpoints.FindSymbols, ["Language"] = LanguageNames.CSharp
                }),
            };

            using (StdioServerFacts.BuildTestServerAndStart(new StringReader(JsonConvert.SerializeObject(request) + "\r\n"), writer, additionalExports: exports))
            {
                Assert.True(writer.Completion.WaitOne(TimeSpan.FromSeconds(60)), "Timeout");
                Assert.Null(writer.Exception);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Add an export descriptor provider to the container.
 /// </summary>
 /// <param name="exportDescriptorProvider">An export descriptor provider.</param>
 /// <returns>A configuration object allowing configuration to continue.</returns>
 public ContainerConfiguration WithProvider(ExportDescriptorProvider exportDescriptorProvider)
 {
     if (exportDescriptorProvider == null)
     {
         throw new ArgumentNullException("ExportDescriptorProvider");
     }
     _addedSources.Add(exportDescriptorProvider);
     return(this);
 }
        public void HandleNonAggregatableResponses()
        {
            var request = new TestRequestPacket()
            {
                Seq       = 99,
                Command   = OmniSharpEndpoints.GotoDefinition,
                Arguments = JsonConvert.SerializeObject(new GotoDefinitionRequest {
                    FileName = "foo.cs"
                })
            };

            var writer = new TestTextWriter(
                value =>
            {
                var packet = JsonConvert.DeserializeObject <EventPacket>(value);
                Assert.Equal("started", packet.Event);
            },
                value =>
            {
                var packet = JsonConvert.DeserializeObject <ResponsePacket>(value);
                Assert.Equal(request.Seq, packet.Request_seq);
                Assert.Equal(request.Command, packet.Command);
                Assert.True(packet.Success);
                Assert.True(packet.Running);
                Assert.Null(packet.Message);
                var gotoDefinitionResponse = ((JObject)packet.Body).ToObject <GotoDefinitionResponse>();
                Assert.Equal("ZZZFake.cs", gotoDefinitionResponse.FileName);
            }
                );

            var exports = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IProjectSystem>(new FakeProjectSystem()),
                MefValueProvider.From <IRequestHandler>(
                    new FakeGotoDefinitionService("ZZZFake", false),
                    new Dictionary <string, object> {
                    ["EndpointName"] = OmniSharpEndpoints.GotoDefinition, ["Language"] = LanguageNames.CSharp
                }),
                MefValueProvider.From <IRequestHandler>(
                    new FakeGotoDefinitionService("AAAFake", true),
                    new Dictionary <string, object> {
                    ["EndpointName"] = OmniSharpEndpoints.GotoDefinition, ["Language"] = LanguageNames.CSharp
                }),
            };

            using (StdioServerFacts.BuildTestServerAndStart(new StringReader(JsonConvert.SerializeObject(request) + "\r\n"), writer, additionalExports: exports))
            {
                Assert.True(writer.Completion.WaitOne(TimeSpan.FromSeconds(60)), "Timeout");
                Assert.Null(writer.Exception);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Create the composition host.
        /// </summary>
        /// <returns>The container as an <see cref="CompositionHost"/>.</returns>
        public static CompositionHost CreateCompositionHost(IEnumerable <ExportDescriptorProvider> providers)
        {
            Requires.NotNull(providers, "providers");

            var allProviders = new ExportDescriptorProvider[] {
                new LazyExportDescriptorProvider(),
                new ExportFactoryExportDescriptorProvider(),
                new ImportManyExportDescriptorProvider(),
                new LazyWithMetadataExportDescriptorProvider(),
                new CurrentScopeExportDescriptorProvider(),
                new ExportFactoryWithMetadataExportDescriptorProvider()
            }
            .Concat(providers)
            .ToArray();

            var container = new LifetimeContext(new ExportDescriptorRegistry(allProviders), s_noBoundaries);

            return(new CompositionHost(container));
        }
        public async Task The_target_framework_is_emitted()
        {
            // Arrange
            var expectedTFM = "netcoreapp2.1";
            var messages    = new List <ProjectConfigurationMessage>();
            var emitter     = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    Assert.Single(messages);
                    Assert.Equal(messages[0].TargetFrameworks.First(), expectedTFM);
                }
        }
        public async Task The_hashed_references_of_the_source_files_are_emitted()
        {
            // Arrange
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    Assert.Single(messages);
                    Assert.Single(messages[0].FileExtensions);
                    Assert.Equal(messages[0].FileExtensions.First(), GetHashedFileExtension(".cs"));
                }
        }
        public async Task If_there_is_a_solution_file_the_project_guid_present_in_it_is_emitted()
        {
            // Arrange
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectAndSolution"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    var expectedGuid = "A4C2694D-AEB4-4CB1-8951-5290424EF883".ToLower();
                    Assert.Single(messages);
                    Assert.Equal(messages[0].ProjectId, expectedGuid);
                }
        }
        public async Task If_there_is_no_solution_file_the_hash_of_project_file_content_and_name_is_emitted()
        {
            // Arrange
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    var projectFileContent = File.ReadAllText(Directory.GetFiles(testProject.Directory, "*.csproj").Single());
                    var expectedGuid       = GetHashedReference($"Filename: HelloWorld.csproj\n{projectFileContent}");
                    Assert.Single(messages);
                    Assert.Equal(messages[0].ProjectId, expectedGuid);
                }
        }
        public async Task If_there_are_multiple_target_frameworks_they_are_emitted()
        {
            // Arrange
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMultiTFMLib/Lib"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    Assert.Single(messages);
                    var tfm = messages[0].TargetFrameworks.ToArray();
                    Assert.Equal(2, tfm.Count());
                    Assert.Equal("netstandard1.3", tfm[0]);
                    Assert.Equal("netstandard2.0", tfm[1]);
                }
        }
        /// <summary>
        /// Create the composition host.
        /// </summary>
        /// <returns>The container as an <see cref="CompositionHost"/>.</returns>
        public static CompositionHost CreateCompositionHost(IEnumerable <ExportDescriptorProvider> providers)
        {
            if (providers == null)
            {
                throw new ArgumentNullException(nameof(providers));
            }

            var allProviders = new ExportDescriptorProvider[] {
                new LazyExportDescriptorProvider(),
                new ExportFactoryExportDescriptorProvider(),
                new ImportManyExportDescriptorProvider(),
                new LazyWithMetadataExportDescriptorProvider(),
                new CurrentScopeExportDescriptorProvider(),
                new ExportFactoryWithMetadataExportDescriptorProvider()
            }
            .Concat(providers)
            .ToArray();

            var container = new LifetimeContext(new ExportDescriptorRegistry(allProviders), s_noBoundaries);

            return(new CompositionHost(container));
        }
Beispiel #11
0
        public async Task ProjectLoadedFires()
        {
            var allEventArgs = new List <ProjectLoadedEventArgs>();

            var eventSink = new FakeMSBuildEventSink(e =>
            {
                allEventArgs.Add(e);
            });

            var exports = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(eventSink)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectAndSolution"))
                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    var eventArgs = Assert.Single(allEventArgs);
                    Assert.Equal(
                        $"{testProject.Directory}/{testProject.Name}.csproj".EnsureForwardSlashes(),
                        eventArgs.ProjectInstance.FullPath.EnsureForwardSlashes());
                }
        }
        public async Task Given_a_restored_project_the_references_are_emitted()
        {
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
            {
                var dotnetCliService = new DotNetCliService(LoggerFactory, emitter);
                await dotnetCliService.RestoreAsync(testProject.Directory);

                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    Assert.Single(messages);
                    Assert.NotEmpty(messages[0].References.Where(reference => reference == GetHashedReference("system.core")));
                }
            }
        }
Beispiel #13
0
 /// <summary>
 /// Add an export descriptor provider to the container.
 /// </summary>
 /// <param name="exportDescriptorProvider">An export descriptor provider.</param>
 /// <returns>A configuration object allowing configuration to continue.</returns>
 public ContainerConfiguration WithProvider(ExportDescriptorProvider exportDescriptorProvider !!)
 {