예제 #1
0
        public void TestInterfaceShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestInterface.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 2 members
            Assert.AreEqual(3, (document.First() as IMembers).Members.Count);

            // First item should be an interface
            var innerInterface = (document.First() as IMembers).Members.First() as CodeInterfaceItem;

            Assert.AreEqual(3, innerInterface.Members.Count);

            // Second item should be the implementing class
            var implementingClass = (document.First() as IMembers).Members[1] as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, implementingClass.Kind);
            Assert.AreEqual(3, implementingClass.Members.Count);

            var implementedInterface = implementingClass.Members.Last() as CodeImplementedInterfaceItem;

            Assert.AreEqual(CodeItemKindEnum.ImplementedInterface, implementedInterface.Kind);
            Assert.AreEqual(3, implementedInterface.Members.Count);
            Assert.IsFalse(implementedInterface.Name.StartsWith("#"));

            // Items should have proper start lines
            Assert.AreEqual(12, implementedInterface.Members[0].StartLine);
            Assert.AreEqual(17, implementedInterface.Members[1].StartLine);
            Assert.AreEqual(34, implementedInterface.Members[2].StartLine);
        }
예제 #2
0
        public void ShouldBeOk()
        {
            SettingsHelper.UseXMLComments = true;

            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestMethodsWithComments.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Inner item should be a class
            var innerClass = (document.First() as CodeNamespaceItem).Members.First() as CodeClassItem;

            // Class should have a method
            var methodWithComment = innerClass.Members.First() as CodeFunctionItem;

            Assert.AreEqual("Super important summary", methodWithComment.Tooltip);

            // Class should have a method
            var methodWithoutComment = innerClass.Members[1] as CodeFunctionItem;

            Assert.AreEqual("Public void MethodWithoutComment ()", methodWithoutComment.Tooltip);

            // Class should have a method
            var methodWithMultipleComment = innerClass.Members[2] as CodeFunctionItem;

            Assert.AreEqual("Multiple comment - summary", methodWithMultipleComment.Tooltip);

            // Class should have a method
            var methodWithReorderedComment = innerClass.Members[3] as CodeFunctionItem;

            Assert.AreEqual("Multiple comment - summary", methodWithReorderedComment.Tooltip);
        }
예제 #3
0
        public void ShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestProperties.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 1 member
            Assert.AreEqual(1, (document.First() as IMembers).Members.Count);

            // Inner item should be a class
            var innerClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            // Inheriting class should have properties
            var propertyGetSet = innerClass.Members.First() as CodeFunctionItem;

            Assert.AreEqual(" {get,set}", propertyGetSet.Parameters);

            var propertyGet = innerClass.Members[1] as CodeFunctionItem;

            Assert.AreEqual(" {get}", propertyGet.Parameters);

            var propertySet = innerClass.Members[2] as CodeFunctionItem;

            Assert.AreEqual(" {set}", propertySet.Parameters);

            var property = innerClass.Members.Last() as CodeFunctionItem;

            Assert.IsNull(property.Parameters);
        }
예제 #4
0
        public void TestSealedShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestSealed.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 3 members
            Assert.AreEqual(3, (document.First() as IMembers).Members.Count);

            // Inner item should be a sealed class
            var sealedBaseClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, sealedBaseClass.Kind);
            Assert.AreEqual("SealedBaseClass", sealedBaseClass.Name);
            Assert.AreEqual(CodeItemAccessEnum.Sealed, sealedBaseClass.Access);

            // Inheriting Class should be there
            var inheritingClass = (document.First() as IMembers).Members.Last() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, inheritingClass.Kind);
            Assert.AreEqual("InheritingClass", inheritingClass.Name);
            Assert.AreEqual(CodeItemAccessEnum.Public, inheritingClass.Access);
            Assert.AreEqual(" : BaseClass", inheritingClass.Parameters);

            // Inheriting class should have sealed property
            var sealedProperty = inheritingClass.Members.Last() as CodeFunctionItem;

            Assert.AreEqual(CodeItemKindEnum.Property, sealedProperty.Kind);
            Assert.AreEqual("BaseProperty", sealedProperty.Name);
            Assert.AreEqual(CodeItemAccessEnum.Sealed, sealedProperty.Access);
            Assert.AreEqual("BaseProperty {get,set}", sealedProperty.Parameters);
        }
