public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
            {
                if (typeDeclaration.HasModifier(Modifiers.Abstract))
                {
                    return;
                }
                var result = resolver.Resolve(typeDeclaration);

                if (result == null || result.Type.GetDefinition() == null)
                {
                    return;
                }
                UnitTestLocation unitTest  = null;
                bool             isIgnored = false;

                foreach (var attr in result.Type.GetDefinition().GetAttributes())
                {
                    if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestFixtureAttribute")
                    {
                        unitTest                    = new UnitTestLocation(typeDeclaration.NameToken.StartLocation.Line);
                        unitTest.IsFixture          = true;
                        unitTest.UnitTestIdentifier = GetFullName(typeDeclaration);
                        foundTests.Add(unitTest);
                    }
                    else
                    {
                        isIgnored |= attr.AttributeType.ReflectionName == "NUnit.Framework.IgnoreAttribute";
                    }
                }
                if (unitTest != null)
                {
                    unitTest.IsIgnored = isIgnored;
                    base.VisitTypeDeclaration(typeDeclaration);
                }
            }
Пример #2
0
 public UnitTestMarker(ExtensibleTextEditor textEditor, UnitTestMarkerHost host, UnitTestLocation unitTest)
 {
     if (textEditor == null)
     {
         throw new ArgumentNullException("textEditor");
     }
     if (host == null)
     {
         throw new ArgumentNullException("host");
     }
     this.textEditor = textEditor;
     this.host       = host;
     this.unitTest   = unitTest;
 }
Пример #3
0
            public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
            {
                var method = semanticModel.GetDeclaredSymbol(node);

                if (method == null)
                {
                    return;
                }
                var parentClass = node.Parent as ClassDeclarationSyntax;

                if (parentClass == null)
                {
                    return;
                }
                UnitTestLocation test    = null;
                IUnitTestMarkers markers = null;

                foreach (var attr in method.GetAttributes())
                {
                    var cname = attr.AttributeClass.GetFullName();
                    markers = unitTestMarkers.FirstOrDefault(m => m.TestMethodAttributeMarker == cname);
                    if (markers != null)
                    {
                        if (test == null)
                        {
                            TagClass(parentClass, markers);
                            test = new UnitTestLocation(node.Identifier.SpanStart);
                            test.UnitTestIdentifier = GetFullName(parentClass) + "." + method.Name;
                            foundTests.Add(test);
                        }
                        break;
                    }
                }
                if (test != null)
                {
                    foreach (var attr in method.GetAttributes())
                    {
                        if (attr.AttributeClass.GetFullName() == markers.TestCaseMethodAttributeMarker)
                        {
                            test.TestCases.Add("(" + BuildArguments(attr) + ")");
                        }
                        else
                        {
                            test.IsIgnored |= attr.AttributeClass.GetFullName() == markers.IgnoreTestMethodAttributeMarker;
                        }
                    }
                }
            }
Пример #4
0
            public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
            {
                var method = semanticModel.GetDeclaredSymbol(node);

                if (method == null)
                {
                    return;
                }
                var parentClass = node.Parent as ClassDeclarationSyntax;

                if (parentClass == null)
                {
                    return;
                }
                UnitTestLocation test = null;

                foreach (var attr in method.GetAttributes())
                {
                    if (attr.AttributeClass.GetFullName() == "NUnit.Framework.TestAttribute")
                    {
                        if (test == null)
                        {
                            TagClass(parentClass);
                            test = new UnitTestLocation(node.Identifier.SpanStart);
                            test.UnitTestIdentifier = GetFullName(parentClass) + "." + method.Name;
                            foundTests.Add(test);
                        }
                    }
                }
                if (test != null)
                {
                    foreach (var attr in method.GetAttributes())
                    {
                        if (attr.AttributeClass.GetFullName() == "NUnit.Framework.TestCaseAttribute")
                        {
                            test.TestCases.Add("(" + BuildArguments(attr) + ")");
                        }
                        else
                        {
                            test.IsIgnored |= attr.AttributeClass.GetFullName() == "NUnit.Framework.IgnoreAttribute";
                        }
                    }
                }
            }
            public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
            {
                var result = resolver.Resolve(methodDeclaration) as MemberResolveResult;

                if (result == null)
                {
                    return;
                }
                var method = result.Member as IMethod;

                if (method == null)
                {
                    return;
                }

                UnitTestLocation test = null;

                foreach (var attr in method.Attributes)
                {
                    if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestAttribute")
                    {
                        if (test == null)
                        {
                            test = new UnitTestLocation(methodDeclaration.NameToken.StartLocation.Line);
                            test.UnitTestIdentifier = GetFullName((TypeDeclaration)methodDeclaration.Parent) + "." + methodDeclaration.Name;
                            foundTests.Add(test);
                        }
                    }
                }
                if (test != null)
                {
                    foreach (var attr in method.Attributes)
                    {
                        if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestCaseAttribute")
                        {
                            test.TestCases.Add("(" + BuildArguments(attr) + ")");
                        }
                        else
                        {
                            test.IsIgnored |= attr.AttributeType.ReflectionName == "NUnit.Framework.IgnoreAttribute";
                        }
                    }
                }
            }
