diff options
-rw-r--r-- | main/tests/UnitTests/ChangeLog | 9 | ||||
-rw-r--r-- | main/tests/UnitTests/Makefile.am | 5 | ||||
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.AspNet/AspNetCompletionTests.cs | 111 | ||||
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.AspNet/AspNetTesting.cs | 107 | ||||
-rw-r--r-- | main/tests/UnitTests/UnitTests.csproj | 23 |
5 files changed, 250 insertions, 5 deletions
diff --git a/main/tests/UnitTests/ChangeLog b/main/tests/UnitTests/ChangeLog index ae8bff4583..022bec6720 100644 --- a/main/tests/UnitTests/ChangeLog +++ b/main/tests/UnitTests/ChangeLog @@ -1,3 +1,12 @@ +2009-09-22 Michael Hutchinson <mhutchinson@novell.com> + + * Makefile.am: + * UnitTests.csproj: + * MonoDevelop.AspNet: + * MonoDevelop.AspNet/AspNetTesting.cs: + * MonoDevelop.AspNet/AspNetCompletionTests.cs: Start adding + some ASP.NET completion tests. + 2009-09-21 Mike Krüger <mkrueger@novell.com> * MonoDevelop.CSharpBinding/FindMemberVisitorTests.cs: Renamed diff --git a/main/tests/UnitTests/Makefile.am b/main/tests/UnitTests/Makefile.am index 9ad709cb8d..f01bbb486b 100644 --- a/main/tests/UnitTests/Makefile.am +++ b/main/tests/UnitTests/Makefile.am @@ -15,6 +15,7 @@ REFS = \ -r:../../build/AddIns/MonoDevelop.AspNet/MonoDevelop.AspNet.dll \ -r:../../build/AddIns/MonoDevelop.Autotools/MonoDevelop.Autotools.dll \ -r:../../build/AddIns/MonoDevelop.Deployment/MonoDevelop.Deployment.dll \ + -r:../../build/AddIns/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.dll \ -r:../../build/AddIns/MonoDevelop.Refactoring/MonoDevelop.Refactoring.dll \ -r:../../build/AddIns/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor.dll \ -r:../../build/bin/Mono.TextEditor.dll \ @@ -47,6 +48,8 @@ FILES = \ Mono.TextEditor.Tests/SelectionTests.cs \ Mono.TextEditor.Tests/SyntaxHighlightingTests.cs \ Mono.TextEditor.Tests/UndoRedoTests.cs \ + MonoDevelop.AspNet/AspNetCompletionTests.cs \ + MonoDevelop.AspNet/AspNetTesting.cs \ MonoDevelop.CSharpBinding/CodeCompletionAccessibleTests.cs \ MonoDevelop.CSharpBinding/CodeCompletionBugTests.cs \ MonoDevelop.CSharpBinding/CodeCompletionCSharp3Tests.cs \ @@ -96,7 +99,7 @@ test: all if test -n "$(fixture)"; then \ fp="-fixture=$(fixture)"; \ fi; \ - $(MD_LAUNCH_SETUP) MONO_PATH=$(top_builddir)/build/AddIns/MonoDevelop.Refactoring:$(top_builddir)/build/AddIns/BackendBindings:$(top_builddir)/build/AddIns/MonoDevelop.XmlEditor:$(top_builddir)/build/AddIns/MonoDevelop.AspNet mono --debug $(NUNIT_CONSOLE) -noshadow $(top_builddir)/build/bin/UnitTests.dll $$fp + $(MD_LAUNCH_SETUP) MONO_PATH=$(top_builddir)/build/AddIns/MonoDevelop.DesignerSupport:$(top_builddir)/build/AddIns/MonoDevelop.Refactoring:$(top_builddir)/build/AddIns/BackendBindings:$(top_builddir)/build/AddIns/MonoDevelop.XmlEditor:$(top_builddir)/build/AddIns/MonoDevelop.AspNet mono --debug $(NUNIT_CONSOLE) -noshadow $(top_builddir)/build/bin/UnitTests.dll $$fp CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb EXTRA_DIST = $(FILES) $(RES) diff --git a/main/tests/UnitTests/MonoDevelop.AspNet/AspNetCompletionTests.cs b/main/tests/UnitTests/MonoDevelop.AspNet/AspNetCompletionTests.cs new file mode 100644 index 0000000000..45e6a7801f --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.AspNet/AspNetCompletionTests.cs @@ -0,0 +1,111 @@ +// +// AspNetCompletion.cs +// +// Author: +// Michael Hutchinson <mhutchinson@novell.com> +// +// Copyright (c) 2009 Novell, Inc. (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using NUnit.Framework; + +namespace MonoDevelop.AspNet.Tests +{ + + [TestFixture] + public class AspNetCompletionTests : UnitTests.TestBase + { + [Test] + public void DirectiveCompletion () + { + var provider = AspNetTesting.CreateProvider (@"<%@ $ %>", ".aspx", false); + Assert.IsNotNull (provider); + Assert.AreEqual (9, provider.Count); + Assert.IsNotNull (provider.Find ("Page")); + Assert.IsNotNull (provider.Find ("Register")); + + provider = AspNetTesting.CreateProvider (@"<%@ $ %>", ".master", false); + Assert.IsNotNull (provider); + Assert.AreEqual (7, provider.Count); + Assert.IsNotNull (provider.Find ("Master")); + Assert.IsNotNull (provider.Find ("Register")); + + provider = AspNetTesting.CreateProvider (@"<%@ $ %>", ".ascx", false); + Assert.IsNotNull (provider); + Assert.AreEqual (7, provider.Count); + Assert.IsNotNull (provider.Find ("Control")); + Assert.IsNotNull (provider.Find ("Register")); + + provider = AspNetTesting.CreateProvider (@"<%@$ %>", ".aspx", false); + Assert.IsNull (provider); + + provider = AspNetTesting.CreateProvider (@"<%@ $ %>", ".aspx", false); + Assert.IsNull (provider); + } + + [Test] + public void DirectiveAttributeCompletion () + { + var provider = AspNetTesting.CreateProvider (@"<%@ Page A$ %>", ".aspx", false); + Assert.IsNotNull (provider); + Assert.AreEqual (41, provider.Count); + Assert.IsNotNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("Inherits")); + + provider = AspNetTesting.CreateProvider (@"<%@ Master A$ %>", ".master", false); + Assert.IsNotNull (provider); + Assert.AreEqual (18, provider.Count); + Assert.IsNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("MasterPageFile")); + Assert.IsNotNull (provider.Find ("Inherits")); + + provider = AspNetTesting.CreateProvider (@"<%@ Control A$ %>", ".ascx", false); + Assert.IsNotNull (provider); + Assert.AreEqual (17, provider.Count); + Assert.IsNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("Inherits")); + } + + [Test] + [Ignore ("Not working")] + public void DirectiveAttributeCtrlSpaceCompletion () + { + var provider = AspNetTesting.CreateProvider (@"<%@ Page $ %>", ".aspx", true); + Assert.IsNotNull (provider); + Assert.AreEqual (41, provider.Count); + Assert.IsNotNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("Inherits")); + + provider = AspNetTesting.CreateProvider (@"<%@ Master $ %>", ".master", true); + Assert.IsNotNull (provider); + Assert.AreEqual (18, provider.Count); + Assert.IsNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("MasterPageFile")); + Assert.IsNotNull (provider.Find ("Inherits")); + + provider = AspNetTesting.CreateProvider (@"<%@ Control $ %>", ".ascx", true); + Assert.IsNotNull (provider); + Assert.AreEqual (17, provider.Count); + Assert.IsNull (provider.Find ("StyleSheetTheme")); + Assert.IsNotNull (provider.Find ("Inherits")); + } + } +} diff --git a/main/tests/UnitTests/MonoDevelop.AspNet/AspNetTesting.cs b/main/tests/UnitTests/MonoDevelop.AspNet/AspNetTesting.cs new file mode 100644 index 0000000000..513ee0d0be --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.AspNet/AspNetTesting.cs @@ -0,0 +1,107 @@ +// +// AspNetTesting.cs +// +// Author: +// Michael Hutchinson <mhutchinson@novell.com> +// +// Copyright (c) 2009 Novell, Inc. (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Projects.Gui.Completion; +using MonoDevelop.Projects; +using MonoDevelop.Projects.Dom.Parser; + +namespace MonoDevelop.AspNet.Tests +{ + + //largely copied from MonoDevelop.CSharpBinding.Tests.CodeCompletionBugTests + public static class AspNetTesting + { + static int pcount = 0; + + public static CompletionDataList CreateAspxCtrlSpaceProvider (string text) + { + return CreateProvider (text, ".aspx", true); + } + + public static CompletionDataList CreateProvider (string text, string extension, bool isCtrlSpace) + { + string parsedText; + string editorText; + int cursorPosition = text.IndexOf ('$'); + int endPos = text.IndexOf ('$', cursorPosition + 1); + if (endPos == -1) + parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); + else { + parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); + editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); + cursorPosition = endPos - 1; + } + var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow (); + var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent (); + var project = new AspNetAppProject ("C#"); + project.FileName = "/tmp/a" + pcount + ".csproj"; + + string file = "/tmp/test-file-" + (pcount++) + extension; + project.AddFile (file); + + ProjectDomService.Load (project); + ProjectDom dom = ProjectDomService.GetProjectDom (project); + dom.ForceUpdate (true); + ProjectDomService.Parse (project, file, null, delegate { return parsedText; }); + ProjectDomService.Parse (project, file, null, delegate { return parsedText; }); + + sev.Project = project; + sev.ContentName = file; + sev.Text = editorText; + sev.CursorPosition = cursorPosition; + tww.ViewContent = sev; + var doc = new MonoDevelop.Ide.Gui.Document (tww); + doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser ().Parse (null, sev.ContentName, parsedText); + foreach (var e in doc.ParsedDocument.Errors) + Console.WriteLine (e); + + var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension (); + Initialize (textEditorCompletion, doc); + + int triggerWordLength = 1; + CodeCompletionContext ctx = new CodeCompletionContext (); + ctx.TriggerOffset = sev.CursorPosition; + int line, column; + sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column); + ctx.TriggerLine = line; + ctx.TriggerLineOffset = column; + + if (isCtrlSpace) + return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList; + else + return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList; + } + + static void Initialize (MonoDevelop.Ide.Gui.Content.TextEditorExtension extension, MonoDevelop.Ide.Gui.Document doc) + { + var meth = typeof (MonoDevelop.Ide.Gui.Content.TextEditorExtension) + .GetMethod ("Initialize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, + null, new Type [] { typeof (MonoDevelop.Ide.Gui.Document) }, null); + meth.Invoke (extension, new object [] { doc }); + } + } +} diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj index 3ad2c79dec..a83a9bd0bb 100644 --- a/main/tests/UnitTests/UnitTests.csproj +++ b/main/tests/UnitTests/UnitTests.csproj @@ -9,6 +9,7 @@ <OutputType>Library</OutputType> <AssemblyName>UnitTests</AssemblyName> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + <RootNamespace>UnitTests</RootNamespace> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -59,10 +60,6 @@ <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> - <Reference Include="NRefactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\build\bin\NRefactory.dll</HintPath> - </Reference> <Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\src\addins\NUnit\lib\nunit.core.dll</HintPath> @@ -118,6 +115,7 @@ <ProjectReference Include="..\..\src\addins\MonoDevelop.XmlEditor\MonoDevelop.XmlEditor.csproj"> <Project>{86DFC74A-B0B6-4C73-9E05-9098DA8FA5F1}</Project> <Name>MonoDevelop.XmlEditor</Name> + <Private>False</Private> </ProjectReference> <ProjectReference Include="..\..\src\core\MonoDevelop.Components\MonoDevelop.Components.csproj"> <Project>{3344D566-484B-4AEC-BBCF-86BC484D14B0}</Project> @@ -132,18 +130,32 @@ <ProjectReference Include="..\..\src\addins\CSharpBinding\CSharpBinding.csproj"> <Project>{07CC7654-27D6-421D-A64C-0FFA40456FA2}</Project> <Name>CSharpBinding</Name> + <Private>False</Private> </ProjectReference> <ProjectReference Include="..\..\src\core\Mono.Texteditor\Mono.TextEditor.csproj"> <Project>{A2329308-3751-4DBD-9A75-5F7B8B024625}</Project> <Name>Mono.TextEditor</Name> + <Private>False</Private> </ProjectReference> <ProjectReference Include="..\..\src\addins\MonoDevelop.Refactoring\MonoDevelop.Refactoring.csproj"> <Project>{100568FC-F4E8-439B-94AD-41D11724E45B}</Project> <Name>MonoDevelop.Refactoring</Name> + <Private>False</Private> </ProjectReference> <ProjectReference Include="..\..\src\addins\AspNet\MonoDevelop.AspNet\MonoDevelop.AspNet.csproj"> <Project>{1CF94D07-5480-4D10-A3CD-2EBD5E87B02E}</Project> <Name>MonoDevelop.AspNet</Name> + <Private>False</Private> + </ProjectReference> + <ProjectReference Include="..\..\contrib\NRefactory\Project\NRefactory.csproj"> + <Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project> + <Name>NRefactory</Name> + <Private>False</Private> + </ProjectReference> + <ProjectReference Include="..\..\src\addins\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.csproj"> + <Project>{2C24D515-4A2C-445C-8419-C09231913CFA}</Project> + <Name>MonoDevelop.DesignerSupport</Name> + <Private>False</Private> </ProjectReference> </ItemGroup> <ItemGroup> @@ -201,6 +213,8 @@ <Compile Include="Mono.TextEditor.Tests.DefaultEditActions\DeleteActionTests.cs" /> <Compile Include="Mono.TextEditor.Tests.DefaultEditActions\SelectionActionTests.cs" /> <Compile Include="MonoDevelop.Projects.Gui\CompletionListWindowTests.cs" /> + <Compile Include="MonoDevelop.AspNet\AspNetCompletionTests.cs" /> + <Compile Include="MonoDevelop.AspNet\AspNetTesting.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> @@ -224,5 +238,6 @@ <ItemGroup> <Folder Include="MonoDevelop.Refactoring\" /> <Folder Include="MonoDevelop.Projects.Gui\" /> + <Folder Include="MonoDevelop.AspNet\" /> </ItemGroup> </Project>
\ No newline at end of file |