예제 #5
0
        public void ShouldHaveCorrectStructure()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestNestedNamespaces.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have members
            Assert.IsTrue((document.First() as IMembers).Members.Any());

            // Inner item should also be a namespace
            var innerNamespace = (document.First() as IMembers).Members.First() as CodeNamespaceItem;

            Assert.AreEqual(CodeItemKindEnum.Namespace, innerNamespace.Kind);

            // That inner namespace should have members
            Assert.IsTrue(innerNamespace.Members.Any());

            // That member should be a class
            var innerClass = (innerNamespace as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, innerClass.Kind);
            Assert.AreEqual("ClassInNestedNamespace", innerClass.Name);
        }
예제 #6
0
        public void TestRegionsSpan()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestRegions.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // There should be a single class
            var regionClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.NotNull(regionClass);

            // The class should have a function in it
            Assert.NotNull(regionClass.Members.FirstOrDefault(m => m.Name.Equals("OutsideRegionFunction")));

            // The class should have a region in it
            var regionR1 = regionClass.Members.FirstOrDefault(m => m.Name.Equals("#R1")) as CodeRegionItem;

            Assert.NotNull(regionR1, "Region #R1 not found");

            // The region should have correct span for outlining usages
            Assert.AreEqual(101, regionR1.Span.Start);
            Assert.AreEqual(111, regionR1.Span.End);
        }
예제 #7
0
        public void TestRegions()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestRegions.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // There should be a single class
            var regionClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.NotNull(regionClass);

            // The class should have a function in it
            Assert.NotNull(regionClass.Members.FirstOrDefault(m => m.Name.Equals("OutsideRegionFunction")));

            // The class should have a region in it
            var regionR1 = regionClass.Members.FirstOrDefault(m => m.Name.Equals("#R1")) as CodeRegionItem;

            Assert.NotNull(regionR1);

            // Region R1 should have a nested region R15 with a constant in it
            var regionR15 = regionR1.Members.FirstOrDefault(m => m.Name.Equals("#R15")) as CodeRegionItem;

            Assert.NotNull(regionR15);
            Assert.NotNull(regionR15.Members.FirstOrDefault(m => m.Name.Equals("nestedRegionConstant")));

            // Region R1 should have a function Test1 and Test2 in it
            Assert.NotNull(regionR1.Members.FirstOrDefault(m => m.Name.Equals("Test1")));
            Assert.NotNull(regionR1.Members.FirstOrDefault(m => m.Name.Equals("Test2")));
        }
예제 #8
0
        public void TestInterfaceInRegionShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestInterface.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 2 members
            Assert.AreEqual(3, (document.First() as IMembers).Members.Count);

            // Third item should be a implementing class
            var implementingClass = (document.First() as IMembers).Members.Last() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, implementingClass.Kind);
            Assert.AreEqual(3, implementingClass.Members.Count);

            var region = implementingClass.Members.Last() as CodeRegionItem;

            var implementedInterface = region.Members.First() as CodeImplementedInterfaceItem;

            Assert.AreEqual(CodeItemKindEnum.ImplementedInterface, implementedInterface.Kind);
            Assert.AreEqual(3, implementedInterface.Members.Count);
        }
예제 #9
0
        public void ShouldHaveCorrectStructure()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestNoNamespace.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a class
            Assert.AreEqual(CodeItemKindEnum.Class, document.First().Kind);
        }
예제 #10
0
        public void ShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestEmptyInterface.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should not have members
            Assert.IsTrue(!(document.First() as IMembers).Members.Any());
        }
예제 #11
0
 private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     if (!_backgroundWorker.CancellationPending)
     {
         var request = e.Argument as BackgroundWorkerRequest;
         if (request == null)
         {
             return;
         }
         var codeItems = SyntaxMapper.MapDocument(request.Document, this, _workspace);
         e.Result = new BackgroundWorkerResult {
             CodeItems = codeItems, ForceUpdate = request.ForceUpdate
         };
     }
 }