Пример #6
0
            void TagClass(ClassDeclarationSyntax c, IUnitTestMarkers markers)
            {
                if (unitTestClasses.Contains(c))
                {
                    return;
                }
                unitTestClasses.Add(c);

                var type = semanticModel.GetDeclaredSymbol(c);
                var test = new UnitTestLocation(c.Identifier.SpanStart);

                test.IsFixture          = true;
                test.UnitTestIdentifier = GetFullName(c);
                foundTests.Add(test);

                if (test != null)
                {
                    foreach (var attr in type.GetAttributes())
                    {
                        test.IsIgnored |= attr.AttributeClass.GetFullName() == markers.IgnoreTestClassAttributeMarker;
                    }
                }
            }
			public override void VisitTypeDeclaration (TypeDeclaration typeDeclaration)
			{
				if (typeDeclaration.HasModifier (Modifiers.Abstract))
					return;
				var result = resolver.Resolve (typeDeclaration);
				if (result == null || result.Type.GetDefinition () == null)
					return;
				UnitTestLocation unitTest = null;
				bool isIgnored = false;
				foreach (var attr in result.Type.GetDefinition ().GetAttributes ()) {
					if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestFixtureAttribute") {
						unitTest = new UnitTestLocation (typeDeclaration.NameToken.StartLocation.Line);
						unitTest.IsFixture = true;
						unitTest.UnitTestIdentifier = GetFullName (typeDeclaration);
						foundTests.Add (unitTest);
					} else
						isIgnored |= attr.AttributeType.ReflectionName == "NUnit.Framework.IgnoreAttribute";
				}
				if (unitTest != null) {
					unitTest.IsIgnored = isIgnored;
					base.VisitTypeDeclaration (typeDeclaration);
				}
			}
			public override void VisitMethodDeclaration (MethodDeclaration methodDeclaration)
			{
				var result = resolver.Resolve (methodDeclaration) as MemberResolveResult;
				if (result == null)
					return;
				var method = result.Member as IMethod;
				if (method == null)
					return;

				UnitTestLocation test = null;
				foreach (var attr in method.Attributes) {
					if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestAttribute") {
						if (test == null) {
							test = new UnitTestLocation (methodDeclaration.NameToken.StartLocation.Line);
							test.UnitTestIdentifier = GetFullName ((TypeDeclaration)methodDeclaration.Parent) + "." + methodDeclaration.Name;
							foundTests.Add (test);
						}
					}
				}
				if (test != null) {
					foreach (var attr in method.Attributes) {
						if (attr.AttributeType.ReflectionName == "NUnit.Framework.TestCaseAttribute") {
							test.TestCases.Add ("(" + BuildArguments (attr) + ")");
						} else
							test.IsIgnored |= attr.AttributeType.ReflectionName == "NUnit.Framework.IgnoreAttribute";
					}
				}
			}
