private LiveIssue SetupAndCreate(Diagnostic diagnostic, string diagnosticProjectFilePath) { // Arrange var vsSolutionMock = SetupSolutionMocks( new KeyValuePair <string, string>(ProjectInSolutionFilePath, "{31D0DAAC-8606-40FE-8DF0-01784706EA3E}")); var projectId = ProjectId.CreateNewId(); var workspace = new AdhocWorkspace(); var solution = workspace.CurrentSolution .AddProject(ProjectInfo.Create(projectId, VersionStamp.Default, "Project1", "Assembly1", LanguageNames.CSharp, diagnosticProjectFilePath)) .AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "name is unimportant.cs", loader: TextLoader.From(TextAndVersion.Create(SourceText.From(@"namespace { class Foo { } }"), VersionStamp.Default)))); workspace.TryApplyChanges(solution); var liveIssueFactory = new RoslynLiveIssueFactory(workspace, vsSolutionMock.Object); var syntaxTree = workspace.CurrentSolution.Projects.First().GetCompilationAsync().Result.SyntaxTrees.First(); // Act using (new AssertIgnoreScope()) { return(liveIssueFactory.Create(syntaxTree, diagnostic)); } }
public void Create_WhenSyntaxTreeIsNull_ReturnsNull() { // Arrange var vsSolutionMock = new Mock <IVsSolution>(); uint fileCount = 2; // initialized with a value to actually assign a value to the out vsSolutionMock.Setup(x => x.GetProjectFilesInSolution(0, 0, null, out fileCount)) .Returns(VSConstants.S_OK); var fileNames = new string[fileCount]; vsSolutionMock.Setup(x => x.GetProjectFilesInSolution(0, fileCount, fileNames, out fileCount)) .Callback(new OutAction <uint, uint, string[], uint>((uint x, uint y, string[] paths, out uint z) => { z = 0; paths[0] = "Project1"; paths[1] = "Project2"; })); vsSolutionMock.As <IVsSolution5>().Setup(x => x.GetGuidOfProjectFile(It.IsAny <string>())) .Returns(Guid.Empty); var liveIssueFactory = new RoslynLiveIssueFactory(new AdhocWorkspace(), vsSolutionMock.Object); var diagnostic = CreateDiagnostic(Location.None); // Act var result = liveIssueFactory.Create(null, diagnostic); // Assert result.Should().BeNull(); }