예제 #12
0
        public void OnlyOneItemShouldBeHighlighted()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestProperties.cs"));

            HighlightHelper.HighlightCurrentItem(document, 13, Brushes.Red, Brushes.Blue, Brushes.Green, Brushes.White);

            HighlightHelper.HighlightCurrentItem(document, 18, Brushes.Red, Brushes.Blue, Brushes.Green, Brushes.White);


            var highlightedItems = new List <CodeItem>();

            FindHighlightedItems(highlightedItems, document);

            Assert.AreEqual(1, highlightedItems.Count);
        }
예제 #13
0
        public void CurrentItemShouldBeHighlighted()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestProperties.cs"));

            HighlightHelper.HighlightCurrentItem(document, 13, Brushes.Red, Brushes.Blue, Brushes.Green, Brushes.White);

            var highlightedClass = (document.First() as IMembers).Members.First() as CodeClassItem;
            var highlightedItem  = highlightedClass.Members[2];

            Assert.AreEqual(FontWeights.Bold, highlightedItem.FontWeight);
            Assert.AreEqual(Brushes.Red, highlightedItem.Foreground);
            Assert.AreEqual(Brushes.Blue, highlightedItem.HighlightBackground);

            Assert.AreEqual(Brushes.Green, highlightedClass.BorderBrush);
        }
예제 #14
0
        public void ItemsSorting(SortOrderEnum sortOrder, string[] methodNames)
        {
            var document  = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestSorting.cs"));
            var viewModel = new CodeDocumentViewModel {
                CodeDocument = document, SortOrder = sortOrder
            };

            viewModel.CodeDocument = SortHelper.Sort(viewModel);

            var sortingClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(methodNames[0], sortingClass.Members.First().Name);
            Assert.AreEqual(methodNames[1], sortingClass.Members[1].Name);
            Assert.AreEqual(methodNames[2], sortingClass.Members.Last().Name);

            Assert.AreEqual(sortOrder, viewModel.SortOrder);
        }
예제 #15
0
        public void ShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestIndexers.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Inner item should be a class
            var innerClass = (document.First() as CodeNamespaceItem).Members.First() as CodeClassItem;

            // Class should have an indexer
            var indexer = innerClass.Members.First() as CodeFunctionItem;

            Assert.AreEqual(CodeItemKindEnum.Indexer, indexer.Kind);
        }
예제 #16
0
        public void TestBaseImplementedInterfaceShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestInterface3.cs"));

            Assert.IsTrue(document.Any());

            // last item should be the implementing class
            var implementingClass = (document.First() as IMembers).Members.Last() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, implementingClass.Kind);
            Assert.AreEqual(1, implementingClass.Members.Count);

            var implementedInterface = implementingClass.Members.First() as CodeImplementedInterfaceItem;

            Assert.AreEqual(CodeItemKindEnum.ImplementedInterface, implementedInterface.Kind);
            Assert.AreEqual(1, implementedInterface.Members.Count);
        }
예제 #17
0
        public void TestRegionsNoName()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestRegionsNoName.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // There should be a single class
            var regionClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.NotNull(regionClass);

            // The class should have a region in it
            var regionR1 = regionClass.Members.FirstOrDefault(m => m.Name.Equals("#Region")) as CodeRegionItem;

            Assert.NotNull(regionR1, "Region #Region not found");
        }
예제 #18
0
        public void TestUsingsInNamespaceShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestUsingsInNamespace.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 1 member
            Assert.AreEqual(1, (document.First() as IMembers).Members.Count);

            // Item should be a class
            var innerClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, innerClass.Kind);
            Assert.AreEqual(2, innerClass.Members.Count);

            Assert.AreEqual(CodeItemKindEnum.Constructor, innerClass.Members.First().Kind);
            Assert.AreEqual(CodeItemKindEnum.Method, innerClass.Members.Last().Kind);
        }