Пример #9
0
            public override void PopupContextMenu(UnitTestLocation unitTest, int x, int y)
            {
                var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode();
                var project      = ext?.DocumentContext?.Project;

                if (project == null)
                {
                    return;
                }
                var menu = new ContextMenu();

                if (unitTest.IsFixture)
                {
                    var menuItem = new ContextMenuItem(GettextCatalog.GetString("_Run All"));
                    menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, false).Run;
                    menu.Add(menuItem);
                    if (debugModeSet != null)
                    {
                        menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Debug All"));
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, true).Run;
                        menu.Add(menuItem);
                    }
                    menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Select in Test Pad"));
                    menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, true).Select;
                    menu.Add(menuItem);
                }
                else
                {
                    if (unitTest.TestCases.Count == 0)
                    {
                        var menuItem = new ContextMenuItem(GettextCatalog.GetString("_Run"));
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Debug"));
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, true).Run;
                            menu.Add(menuItem);
                        }
                        menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Select in Test Pad"));
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, true).Select;
                        menu.Add(menuItem);
                    }
                    else
                    {
                        var menuItem = new ContextMenuItem(GettextCatalog.GetString("_Run All"));
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Debug All"));
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, project, true).Run;
                            menu.Add(menuItem);
                        }
                        menu.Add(new SeparatorContextMenuItem());
                        foreach (var id in unitTest.TestCases)
                        {
                            var submenu = new ContextMenu();
                            menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Run"));
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, project, false).Run;
                            submenu.Add(menuItem);
                            if (debugModeSet != null)
                            {
                                menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Debug"));
                                menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, project, true).Run;
                                submenu.Add(menuItem);
                            }

                            var    label   = "Test" + id;
                            string tooltip = null;
                            var    test    = UnitTestService.SearchTestById(unitTest.UnitTestIdentifier + id);
                            if (test != null)
                            {
                                var result = test.GetLastResult();
                                if (result != null && result.IsFailure)
                                {
                                    tooltip = result.Message;
                                    label  += "!";
                                }
                            }

                            menuItem          = new ContextMenuItem(GettextCatalog.GetString("_Select in Test Pad"));
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, project, true).Select;
                            submenu.Add(menuItem);

                            const int maxLabelLength = 80;
                            var       trimmedLabel   = label.Trim();
                            if (trimmedLabel.Length > maxLabelLength)
                            {
                                const char gap           = '\u2026';
                                int        remainsLength = (maxLabelLength - 1) / 2;
                                string     start         = trimmedLabel.Substring(0, remainsLength);
                                string     end           = trimmedLabel.Substring(trimmedLabel.Length - remainsLength, remainsLength);
                                label = $"{start.TrimEnd()}{gap}{end.TrimStart ()}";
                            }

                            var subMenuItem = new ContextMenuItem(label);
                            // if (!string.IsNullOrEmpty (tooltip))
                            //	subMenuItem.TooltipText = tooltip;
                            subMenuItem.SubMenu = submenu;
                            menu.Add(subMenuItem);
                        }
                    }
                }
                // FIXME: enforce public API by casting Control to Gtk.Widget, because of IVT
                menu.Show((Gtk.Widget)ext.Editor, x, y);
            }
 public UnitTestMarker(UnitTestLocation unitTest, MonoDevelop.Ide.Gui.Document doc)
 {
     this.unitTest = unitTest;
     this.doc      = doc;
 }
			public UnitTestMarker(UnitTestLocation unitTest, MonoDevelop.Ide.Gui.Document doc)
			{
				this.unitTest = unitTest;
				this.doc = doc;
			}
Пример #12
0
            public override void PopupContextMenu(UnitTestLocation unitTest, int x, int y)
            {
                var debugModeSet = Runtime.ProcessService.GetDebugExecutionMode();

                var menu = new ContextMenu();

                if (unitTest.IsFixture)
                {
                    var menuItem = new ContextMenuItem("_Run All");
                    menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, false).Run;
                    menu.Add(menuItem);
                    if (debugModeSet != null)
                    {
                        menuItem          = new ContextMenuItem("_Debug All");
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, true).Run;
                        menu.Add(menuItem);
                    }
                    menuItem          = new ContextMenuItem("_Select in Test Pad");
                    menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, true).Select;
                    menu.Add(menuItem);
                }
                else
                {
                    if (unitTest.TestCases.Count == 0)
                    {
                        var menuItem = new ContextMenuItem("_Run");
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem          = new ContextMenuItem("_Debug");
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, true).Run;
                            menu.Add(menuItem);
                        }
                        menuItem          = new ContextMenuItem("_Select in Test Pad");
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, true).Select;
                        menu.Add(menuItem);
                    }
                    else
                    {
                        var menuItem = new ContextMenuItem("_Run All");
                        menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, false).Run;
                        menu.Add(menuItem);
                        if (debugModeSet != null)
                        {
                            menuItem          = new ContextMenuItem("_Debug All");
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier, true).Run;
                            menu.Add(menuItem);
                        }
                        menu.Add(new SeparatorContextMenuItem());
                        foreach (var id in unitTest.TestCases)
                        {
                            var submenu = new ContextMenu();
                            menuItem          = new ContextMenuItem("_Run");
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, false).Run;
                            submenu.Add(menuItem);
                            if (debugModeSet != null)
                            {
                                menuItem          = new ContextMenuItem("_Debug");
                                menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, true).Run;
                                submenu.Add(menuItem);
                            }

                            var    label   = "Test" + id;
                            string tooltip = null;
                            var    test    = NUnitService.Instance.SearchTestById(unitTest.UnitTestIdentifier + id);
                            if (test != null)
                            {
                                var result = test.GetLastResult();
                                if (result != null && result.IsFailure)
                                {
                                    tooltip = result.Message;
                                    label  += "!";
                                }
                            }

                            menuItem          = new ContextMenuItem("_Select in Test Pad");
                            menuItem.Clicked += new TestRunner(unitTest.UnitTestIdentifier + id, true).Select;
                            submenu.Add(menuItem);

                            var subMenuItem = new ContextMenuItem(label);
                            // if (!string.IsNullOrEmpty (tooltip))
                            //	subMenuItem.TooltipText = tooltip;
                            subMenuItem.SubMenu = submenu;
                            menu.Add(subMenuItem);
                        }
                    }
                }
                menu.Show(ext.Editor, x, y);
            }
Пример #13
0
 public override void PopupContextMenu(UnitTestLocation unitTest, int x, int y)
 {
 }