public void ShouldRemoveItemGroupWhenRemovingLastFile() { XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003"; var project = new FakeProject(fileName: @"c:\test\code\fake.csproj"); project.AddFile("some content", @"c:\test\code\test.cs"); var xml = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> </Project>"; project.XmlRepresentation = XDocument.Parse(xml); var solution = new FakeSolution(@"c:\test\fake.sln"); solution.Projects.Add(project); var request = new RemoveFromProjectRequest { FileName = @"c:\test\code\test.cs" }; var handler = new RemoveFromProjectHandler(solution); handler.RemoveFromProject(request); project.AsXml().Descendants(ns + "ItemGroup").Count().ShouldEqual(0); }
public void Should_find_usages_of_class() { const string editorText = @"public class myclass { public void method() { } public void method_calling_method() { method(); } } "; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new FindUsagesHandler(new OmniSharp.Parser.BufferParser(solution), solution, new ProjectFinder(solution)); var usages = handler.FindUsages(new FindUsagesRequest { FileName = "myfile", Line = 3, Column = 21, Buffer = editorText }).QuickFixes.ToArray(); usages.Length.ShouldEqual(2); usages[0].Text.Trim().ShouldEqual("public void method() { }"); usages[1].Text.Trim().ShouldEqual("method();"); }
public void Should_find_usages_of_class() { const string editorText = @"public class myclass { public void method() { } public void method_calling_method() { method(); } } "; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new FindUsagesHandler (new OmniSharp.Parser.BufferParser (solution), solution, new ProjectFinder(solution)); var usages = handler.FindUsages (new FindUsagesRequest { FileName = "myfile", Line = 3, Column = 21, Buffer = editorText }).QuickFixes.ToArray(); usages.Length.ShouldEqual(2); usages[0].Text.Trim().ShouldEqual("public void method() { }"); usages[1].Text.Trim().ShouldEqual("method();"); }
public IEnumerable <CompletionData> GetCompletions(string editorText, bool includeImportableTypes) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if (cursorOffset == -1) { throw new ArgumentException("Editor text should contain a $"); } TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(_solution, new BufferParser(_solution), new Logger(Verbosity.Quiet), new OmniSharpConfiguration()); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, WantDocumentationForEveryCompletionResult = false, WantImportableTypes = includeImportableTypes, WantMethodHeader = true, WantReturnType = true, WantSnippet = true }; return(provider.CreateProvider(request)); }
public IEnumerable <ICompletionData> GetCompletions(string editorText) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if (cursorOffset == -1) { throw new ArgumentException("Editor text should contain a $"); } TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(new BufferParser(_solution), new Logger()); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, }; return(provider.CreateProvider(request)); }
public void Should_find_usages_in_same_file() { const string editorText = @" public class BaseClass {} public class DerivedClassA : BaseClass {} public class DerivedClassB : BaseClass {} public class DerivedClassC : BaseClass {} "; var fileName = "test.cs"; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText, fileName); solution.Projects.Add(project); var handler = new GotoImplementationHandler (solution, new BufferParser(solution), new ProjectFinder(solution)); var request = new GotoImplementationRequest { Buffer = editorText , Line = 2 , Column = 14 // At word 'BaseClass' , FileName = fileName }; var gotoImplementationResponse = handler.FindDerivedMembersAsQuickFixes(request); var quickFixes = gotoImplementationResponse.QuickFixes.ToArray(); Assert.AreEqual(3, quickFixes.Length); quickFixes[0].Text.Trim().ShouldEqual("public class DerivedClassA : BaseClass {}"); quickFixes[1].Text.Trim().ShouldEqual("public class DerivedClassB : BaseClass {}"); quickFixes[2].Text.Trim().ShouldEqual("public class DerivedClassC : BaseClass {}"); }
public void ShouldRemoveFileFromProjectXml() { var project = new FakeProject(fileName: @"c:\test\code\fake.csproj"); project.AddFile("some content", @"c:\test\code\test.cs"); var xml = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Hello.cs""/> <Compile Include=""Test.cs""/> </ItemGroup> </Project>"; project.XmlRepresentation = XDocument.Parse(xml); var expectedXml = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Hello.cs""/> </ItemGroup> </Project>"); var solution = new FakeSolution(@"c:\test\fake.sln"); solution.Projects.Add(project); var request = new RemoveFromProjectRequest { FileName = @"c:\test\code\test.cs" }; var handler = new RemoveFromProjectHandler(solution); handler.RemoveFromProject(request); project.AsXml().ToString().ShouldEqual(expectedXml.ToString()); }
public void Should_find_usages_of_class() { const string editorText = @"public class myclass { public void method() { } public void method_calling_method() { method(); } } "; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency<ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/findusages", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("Line", "3"); with.FormValue("Column", "21"); with.FormValue("Buffer", editorText); }); var usages = result.Body.DeserializeJson<FindUsagesResponse>().Usages.ToArray(); usages.Count().ShouldEqual(2); usages[0].Text.Trim().ShouldEqual("public void method() { }"); usages[1].Text.Trim().ShouldEqual("method();"); }
public IEnumerable<ICompletionData> GetCompletions(string editorText) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if(cursorOffset == -1) throw new ArgumentException("Editor text should contain a $"); TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(new BufferParser(_solution), new Logger()); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, }; return provider.CreateProvider(request); }
public void Should_find_usages_in_same_file() { const string editorText = @" public class BaseClass {} public class DerivedClassA : BaseClass {} public class DerivedClassB : BaseClass {} public class DerivedClassC : BaseClass {} "; var fileName = "test.cs"; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText, fileName: fileName); solution.Projects.Add(project); var handler = new GotoImplementationHandler (solution, new BufferParser(solution)); var request = new GotoImplementationRequest { Buffer = editorText , Line = 2 , Column = 14 // At word 'BaseClass' , FileName = fileName}; var gotoImplementationResponse = handler.FindDerivedMembersAsQuickFixes(request); var quickFixes = gotoImplementationResponse.QuickFixes.ToArray(); Assert.AreEqual(3, quickFixes.Length); quickFixes[0].Text.Trim().ShouldEqual("public class DerivedClassA : BaseClass {}"); quickFixes[1].Text.Trim().ShouldEqual("public class DerivedClassB : BaseClass {}"); quickFixes[2].Text.Trim().ShouldEqual("public class DerivedClassC : BaseClass {}"); }
public void ShouldRemoveItemGroupWhenRemovingLastFile() { XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003"; var project = new FakeProject(fileName: @"c:\test\code\fake.csproj"); project.AddFile("some content", @"c:\test\code\test.cs"); var xml = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> </Project>"; project.XmlRepresentation = XDocument.Parse(xml); var solution = new FakeSolution(@"c:\test\fake.sln"); solution.Projects.Add(project); var request = new RemoveFromProjectRequest { FileName = @"c:\test\code\test.cs" }; var handler = new RemoveFromProjectHandler(solution); handler.RemoveFromProject(request); project.AsXml().Descendants(ns + "ItemGroup").Count().ShouldEqual(0); }
public void ShouldRemoveFileFromProject() { var project = new FakeProject(fileName: @"c:\test\code\fake.csproj"); project.AddFile("some content", @"c:\test\code\test.cs"); var xml = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> </Project>"; project.XmlRepresentation = XDocument.Parse(xml); var solution = new FakeSolution(@"c:\test\fake.sln"); solution.Projects.Add(project); var request = new RemoveFromProjectRequest { FileName = @"c:\test\code\test.cs" }; var handler = new RemoveFromProjectHandler(solution); handler.RemoveFromProject(request); project.Files.ShouldBeEmpty(); }
public IEnumerable<CompletionData> GetCompletions(string editorText, bool includeImportableTypes) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); if(cursorOffset == -1) throw new ArgumentException("Editor text should contain a $"); TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var project = new FakeProject(); project.AddFile(editorText); _solution.Projects.Add(project); var provider = new AutoCompleteHandler(_solution, new BufferParser(_solution), new Logger(Verbosity.Quiet)); var request = new AutoCompleteRequest { FileName = "myfile", WordToComplete = partialWord, Buffer = editorText, Line = cursorPosition.Line, Column = cursorPosition.Column, WantDocumentationForEveryCompletionResult = false, WantImportableTypes = includeImportableTypes, WantMethodHeader = true, WantReturnType = true, WantSnippet = true }; return provider.CreateProvider(request); }
public void ShouldNotAddNonCSharpFile() { var project = new FakeProject(fileName: @"c:\test\code\fake.csproj"); var expectedXml = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/></ItemGroup></Project>"); project.XmlRepresentation = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/></ItemGroup></Project>"); project.AddFile("some content", @"c:\test\code\foo.txt"); var solution = new FakeSolution(@"c:\test\fake.sln"); solution.Projects.Add(project); var request = new AddToProjectRequest { FileName = @"c:\test\code\foo.txt" }; var handler = new AddToProjectHandler(solution, new FakeWindowsFileSystem()); handler.AddToProject(request); project.AsXml().ToString().ShouldEqual(expectedXml.ToString()); }
void CreateTestProject() { var solution = new FakeSolution(@"c:\projects\Test\MyProject\MySolution.sln"); solution.BaseDirectory = @"c:\projects\Test\MyProject"; project = new FakeProject(); project.ParentSolution = solution; }
public CustomToolParameterTest() { this.dte = new FakeDte(); this.solution = new FakeSolution(this.dte); this.project = new FakeProject(this.solution); this.projectItem = new FakeProjectItem(this.project); this.parent = new CustomToolParameters(this.dte, this.project, this.projectItem.Id); }
public BrowseObjectExtenderTest() { this.dte = new FakeDte(); this.solution = new FakeSolution(this.dte); this.project = new FakeProject(this.solution); this.projectItem = new FakeProjectItem(this.project); this.extenderSite = new StubExtenderSite(); }
public CustomToolParametersTest() { this.dte = new FakeDte(); this.dte.AddService(typeof(TemplateLocator), new FakeTemplateLocator(), false); this.dte.AddService(typeof(STextTemplating), new FakeTextTemplatingService(), false); this.solution = new FakeSolution(this.dte); this.project = new FakeProject(this.solution); this.projectItem = new FakeProjectItem(this.project); }
public FakeSREDContext() { Employees = new FakeEmployee(); Permissions = new FakePermission(); Positions = new FakePosition(); Projects = new FakeProject(); ProjectEntries = new FakeProjectEntry(); SREDCategories = new FakeSREDCategory(); TransactionLogs = new FakeTransactionLog(); }
public void CanAddProjectReferenceWhenProjectReferencesExist() { var projectOne = CreateDefaultProject(); var projectTwoId = Guid.NewGuid(); var projectTwo = new FakeProject("faketwo", @"c:\test\two\fake2.csproj", projectTwoId); projectTwo.Title = "Project Two"; projectTwo.AddFile("some content", @"c:\test\two\test.cs"); projectTwo.XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\existing\project.csproj""> <Project>{1-2-3-4}</Project> <Name>Existing Project</Name> </ProjectReference> </ItemGroup> </Project>"); var expectedXml = XDocument.Parse(string.Format(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\existing\project.csproj""> <Project>{{1-2-3-4}}</Project> <Name>Existing Project</Name> </ProjectReference> <ProjectReference Include=""..\one\fake1.csproj""> <Project>{0}</Project> <Name>Project One</Name> </ProjectReference> </ItemGroup> </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}"))); Solution.Projects.Add(projectOne); Solution.Projects.Add(projectTwo); var request = new AddReferenceRequest { Reference = @"fake1", FileName = @"c:\test\two\test.cs" }; var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(Solution) })); handler.AddReference(request); projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString()); }
public void CanAddProjectReferenceWhenProjectReferencesExist() { var projectOne = CreateDefaultProject(); var projectTwoId = Guid.NewGuid(); var projectTwo = new FakeProject("faketwo", @"c:\test\two\fake2.csproj", projectTwoId); projectTwo.Title = "Project Two"; projectTwo.AddFile("some content", @"c:\test\two\test.cs"); projectTwo.XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\existing\project.csproj""> <Project>{1-2-3-4}</Project> <Name>Existing Project</Name> </ProjectReference> </ItemGroup> </Project>"); var expectedXml = XDocument.Parse(string.Format(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\existing\project.csproj""> <Project>{{1-2-3-4}}</Project> <Name>Existing Project</Name> </ProjectReference> <ProjectReference Include=""..\one\fake1.csproj""> <Project>{0}</Project> <Name>Project One</Name> </ProjectReference> </ItemGroup> </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}"))); Solution.Projects.Add(projectOne); Solution.Projects.Add(projectTwo); var request = new AddReferenceRequest { Reference = @"fake1", FileName = @"c:\test\two\test.cs" }; var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(Solution) }, new NativeFileSystem())); handler.AddReference(request); projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString()); }
public FakeSolutionBuilder AddProject() { var newProject = new FakeProject("Project" + projectCount++); foreach (var project in _projects) { // each project references the ones that came before it. newProject.AddReference(new ProjectReference(project.Name)); } _projects.Add(newProject); return this; }
public FakeSolutionBuilder AddProject() { var newProject = new FakeProject("Project" + projectCount++); foreach (var project in _projects) { // each project references the ones that came before it. newProject.AddReference(new ProjectReference(project.Name)); } _projects.Add(newProject); return(this); }
public OutputFileManagerTest() { this.dte = new FakeDte(); this.solution = new FakeSolution(this.dte); this.project = new FakeProject(this.solution); this.projectItem = new FakeProjectItem(this.project); this.textTemplating = new FakeTextTemplating(); this.queryEditQuerySave = new StubIVsQueryEditQuerySave(); this.runningDocumentTable = new StubIVsRunningDocumentTable(); this.dte.AddService(typeof(STextTemplating), this.textTemplating, false); this.dte.AddService(typeof(SVsQueryEditQuerySave), this.queryEditQuerySave, false); this.dte.AddService(typeof(SVsRunningDocumentTable), this.runningDocumentTable, false); }
public void ShouldThrowProjectNotFoundExceptionWhenProjectNotFound() { var project = new FakeProject(fileName: @"/test/code/fake.csproj"); var solution = new FakeSolution(@"/test/fake.sln"); solution.Projects.Add(project); var request = new RemoveFromProjectRequest { FileName = @"/test/folder/Test.cs" }; var handler = new RemoveFromProjectHandler(solution); handler.RemoveFromProject(request); }
public void SetUp() { _solution = new FakeSolution(); var project = new FakeProject(); _solution.Projects.Add(project); _processors = new List<IReferenceProcessor> { new AddProjectReferenceProcessor(_solution), new AddFileReferenceProcessor(), new AddGacReferenceProcessor() }; _factory = new AddReferenceProcessorFactory(_solution, _processors, new FileSystem()); }
protected IProject CreateDefaultProject() { var project = new FakeProject("fakeone", @"c:\test\one\fake1.csproj", Guid.NewGuid()) { Title = "Project One", XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> </Project>") }; project.AddFile("some content", @"c:\test\one\test.cs"); return project; }
public void SetUp() { _solution = new FakeSolution(); var project = new FakeProject(); _solution.Projects.Add(project); _processors = new List <IReferenceProcessor> { new AddProjectReferenceProcessor(_solution), new AddFileReferenceProcessor(), new AddGacReferenceProcessor() }; _factory = new AddReferenceProcessorFactory(_solution, _processors); }
public void ShouldThrowProjectNotFoundExceptionWhenProjectNotFound() { var project = new FakeProject(fileName: @"/test/code/fake.csproj"); var solution = new FakeSolution(@"/test/fake.sln"); solution.Projects.Add(project); var request = new AddToProjectRequest { FileName = @"/test/folder/Test.cs" }; var handler = new AddToProjectHandler(solution, new FakeUnixFileSystem()); handler.AddToProject(request); }
protected IProject CreateDefaultProject() { var project = new FakeProject("fakeone", @"c:\test\one\fake1.csproj", Guid.NewGuid()) { Title = "Project One", XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> </Project>") }; project.AddFile("some content", @"c:\test\one\test.cs"); return(project); }
private static Error[] GetErrors(string editorText) { var fileName = "test.cs"; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText, fileName); solution.Projects.Add(project); var handler = new SemanticErrorsHandler(solution); var request = new Request { Buffer = editorText, FileName = fileName, }; var semanticErrorsResponse = handler.FindSemanticErrors(request); return(semanticErrorsResponse.Errors.ToArray()); }
public void ShouldNotAddCircularReference() { var projectOne = CreateDefaultProject(); var projectTwoId = Guid.NewGuid(); var projectTwo = new FakeProject("faketwo", @"c:\test\two\fake2.csproj", projectTwoId); projectTwo.Title = "Project Two"; projectTwo.AddFile("some content", @"c:\test\two\test.cs"); projectTwo.AddReference(new ProjectReference(Solution, "Project One")); var xml = string.Format(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\one\fake1.csproj""> <Project>{0}</Project> <Name>Project One</Name> </ProjectReference> </ItemGroup> </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}")); var expectedXml = XDocument.Parse(xml); projectTwo.XmlRepresentation = XDocument.Parse(xml); Solution.Projects.Add(projectOne); Solution.Projects.Add(projectTwo); var request = new AddReferenceRequest { Reference = @"fake2", FileName = @"c:\test\one\test.cs" }; var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(Solution) })); var response = handler.AddReference(request); projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString()); response.Message.ShouldEqual("Reference will create circular dependency"); }
protected IProject CreateDefaultProjectWithFileReference() { var project = new FakeProject("fakeone", @"c:\test\one\fake1.csproj", Guid.NewGuid()) { Title = "Project One", XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <Reference Include=""Hello.World""> <HintPath>..\packages\HelloWorld\lib\net40\Hello.World.dll</HintPath> </Reference> </ItemGroup> </Project>") }; project.AddFile("some content", @"c:\test\one\test.cs"); return project; }
public void Should_complete_string() { string editorText = @" public class myclass { public void method() { string s; s.$; } } "; int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency <ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/autocomplete", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("WordToComplete", partialWord); with.FormValue("Buffer", editorText); with.FormValue("Line", cursorPosition.Line.ToString()); with.FormValue("Column", cursorPosition.Column.ToString()); }); var res = result.Body.DeserializeJson <AutoCompleteResponse[]>().Select(c => c.DisplayText); res.ShouldContain("Trim()"); }
public void ShouldAlwaysUseWindowsFileSeparatorWhenAddingToProject() { var project = new FakeProject(fileName: @"/test/code/fake.csproj"); project.XmlRepresentation = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/></ItemGroup></Project>"); var expectedXml = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/><Compile Include=""folder\Test.cs""/></ItemGroup></Project>"); project.AddFile("some content", @"/test/code/folder/Test.cs"); var solution = new FakeSolution(@"/test/fake.sln"); solution.Projects.Add(project); var request = new AddToProjectRequest { FileName = @"/test/code/folder/Test.cs" }; var handler = new AddToProjectHandler(solution); handler.AddToProject(request); project.AsXml().ToString().ShouldEqual(expectedXml.ToString()); }
public static GetContextResponse GetContextInformation(this string editorText) { var cursorPosition = TestHelpers.GetLineAndColumnFromDollar(editorText); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new GetTestContextHandler(solution, new BufferParser(solution)); var request = new TestCommandRequest { Buffer = editorText, FileName = "myfile", Line = cursorPosition.Line, Column = cursorPosition.Column, }; return handler.GetContextResponse(request); }
protected IProject CreateDefaultProjectWithFileReference() { var project = new FakeProject("fakeone", @"c:\test\one\fake1.csproj", Guid.NewGuid()) { Title = "Project One", XmlRepresentation = XDocument.Parse(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <Reference Include=""Hello.World""> <HintPath>..\packages\HelloWorld\lib\net40\Hello.World.dll</HintPath> </Reference> </ItemGroup> </Project>") }; project.AddFile("some content", @"c:\test\one\test.cs"); return(project); }
public void ProjectItemFinishedGeneratingSetsMetadata() { using (var dte = new FakeDte()) { var solution = new FakeSolution(dte); var project = new FakeProject(solution); var projectItem = new FakeProjectItem(project); var replacements = new Dictionary <string, string>(); replacements["$wizarddata$"] = @" <Properties> <Generator>TextTemplatingFilePreprocessor</Generator> </Properties>"; var wizard = new ItemMetadataWizard(); wizard.RunStarted(null, replacements, default(WizardRunKind), null); wizard.ProjectItemFinishedGenerating(projectItem); // Wizard should clear the value Assert.AreEqual("TextTemplatingFilePreprocessor", projectItem.GetItemAttribute("Generator")); } }
public static string LookupType(this string editorText) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); var cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new TypeLookupHandler(new BufferParser(solution)); var request = new TypeLookupRequest() { Buffer = editorText, FileName = "myfile", Line = cursorPosition.Line, Column = cursorPosition.Column, }; return handler.GetTypeLookupResponse(request).Type; }
public void Should_lookup_Test() { string editorText = @" public class Test { public void Main() { Test test; te$st = new Test(); } } "; int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency <ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/typelookup", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("Buffer", editorText); with.FormValue("Line", cursorPosition.Line.ToString()); with.FormValue("Column", cursorPosition.Column.ToString()); }); var res = result.Body.DeserializeJson <TypeLookupResponse>(); res.Type.ShouldEqual("Test test"); }
public void Should_complete_string() { string editorText = @" public class myclass { public void method() { string s; s.$; } } "; int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); Tuple<int, int> cursorPosition = GetLineAndColumnFromIndex(editorText, cursorOffset); string partialWord = GetPartialWord(editorText); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add("dummyproject", project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency<ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/autocomplete", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("WordToComplete", partialWord); with.FormValue("Buffer", editorText); with.FormValue("Line", cursorPosition.Item1.ToString()); with.FormValue("Column", cursorPosition.Item2.ToString()); }); var res = result.Body.DeserializeJson<AutoCompleteResponse[]>().Select(c => c.DisplayText); res.ShouldContain("Trim()"); }
public static GetContextResponse GetContextInformation(this string editorText) { var cursorPosition = TestHelpers.GetLineAndColumnFromDollar(editorText); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new GetTestContextHandler(solution, new BufferParser(solution)); var request = new TestCommandRequest { Buffer = editorText, FileName = "myfile", Line = cursorPosition.Line, Column = cursorPosition.Column, }; return(handler.GetContextResponse(request)); }
public void ShouldAlwaysUseWindowsFileSeparatorWhenAddingToProject() { if (PlatformService.IsUnix) { var project = new FakeProject(fileName: @"/test/code/fake.csproj"); project.XmlRepresentation = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/></ItemGroup></Project>"); var expectedXml = XDocument.Parse(@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""><ItemGroup><Compile Include=""Hello.cs""/><Compile Include=""folder\Test.cs""/></ItemGroup></Project>"); project.AddFile("some content", @"/test/code/folder/Test.cs"); var solution = new FakeSolution(@"/test/fake.sln"); solution.Projects.Add(project); var request = new AddToProjectRequest { FileName = @"/test/code/folder/Test.cs" }; var handler = new AddToProjectHandler(solution, new FakeUnixFileSystem()); handler.AddToProject(request); project.AsXml().ToString().ShouldEqual(expectedXml.ToString()); } }
public void Should_find_usages_of_class() { const string editorText = @"public class myclass { public void method() { } public void method_calling_method() { method(); } } "; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency <ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/findusages", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("Line", "3"); with.FormValue("Column", "21"); with.FormValue("Buffer", editorText); }); var usages = result.Body.DeserializeJson <FindUsagesResponse>().Usages.ToArray(); usages.Count().ShouldEqual(2); usages[0].Text.Trim().ShouldEqual("public void method() { }"); usages[1].Text.Trim().ShouldEqual("method();"); }
public static string LookupType(this string editorText) { int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); var cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new TypeLookupHandler(solution, new BufferParser(solution)); var request = new TypeLookupRequest() { Buffer = editorText, FileName = "myfile", Line = cursorPosition.Line, Column = cursorPosition.Column, }; return(handler.GetTypeLookupResponse(request).Type); }
public void Should_lookup_Test() { string editorText = @" public class Test { public void Main() { Test test; te$st = new Test(); } } "; int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal); Tuple<int, int> cursorPosition = GetLineAndColumnFromIndex(editorText, cursorOffset); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add("dummyproject", project); var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency<ISolution>(solution)); var browser = new Browser(bootstrapper); var result = browser.Post("/typelookup", with => { with.HttpRequest(); with.FormValue("FileName", "myfile"); with.FormValue("Buffer", editorText); with.FormValue("Line", cursorPosition.Item1.ToString()); with.FormValue("Column", cursorPosition.Item2.ToString()); }); var res = result.Body.DeserializeJson<TypeLookupResponse>(); res.Type.ShouldEqual("Test test"); }
public FakeSolutionBuilder() { _solution = new FakeSolution(); _project = new FakeProject("Project" + projectCount++); _projects.Add(_project); }
void CreateTestProject() { project = new FakeProject(); }
public FakeSolutionBuilder() { _solution = new FakeSolution(); _project = new FakeProject("Project" + projectCount++); _projects.Add(_project); }
private static Error[] GetErrors(string editorText) { var fileName = "test.cs"; var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText, fileName); solution.Projects.Add(project); var handler = new SemanticErrorsHandler(solution); var request = new Request { Buffer = editorText, FileName = fileName, }; var semanticErrorsResponse = handler.FindSemanticErrors(request); return semanticErrorsResponse.Errors.ToArray(); }
public void ShouldNotAddCircularReference() { var projectOne = CreateDefaultProject(); var projectTwoId = Guid.NewGuid(); var projectTwo = new FakeProject("faketwo", @"c:\test\two\fake2.csproj", projectTwoId); projectTwo.Title = "Project Two"; projectTwo.AddFile("some content", @"c:\test\two\test.cs"); projectTwo.AddReference(new ProjectReference(Solution, "Project One", projectOne.ProjectId)); var xml = string.Format(@" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Compile Include=""Test.cs""/> </ItemGroup> <ItemGroup> <ProjectReference Include=""..\one\fake1.csproj""> <Project>{0}</Project> <Name>Project One</Name> </ProjectReference> </ItemGroup> </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}")); var expectedXml = XDocument.Parse(xml); projectTwo.XmlRepresentation = XDocument.Parse(xml); Solution.Projects.Add(projectOne); Solution.Projects.Add(projectTwo); var request = new AddReferenceRequest { Reference = @"fake2", FileName = @"c:\test\one\test.cs" }; var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(Solution) }, new NativeFileSystem())); var response = handler.AddReference(request); projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString()); response.Message.ShouldEqual("Reference will create circular dependency"); }