public async Task ProjectLoadedAsync_AddsNewProjectWithDocument()
        {
            // Arrange
            var projectRootElement = ProjectRootElement.Create("/project/project.csproj");
            var intermediateOutputPath = "/project/obj";
            projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath);
            var projectInstance = new ProjectInstance(projectRootElement);
            var hostDocument = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component);
            var projectConfiguration = new ProjectConfiguration(CustomConfiguration, new[] { hostDocument }, "TestRootNamespace");
            var configurationProvider = new Mock<ProjectConfigurationProvider>();
            configurationProvider.Setup(provider => provider.TryResolveConfiguration(It.IsAny<ProjectConfigurationProviderContext>(), out projectConfiguration))
                .Returns(true);
            var msbuildProjectManager = new MSBuildProjectManager(
                new[] { configurationProvider.Object },
                ProjectInstanceEvaluator,
                Mock.Of<ProjectChangePublisher>(),
                Dispatcher,
                LoggerFactory);
            var projectManager = CreateProjectSnapshotManager();
            msbuildProjectManager.Initialize(projectManager);
            var args = new ProjectLoadedEventArgs(
                ProjectId.CreateNewId(),
                projectInstance,
                diagnostics: Enumerable.Empty<MSBuildDiagnostic>().ToImmutableArray(),
                isReload: false,
                projectIdIsDefinedInSolution: false,
                sourceFiles: Enumerable.Empty<string>().ToImmutableArray());

            // Act
            await msbuildProjectManager.ProjectLoadedAsync(args);

            // Assert
            var project = await RunOnForegroundAsync(() => Assert.Single(projectManager.Projects));
            Assert.Equal(projectInstance.ProjectFileLocation.File, project.FilePath);
            Assert.Same(CustomConfiguration, project.Configuration);
            var document = project.GetDocument(hostDocument.FilePath);
            Assert.NotNull(document);
        }
예제 #2
0
        public async Task ProjectLoadedAsync_AddsNewProjectWithDocument()
        {
            // Arrange
            var projectRootElement     = ProjectRootElement.Create("/project/project.csproj");
            var intermediateOutputPath = "/project/obj";

            projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath);
            var projectInstance       = new ProjectInstance(projectRootElement);
            var hostDocument          = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component);
            var projectConfiguration  = new ProjectConfiguration(CustomConfiguration, new[] { hostDocument }, "TestRootNamespace");
            var configurationProvider = new Mock <ProjectConfigurationProvider>(MockBehavior.Strict);

            configurationProvider.Setup(provider => provider.TryResolveConfiguration(It.IsAny <ProjectConfigurationProviderContext>(), out projectConfiguration))
            .Returns(true);
            var projectChangePublisher = new Mock <ProjectChangePublisher>(MockBehavior.Strict);

            projectChangePublisher.Setup(p => p.SetPublishFilePath(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            var msbuildProjectManager = new MSBuildProjectManager(
                new[] { configurationProvider.Object },
                CreateProjectInstanceEvaluator(),
                projectChangePublisher.Object,
                Dispatcher,
                LoggerFactory);
            var projectManager = CreateProjectSnapshotManager();

            msbuildProjectManager.Initialize(projectManager);
            var args = new ProjectLoadedEventArgs(
                id: null,
                project: null,
                sessionId: Guid.NewGuid(),
                projectInstance,
                diagnostics: Enumerable.Empty <MSBuildDiagnostic>().ToImmutableArray(),
                isReload: false,
                projectIdIsDefinedInSolution: false,
                sourceFiles: Enumerable.Empty <string>().ToImmutableArray(),
                sdkVersion: default);