예제 #19
0
        public void TestSwitchShouldBeOk()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestSwitch.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 1 member
            Assert.AreEqual(1, (document.First() as IMembers).Members.Count);

            // Inner item should be a class
            var innerClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, innerClass.Kind);

            // Class should have 3 methods
            Assert.AreEqual(3, innerClass.Members.Count);

            // First method should have a switch inside
            var method          = innerClass.Members.First();
            var switchStatement = (method as IMembers).Members.First();

            Assert.AreEqual(CodeItemKindEnum.Switch, switchStatement.Kind);

            // Second method should have a switch inside
            var secondMethod          = innerClass.Members[1];
            var secondSwitchStatement = (secondMethod as IMembers).Members.First();

            Assert.AreEqual(CodeItemKindEnum.Switch, secondSwitchStatement.Kind);

            // last method should have a switch inside
            var lastMethod          = innerClass.Members.Last();
            var lastSwitchStatement = (lastMethod as IMembers).Members.First();

            Assert.AreEqual(CodeItemKindEnum.Switch, lastSwitchStatement.Kind);
        }
예제 #20
0
        public void NestedRegionsShouldWork()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestNestedRegions.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have members
            Assert.IsTrue((document.First() as IMembers).Members.Any());

            // Namespace should have 1 member
            Assert.AreEqual(1, (document.First() as IMembers).Members.Count);

            // Inner item should be a class
            var innerClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, innerClass.Kind);

            // That inner class should have members
            Assert.IsTrue(innerClass.Members.Any());

            // That member should be a region
            var parentRegion = (innerClass as IMembers).Members.First() as CodeRegionItem;

            Assert.AreEqual(CodeItemKindEnum.Region, parentRegion.Kind);
            Assert.AreEqual("#ParentRegion", parentRegion.Name);

            // That parent region should have members
            Assert.IsTrue(parentRegion.Members.Any());

            // That member should be a region
            var innerRegion = (parentRegion as IMembers).Members.First() as CodeRegionItem;

            Assert.AreEqual(CodeItemKindEnum.Region, innerRegion.Kind);
            Assert.AreEqual("#ChildRegion", innerRegion.Name);
        }
예제 #21
0
        public void TestInterfaceWithRegion()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestInterfaceRegion.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have 1 member
            Assert.AreEqual(1, (document.First() as IMembers).Members.Count);

            // First item should be an interface
            var innerInterface = (document.First() as IMembers).Members.First() as CodeInterfaceItem;

            Assert.AreEqual(4, innerInterface.Members.Count);

            // Region in interface should have 1 member
            var region = innerInterface.Members[3] as CodeRegionItem;

            Assert.AreEqual(CodeItemKindEnum.Region, region.Kind);
            Assert.AreEqual(1, region.Members.Count);
        }
예제 #22
0
        public void EmptyItemsShouldRespectSetting(bool hideItemsWithoutChildren, Visibility expectedVisibility)
        {
            var document = new CodeDocumentViewModel
            {
                CodeDocument = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestVisibility.cs"))
            };

            SettingsHelper.FilterRules = new List <FilterRule>
            {
                new FilterRule
                {
                    Access      = CodeItemAccessEnum.All,
                    Kind        = CodeItemKindEnum.Class,
                    Visible     = true,
                    HideIfEmpty = hideItemsWithoutChildren
                }
            };

            VisibilityHelper.SetCodeItemVisibility(document.CodeDocument);

            var firstClass = (document.CodeDocument.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(expectedVisibility, firstClass.IsVisible);
        }
예제 #23
0
        public void ShouldBeVisible()
        {
            var document = SyntaxMapper.MapDocument(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Files\\TestEmptyClass.cs"));

            Assert.IsTrue(document.Any());

            // First item should be a namespace
            Assert.AreEqual(CodeItemKindEnum.Namespace, document.First().Kind);

            // Namespace item should have members
            Assert.IsTrue((document.First() as IMembers).Members.Any());

            // Inner item should be a class
            var innerClass = (document.First() as IMembers).Members.First() as CodeClassItem;

            Assert.AreEqual(CodeItemKindEnum.Class, innerClass.Kind);
            Assert.AreEqual("CodeNavTestEmptyClass", innerClass.Name);

            // Class should be visible
            Assert.AreEqual(Visibility.Visible, innerClass.IsVisible);

            // Since it does not have members, it should not show the expander symbol
            Assert.AreEqual(Visibility.Collapsed, innerClass.HasMembersVisibility);
        }