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)) .OutCallback((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 LiveIssueFactory(new AdhocWorkspace(), vsSolutionMock.Object); var diagnostic = Diagnostic.Create(new DiagnosticDescriptor("id", "title", "message", "category", DiagnosticSeverity.Hidden, true), Location.None); // Act var result = liveIssueFactory.Create(null, diagnostic); // Assert result.Should().BeNull(); }
private LiveIssue SetupAndCreate(Diagnostic diagnostic, string filePath) { // Arrange var vsSolutionMock = SetupSolutionMocks( new KeyValuePair <string, string>("C:\\Project1.csproj", "{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, filePath)) .AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "MySource.cs", loader: TextLoader.From(TextAndVersion.Create(SourceText.From(@"namespace { class Foo { } }"), VersionStamp.Default)))); workspace.TryApplyChanges(solution); var liveIssueFactory = new LiveIssueFactory(workspace, vsSolutionMock.Object); var syntaxTree = workspace.CurrentSolution.Projects.First().GetCompilationAsync().Result.SyntaxTrees.First(); // Act using (new AssertIgnoreScope()) { return(liveIssueFactory.Create(syntaxTree, diagnostic)); } }
private LiveIssue SetupAndCreate(Diagnostic diagnostic, string filePath) { // Arrange var vsSolutionMock = new Mock <IVsSolution>(); uint fileCount = 1; // 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)) .OutCallback((uint x, uint y, string[] paths, out uint z) => { z = 0; paths[0] = "Project1"; }); vsSolutionMock.As <IVsSolution5>().Setup(x => x.GetGuidOfProjectFile(It.IsAny <string>())) .Returns(Guid.Parse("{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, filePath)) .AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "MySource.cs", loader: TextLoader.From(TextAndVersion.Create(SourceText.From(@"namespace { class Foo { } }"), VersionStamp.Default)))); workspace.TryApplyChanges(solution); var liveIssueFactory = new LiveIssueFactory(workspace, vsSolutionMock.Object); var syntaxTree = workspace.CurrentSolution.Projects.First().GetCompilationAsync().Result.SyntaxTrees.First(); // Act using (new AssertIgnoreScope()) { return(liveIssueFactory.Create(syntaxTree, diagnostic)); } }