public async Task CreateProjectContextAsync_WhenCreateProjectContextThrows_ReturnsNull()
        {
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => { throw new Exception(); });
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            var result = await provider.CreateProjectContextAsync(project);

            Assert.Null(result);
        }
        public async Task CreateProjectContextAsync_ReturnsContextWithLastDesignTimeBuildSucceededSetToFalse()
        {
            var context = IWorkspaceProjectContextMockFactory.Create();
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => context);
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            var result = await provider.CreateProjectContextAsync(project);

            Assert.NotNull(context);
            Assert.False(context.LastDesignTimeBuildSucceeded);
        }
        public async Task CreateProjectContextAsync_UniquelyIdentifiesContext(string configuration, string guid, string expected)
        {
            var projectGuidService = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(new Guid(guid));

            string result = null;
            var    workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, id, ___, ____, ______, _______) => { result = id; return(null); });
            var    provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, projectGuidService: projectGuidService);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(configuration);

            await provider.CreateProjectContextAsync(project);

            Assert.Equal(expected, result);
        }
        public async Task CreateProjectContextAsync_WhenEmptyOrMissingMSBuildProperties_ReturnsNull(string json)
        {
            var snapshot = IProjectRuleSnapshotFactory.FromJson(json);

            int callCount = 0;
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => { callCount++; return(null); });
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, projectRuleSnapshot: snapshot);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            var result = await provider.CreateProjectContextAsync(project);

            Assert.Null(result);
            Assert.Equal(0, callCount);
        }
        public async Task CreateProjectContextAsync_RegistersContextWithTracker()
        {
            IWorkspaceProjectContext result          = null;
            var activeWorkspaceProjectContextTracker = IActiveWorkspaceProjectContextTrackerFactory.ImplementRegisterContext((c, id) => { result = c; });

            var context = IWorkspaceProjectContextMockFactory.Create();
            var workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((_, __, ___, ____, ______, _______) => context);
            var provider = CreateInstance(workspaceProjectContextFactory: workspaceProjectContextFactory, activeWorkspaceProjectContextTracker: activeWorkspaceProjectContextTracker);

            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            await provider.CreateProjectContextAsync(project);

            Assert.NotNull(result);
        }
        public async Task CreateProjectContextAsync_PassesThroughDataToCreateProjectContext()
        {
            var projectRuleSnapshot = IProjectRuleSnapshotFactory.FromJson(
                @"{
    ""Properties"": {
        ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"",
        ""LanguageServiceName"": ""CSharp"",
        ""TargetPath"": ""C:\\Target.dll""
    }
}");
            var projectGuid        = new Guid("{72B509BD-C502-4707-ADFD-E2D43867CF45}");
            var projectGuidService = ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(projectGuid);

            var hostObject          = new object();
            var unconfiguredProject = UnconfiguredProjectFactory.Create(hostObject);

            string languageNameResult = null, projectFilePathResult = null, binOutputPathResult = null;
            Guid?  projectGuidResult              = null;
            object hierarchyResult                = null;
            var    workspaceProjectContextFactory = IWorkspaceProjectContextFactoryFactory.ImplementCreateProjectContext((languageName, _, projectFilePath, guid, hierarchy, binOutputPath) =>
            {
                languageNameResult    = languageName;
                projectFilePathResult = projectFilePath;
                projectGuidResult     = guid;
                hierarchyResult       = hierarchy;
                binOutputPathResult   = binOutputPath;
                return(null);
            });

            var provider = CreateInstance(project: unconfiguredProject, workspaceProjectContextFactory: workspaceProjectContextFactory, projectGuidService: projectGuidService);
            var project  = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");

            await provider.CreateProjectContextAsync(project);

            Assert.Equal("CSharp", languageNameResult);
            Assert.Equal("C:\\Project\\Project.csproj", projectFilePathResult);
            Assert.Equal("C:\\Target.dll", binOutputPathResult);
            Assert.Equal(projectGuid, projectGuidResult.Value);
            Assert.Equal(hostObject, hierarchyResult);
        }