private static WorkspaceProjectContextProvider CreateInstance(UnconfiguredProject project = null, IProjectThreadingService threadingService = null, IWorkspaceProjectContextFactory workspaceProjectContextFactory = null, ISafeProjectGuidService projectGuidService = null, IProjectRuleSnapshot projectRuleSnapshot = null) { projectRuleSnapshot = projectRuleSnapshot ?? IProjectRuleSnapshotFactory.FromJson( @"{ ""Properties"": { ""MSBuildProjectFullPath"": ""C:\\Project\\Project.csproj"", ""LanguageServiceName"": ""CSharp"", ""TargetPath"": ""C:\\Target.dll"" } }"); var telemetryService = ITelemetryServiceFactory.Create(); project = project ?? UnconfiguredProjectFactory.Create(); threadingService = threadingService ?? IProjectThreadingServiceFactory.Create(); workspaceProjectContextFactory = workspaceProjectContextFactory ?? IWorkspaceProjectContextFactoryFactory.Create(); projectGuidService = projectGuidService ?? ISafeProjectGuidServiceFactory.ImplementGetProjectGuidAsync(Guid.NewGuid()); var mock = new Mock <WorkspaceProjectContextProvider>(project, threadingService, projectGuidService, telemetryService, workspaceProjectContextFactory.AsLazy()); mock.Protected().Setup <Task <IProjectRuleSnapshot> >("GetLatestSnapshotAsync", ItExpr.IsAny <ConfiguredProject>()) .ReturnsAsync(projectRuleSnapshot); return(mock.Object); }
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_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); }